Class: Spree::Api::V1::CheckoutsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Spree::Api::V1::CheckoutsController
show all
- Includes:
- Core::ControllerHelpers::Auth, Core::ControllerHelpers::Order
- Defined in:
- app/controllers/spree/api/v1/checkouts_controller.rb
Instance Attribute Summary
#current_api_user
Instance Method Summary
collapse
#content_type, #permitted_line_item_attributes
included
Instance Method Details
#advance ⇒ Object
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
|
#next ⇒ Object
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
|
#update ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# 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..env)
if current_api_user.has_spree_role?('admin') && user_id.present?
@order.associate_user!(Spree.user_class.find(user_id))
end
log_state_changes if params[:state]
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
|