Class: Spree::Api::V1::PaymentsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/api/v1/payments_controller.rb

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Methods inherited from BaseController

#content_type, #permitted_line_item_attributes

Methods included from ControllerSetup

included

Instance Method Details

#authorizeObject



43
44
45
# File 'app/controllers/spree/api/v1/payments_controller.rb', line 43

def authorize
  perform_payment_action(:authorize)
end

#captureObject



47
48
49
# File 'app/controllers/spree/api/v1/payments_controller.rb', line 47

def capture
  perform_payment_action(:capture)
end

#createObject



18
19
20
21
22
23
24
25
26
# File 'app/controllers/spree/api/v1/payments_controller.rb', line 18

def create
  @order.validate_payments_attributes([payment_params])
  @payment = @order.payments.build(payment_params)
  if @payment.save
    respond_with(@payment, status: 201, default_template: :show)
  else
    invalid_resource!(@payment)
  end
end

#indexObject



8
9
10
11
# File 'app/controllers/spree/api/v1/payments_controller.rb', line 8

def index
  @payments = @order.payments.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
  respond_with(@payments)
end

#newObject



13
14
15
16
# File 'app/controllers/spree/api/v1/payments_controller.rb', line 13

def new
  @payment_methods = Spree::PaymentMethod.available
  respond_with(@payment_methods)
end

#purchaseObject



51
52
53
# File 'app/controllers/spree/api/v1/payments_controller.rb', line 51

def purchase
  perform_payment_action(:purchase)
end

#showObject



39
40
41
# File 'app/controllers/spree/api/v1/payments_controller.rb', line 39

def show
  respond_with(@payment)
end

#updateObject



28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/spree/api/v1/payments_controller.rb', line 28

def update
  authorize! params[:action], @payment
  if !@payment.editable?
    render 'update_forbidden', status: 403
  elsif @payment.update_attributes(payment_params)
    respond_with(@payment, default_template: :show)
  else
    invalid_resource!(@payment)
  end
end

#voidObject



55
56
57
# File 'app/controllers/spree/api/v1/payments_controller.rb', line 55

def void
  perform_payment_action(:void_transaction)
end