Module: Spree::OrdersControllerDecorator

Defined in:
app/controllers/spree/orders_controller_decorator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



3
4
5
6
7
# File 'app/controllers/spree/orders_controller_decorator.rb', line 3

def self.prepended(base)
  base.include Spree::BraintreeHelper
  base.helper_method [:asset_available?, :options_from_braintree_payments]
  base.before_action :process_paypal_express, only: :update
end

Instance Method Details

#process_paypal_expressObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/spree/orders_controller_decorator.rb', line 9

def process_paypal_express
  return false if current_order.blank?

  if params[:paypal].blank? || params[:paypal][:payment_method_nonce].blank?
    # when user goes back from checkout, paypal express payments should be invalidated  to ensure standard checkout flow
    current_order.invalidate_paypal_express_payments
    return true
  end
  payment_method = Spree::PaymentMethod.find_by_id(params[:paypal][:payment_method_id])
  return true unless payment_method

  email = params[:order][:email]
  # when user goes back from checkout, order's state should be resetted to ensure paypal checkout flow
  current_order.state = 'cart'
  payment_method.push_order_to_state(current_order, 'address', email)
  current_order.save_paypal_payment(payment_params)

  manage_paypal_addresses
  current_order.remove_phone_number_placeholder

  redirect_to checkout_state_path(current_order.state, paypal_email: email)
end