Class: Spree::Api::V2::Storefront::CheckoutController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Spree::Api::V2::Storefront::CheckoutController
- Includes:
- OrderConcern
- Defined in:
- app/controllers/spree/api/v2/storefront/checkout_controller.rb
Instance Method Summary collapse
- #add_store_credit ⇒ Object
- #advance ⇒ Object
- #complete ⇒ Object
- #create_payment ⇒ Object
- #next ⇒ Object
- #payment_methods ⇒ Object
- #remove_store_credit ⇒ Object
- #select_shipping_method ⇒ Object
- #shipping_rates ⇒ Object
- #update ⇒ Object
- #validate_order_for_payment ⇒ Object
Methods inherited from BaseController
Instance Method Details
#add_store_credit ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/spree/api/v2/storefront/checkout_controller.rb', line 65 def add_store_credit :update, spree_current_order, order_token result = add_store_credit_service.call( order: spree_current_order, amount: params[:amount].try(:to_f) ) render_order(result) end |
#advance ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/spree/api/v2/storefront/checkout_controller.rb', line 17 def advance :update, spree_current_order, order_token check_if_quick_checkout result = advance_service.call(order: spree_current_order, state: params[:state], shipping_method_id: params[:shipping_method_id]) render_order(result) end |
#complete ⇒ Object
27 28 29 30 31 32 33 |
# File 'app/controllers/spree/api/v2/storefront/checkout_controller.rb', line 27 def complete :update, spree_current_order, order_token result = complete_service.call(order: spree_current_order) render_order(result) end |
#create_payment ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/spree/api/v2/storefront/checkout_controller.rb', line 49 def create_payment result = create_payment_service.call(order: spree_current_order, params: params) if result.success? render_serialized_payload(201) { serialize_resource(spree_current_order.reload) } else render_error_payload(result.error) end end |
#next ⇒ Object
9 10 11 12 13 14 15 |
# File 'app/controllers/spree/api/v2/storefront/checkout_controller.rb', line 9 def next :update, spree_current_order, order_token result = next_service.call(order: spree_current_order) render_order(result) end |
#payment_methods ⇒ Object
93 94 95 |
# File 'app/controllers/spree/api/v2/storefront/checkout_controller.rb', line 93 def payment_methods render_serialized_payload { serialize_payment_methods(spree_current_order.collect_frontend_payment_methods) } end |
#remove_store_credit ⇒ Object
76 77 78 79 80 81 |
# File 'app/controllers/spree/api/v2/storefront/checkout_controller.rb', line 76 def remove_store_credit :update, spree_current_order, order_token result = remove_store_credit_service.call(order: spree_current_order) render_order(result) end |
#select_shipping_method ⇒ Object
59 60 61 62 63 |
# File 'app/controllers/spree/api/v2/storefront/checkout_controller.rb', line 59 def select_shipping_method result = select_shipping_method_service.call(order: spree_current_order, params: params) render_order(result) end |
#shipping_rates ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'app/controllers/spree/api/v2/storefront/checkout_controller.rb', line 83 def shipping_rates result = shipping_rates_service.call(order: spree_current_order) if result.success? render_serialized_payload { serialize_shipping_rates(result.value) } else render_error_payload(result.error) end end |
#update ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/spree/api/v2/storefront/checkout_controller.rb', line 35 def update :update, spree_current_order, order_token result = update_service.call( order: spree_current_order, params: params, # defined in https://github.com/spree/spree/blob/main/core/lib/spree/core/controller_helpers/strong_parameters.rb#L19 permitted_attributes: permitted_checkout_attributes, request_env: request.headers.env ) render_order(result) end |
#validate_order_for_payment ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/spree/api/v2/storefront/checkout_controller.rb', line 97 def validate_order_for_payment = [] if spree_current_order.present? validated_order, = Spree::Cart::RemoveOutOfStockItems.call(order: spree_current_order).value << Spree.t(:cart_state_changed) if !validated_order.payment? && params[:skip_state].blank? end if .any? render_serialized_payload(422) do serialized_current_order.deep_merge({ meta: { messages: } }) end else render_serialized_payload { serialized_current_order } end end |