Class: SolidusPaypalCommercePlatform::OrdersController

Inherits:
Spree::Api::BaseController
  • Object
show all
Includes:
Spree::Core::ControllerHelpers::Auth
Defined in:
lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/orders_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/orders_controller.rb', line 8

def create
  authorize! :create, ::Spree::Order

  @order = ::Spree::Order.create!(
    user: current_api_user,
    store: current_store,
    currency: current_pricing_options.currency
  )

  if @order.contents.update_cart order_params
    # Overriding any existing orders
    cookies.signed[:guest_token] = @order.guest_token
    render json: @order, status: :ok
  else
    render json: @order.errors.full_messages, status: :unprocessable_entity
  end
end

#update_addressObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/orders_controller.rb', line 26

def update_address
  load_order
  authorize! :update, @order, order_token
  paypal_address = SolidusPaypalCommercePlatform::PaypalAddress.new(@order)

  if paypal_address.update(paypal_address_params).valid?
    @order.ensure_updated_shipments
    @order.contents.advance
    render json: {}, status: :ok
  else
    render json: paypal_address.errors.full_messages, status: :unprocessable_entity
  end
end

#verify_totalObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/generators/solidus_paypal_commerce_platform/install/templates/app/controllers/solidus_paypal_commerce_platform/orders_controller.rb', line 40

def verify_total
  load_order
  authorize! :show, @order, order_token

  if total_is_correct?(params[:paypal_total])
    render json: {}, status: :ok
  else
    respond_with(@order, default_template: 'spree/api/orders/expected_total_mismatch', status: 400)
  end
end