Class: Spree::Api::V3::Store::Carts::DiscountCodesController

Inherits:
BaseController show all
Includes:
CartResolvable, OrderLock
Defined in:
app/controllers/spree/api/v3/store/carts/discount_codes_controller.rb

Constant Summary

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 included from ApiKeyAuthentication

#authenticate_api_key!, #authenticate_secret_key!

Methods included from JwtAuthentication

#authenticate_user, #require_authentication!

Instance Method Details

#createObject

POST /api/v3/store/carts/:cart_id/discount_codes Apply a discount code to the cart



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/spree/api/v3/store/carts/discount_codes_controller.rb', line 14

def create
  with_order_lock do
    @cart.coupon_code = permitted_params[:code]

    coupon_handler.apply

    if coupon_handler.successful?
      render_cart(status: :created)
    else
      render_errors(coupon_handler.error)
    end
  end
end

#destroyObject

DELETE /api/v3/store/carts/:cart_id/discount_codes/:id Remove a discount code from the cart :id is the discount code string (e.g., SAVE10)



31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/spree/api/v3/store/carts/discount_codes_controller.rb', line 31

def destroy
  with_order_lock do
    coupon_handler.remove(params[:id])

    if coupon_handler.successful?
      render_cart
    else
      render_errors(coupon_handler.error)
    end
  end
end