Class: Spree::Api::V3::Admin::Orders::PaymentsController

Inherits:
BaseController show all
Defined in:
app/controllers/spree/api/v3/admin/orders/payments_controller.rb

Constant Summary

Constants included from ScopedAuthorization

ScopedAuthorization::READ_ACTIONS

Constants inherited from BaseController

BaseController::RATE_LIMIT_RESPONSE

Constants included from Idempotent

Idempotent::IDEMPOTENCY_HEADER, Idempotent::IDEMPOTENCY_TTL, Idempotent::MAX_KEY_LENGTH, Idempotent::MUTATING_METHODS

Constants included from ErrorHandler

ErrorHandler::ERROR_CODES

Constants included from JwtAuthentication

JwtAuthentication::JWT_AUDIENCE_ADMIN, JwtAuthentication::JWT_AUDIENCE_STORE, JwtAuthentication::JWT_ISSUER, JwtAuthentication::USER_TYPE_ADMIN, JwtAuthentication::USER_TYPE_CUSTOMER

Instance Method Summary collapse

Methods inherited from ResourceController

#destroy, #index, #show, #update

Methods included from Spree::Api::V3::ApiKeyAuthentication

#authenticate_api_key!, #authenticate_secret_key!

Methods included from JwtAuthentication

#authenticate_user, #require_authentication!

Instance Method Details

#captureObject

PATCH /api/v3/admin/orders/:order_id/payments/:id/capture



39
40
41
42
43
44
45
46
47
# File 'app/controllers/spree/api/v3/admin/orders/payments_controller.rb', line 39

def capture
  with_order_lock do
    amount = params[:amount] ? (params[:amount].to_f * 100).round : nil
    @resource.capture!(amount)
    render json: serialize_resource(@resource.reload)
  rescue Spree::Core::GatewayError => e
    render_service_error(e.message)
  end
end

#createObject

POST /api/v3/admin/orders/:order_id/payments

Supports off-session admin charges by passing ‘source_id` referencing a saved payment source (e.g. a Spree::CreditCard owned by the order’s customer). The source must belong to the customer assigned to the order.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/spree/api/v3/admin/orders/payments_controller.rb', line 16

def create
  with_order_lock do
    payment_method = Spree::PaymentMethod.find_by_prefix_id!(params[:payment_method_id])
    @resource = @parent.payments.build(
      amount: params[:amount] || @parent.order_total_after_store_credit,
      payment_method: payment_method
    )

    if params[:source_id].present? && payment_method.source_required?
      @resource.source = find_source!(payment_method, params[:source_id])
    end

    authorize_resource!(@resource, :create)

    if @resource.save
      render json: serialize_resource(@resource), status: :created
    else
      render_validation_error(@resource.errors)
    end
  end
end

#voidObject

PATCH /api/v3/admin/orders/:order_id/payments/:id/void



50
51
52
53
54
55
56
57
# File 'app/controllers/spree/api/v3/admin/orders/payments_controller.rb', line 50

def void
  with_order_lock do
    @resource.void_transaction!
    render json: serialize_resource(@resource.reload)
  rescue Spree::Core::GatewayError => e
    render_service_error(e.message)
  end
end