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

Methods inherited from BaseController

#map_nested_attributes_keys, #set_jsonp_format

Methods included from ControllerSetup

included

Instance Method Details

#authorizeObject



32
33
34
# File 'app/controllers/spree/api/payments_controller.rb', line 32

def authorize
  perform_payment_action(:authorize)
end

#captureObject



36
37
38
# File 'app/controllers/spree/api/payments_controller.rb', line 36

def capture
  perform_payment_action(:capture)
end

#createObject



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

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

#creditObject



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

def credit
  if params[:amount].to_f > @payment.credit_allowed
    render "spree/api/payments/credit_over_limit", :status => 422
  else
    perform_payment_action(:credit, params[:amount])
  end
end

#indexObject



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

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

#newObject



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

def new
  @payment_methods = Spree::PaymentMethod.where(:environment => Rails.env)
  respond_with(@payment_method)
end

#purchaseObject



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

def purchase
  perform_payment_action(:purchase)
end

#showObject



28
29
30
# File 'app/controllers/spree/api/payments_controller.rb', line 28

def show
  respond_with(@payment)
end

#voidObject



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

def void
  perform_payment_action(:void_transaction)
end