Class: Spree::Api::CheckoutsController

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

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Methods inherited from BaseController

#map_nested_attributes_keys, #set_jsonp_format

Methods included from ControllerSetup

included

Instance Method Details

#createObject



18
19
20
21
# File 'app/controllers/spree/api/checkouts_controller.rb', line 18

def create
  @order = Order.build_from_api(current_api_user, nested_params)
  respond_with(@order, :default_template => 'spree/api/orders/show', :status => 201)
end

#updateObject



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

def update
  authorize! :update, @order, params[:order_token]
  respond_with(@order, :default_template => 'spree/api/orders/show') and return if @order.state == "complete"

  if object_params && object_params[:user_id].present?
    @order.update_attribute(:user_id, object_params[:user_id])
    object_params.delete(:user_id)
  end

  if @order.update_attributes(object_params) && @order.next
    state_callback(:after)
    respond_with(@order, :default_template => 'spree/api/orders/show')
  else
    respond_with(@order, :default_template => 'spree/api/orders/could_not_transition', :status => 422)
  end
end