Class: Stay::Api::V1::UserPaypalController

Inherits:
BaseApiController
  • Object
show all
Defined in:
app/controllers/stay/api/v1/user_paypal_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
# File 'app/controllers/stay/api/v1/user_paypal_controller.rb', line 22

def create
  paypal = current_devise_api_user.build_user_paypal(user_paypal_params)
  if paypal.save
    render json: { message: "PayPal account saved successfully", data: paypal, success: true }, status: :ok
  else
    render json: { error: "PayPal account not saved", success: false, errors: paypal.errors.full_messages }, status: :unprocessable_entity
  end
end

#editObject



32
33
34
# File 'app/controllers/stay/api/v1/user_paypal_controller.rb', line 32

def edit
  render json: { data: paypal, success: true }, status: :ok
end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/stay/api/v1/user_paypal_controller.rb', line 5

def index
  @paypal = current_devise_api_user.user_paypal
  if @paypal.present?
    render json: {
      message: "paypal account found",
      data: @paypal,
      success: true },
    status: :ok
  else
    render json: { error: "No paypal account found", success: false }, status: :unprocessable_entity
  end
end

#showObject



18
19
20
# File 'app/controllers/stay/api/v1/user_paypal_controller.rb', line 18

def show
  render json: { data: @paypal, success: true }, status: :ok
end

#updateObject



36
37
38
39
40
41
42
# File 'app/controllers/stay/api/v1/user_paypal_controller.rb', line 36

def update
  if @paypal.update(user_paypal_params)
    render json: { message: "Credit card updated successfully", data: @paypal, success: true }, status: :ok
  else
    render json: { error: "Credit card not updated", success: false, errors: paypal.errors.full_messages }, status: :unprocessable_entity
  end
end