Class: Spree::Api::V3::Admin::Orders::StoreCreditsController

Inherits:
BaseController show all
Defined in:
app/controllers/spree/api/v3/admin/orders/store_credits_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

#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

#createObject

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

Body: { amount: Number (optional) }

When ‘amount` is omitted, applies the customer’s available store credit up to the order total.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/spree/api/v3/admin/orders/store_credits_controller.rb', line 17

def create
  with_order_lock do
    result = Spree.checkout_add_store_credit_service.call(
      order: @parent,
      amount: params[:amount].try(:to_f)
    )

    if result.success?
      render json: serialize_resource(result.value), status: :created
    else
      render_service_error(result.error)
    end
  end
end

#destroyObject

DELETE /api/v3/admin/orders/:order_id/store_credits



33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/spree/api/v3/admin/orders/store_credits_controller.rb', line 33

def destroy
  with_order_lock do
    result = Spree.checkout_remove_store_credit_service.call(order: @parent)

    if result.success?
      head :no_content
    else
      render_service_error(result.error)
    end
  end
end