Class: Spree::Api::PaymentsController

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

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Instance Method Details

#authorizeObject



45
46
47
# File 'app/controllers/spree/api/payments_controller.rb', line 45

def authorize
  perform_payment_action(:authorize)
end

#captureObject



49
50
51
# File 'app/controllers/spree/api/payments_controller.rb', line 49

def capture
  perform_payment_action(:capture)
end

#createObject



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

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

#indexObject



10
11
12
13
# File 'app/controllers/spree/api/payments_controller.rb', line 10

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

#newObject



15
16
17
18
# File 'app/controllers/spree/api/payments_controller.rb', line 15

def new
  @payment_methods = Spree::PaymentMethod.available_to_users.available_to_admin
  respond_with(@payment_method)
end

#purchaseObject



53
54
55
# File 'app/controllers/spree/api/payments_controller.rb', line 53

def purchase
  perform_payment_action(:purchase)
end

#showObject



41
42
43
# File 'app/controllers/spree/api/payments_controller.rb', line 41

def show
  respond_with(@payment)
end

#updateObject



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

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

#voidObject



57
58
59
# File 'app/controllers/spree/api/payments_controller.rb', line 57

def void
  perform_payment_action(:void_transaction)
end