Class: Spree::Api::V1::CheckoutsController
Instance Attribute Summary
#current_api_user
Instance Method Summary
collapse
#content_type, #permitted_line_item_attributes
included
Instance Method Details
#advance ⇒ Object
15
16
17
18
19
|
# File 'app/controllers/spree/api/v1/checkouts_controller.rb', line 15
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
7
8
9
10
11
12
13
|
# File 'app/controllers/spree/api/v1/checkouts_controller.rb', line 7
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
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'app/controllers/spree/api/v1/checkouts_controller.rb', line 21
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
|