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

Inherits:
BaseController
  • Object
show all
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



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

#nextObject



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

#updateObject



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.headers.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