Class: Spree::Api::PaymentsController

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

Instance Method Summary collapse

Instance Method Details

#authorizeObject



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

def authorize
  perform_payment_action(:authorize)
end

#captureObject



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

def capture
  perform_payment_action(:capture)
end

#createObject



23
24
25
26
27
28
29
30
31
# File 'app/controllers/spree/api/payments_controller.rb', line 23

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



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

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

#newObject



18
19
20
21
# File 'app/controllers/spree/api/payments_controller.rb', line 18

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

#purchaseObject



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

def purchase
  perform_payment_action(:purchase)
end

#showObject



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

def show
  respond_with(@payment)
end

#updateObject



33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/spree/api/payments_controller.rb', line 33

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



60
61
62
# File 'app/controllers/spree/api/payments_controller.rb', line 60

def void
  perform_payment_action(:void_transaction)
end