Class: Spree::Api::CouponCodesController

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

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Instance Method Details

#createObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/spree/api/coupon_codes_controller.rb', line 9

def create
  authorize! :update, @order, order_token

  @order.coupon_code = params[:coupon_code]
  @handler = Spree::Config.coupon_code_handler_class.new(@order).apply

  if @handler.successful?
    render 'spree/api/promotions/handler', status: 200
  else
    logger.error("apply_coupon_code_error=#{@handler.error.inspect}")
    render 'spree/api/promotions/handler', status: 422
  end
end

#destroyObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/spree/api/coupon_codes_controller.rb', line 23

def destroy
  authorize! :update, @order, order_token

  @order.coupon_code = params[:id]
  @handler = Spree::Config.coupon_code_handler_class.new(@order).remove

  if @handler.successful?
    render 'spree/api/promotions/handler', status: 200
  else
    logger.error("remove_coupon_code_error=#{@handler.error.inspect}")
    render 'spree/api/promotions/handler', status: 422
  end
end