Class: Spree::Api::V1::CheckoutsController

Inherits:
BaseController
  • Object
show all
Includes:
Core::ControllerHelpers::Auth, Core::ControllerHelpers::Order
Defined in:
app/controllers/spree/api/v1/checkouts_controller.rb

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Methods inherited from BaseController

#content_type, #permitted_line_item_attributes

Methods included from ControllerSetup

included

Instance Method Details

#advanceObject



21
22
23
24
25
# File 'app/controllers/spree/api/v1/checkouts_controller.rb', line 21

def advance
  authorize! :update, @order, order_token
  while @order.next; end
  respond_with(@order, default_template: 'spree/api/v1/orders/show', status: 200)
end

#nextObject



13
14
15
16
17
18
19
# File 'app/controllers/spree/api/v1/checkouts_controller.rb', line 13

def next
  authorize! :update, @order, order_token
  @order.next!
  respond_with(@order, default_template: 'spree/api/v1/orders/show', status: 200)
rescue StateMachines::InvalidTransition
  respond_with(@order, default_template: 'spree/api/v1/orders/could_not_transition', status: 422)
end

#updateObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/spree/api/v1/checkouts_controller.rb', line 27

def update
  authorize! :update, @order, order_token

  if @order.update_from_params(params, permitted_checkout_attributes, request.headers.env)
    if current_api_user.has_spree_role?('admin') && user_id.present?
      @order.associate_user!(Spree.user_class.find(user_id))
    end

    return if after_update_attributes

    if @order.completed? || @order.next
      state_callback(:after)
      respond_with(@order, default_template: 'spree/api/v1/orders/show')
    else
      respond_with(@order, default_template: 'spree/api/v1/orders/could_not_transition', status: 422)
    end
  else
    invalid_resource!(@order)
  end
end