From 678986cde27f0fcd166452b9087045092d336df4 Mon Sep 17 00:00:00 2001 From: jplecaille Date: Wed, 9 Jun 2010 19:48:01 +0200 Subject: [PATCH] Redirect user to paypal on 'save & continue' --- ...checkouts_controller_with_paypal_express.rb | 7 +++++++ lib/spree/paypal_express.rb | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 lib/spree/checkouts_controller_with_paypal_express.rb diff --git a/lib/spree/checkouts_controller_with_paypal_express.rb b/lib/spree/checkouts_controller_with_paypal_express.rb new file mode 100644 index 0000000..318770d --- /dev/null +++ b/lib/spree/checkouts_controller_with_paypal_express.rb @@ -0,0 +1,7 @@ +module Spree::CheckoutsControllerWithPaypalExpress + def self.included(target) + target.before_filter :redirect_to_paypal_express_form, :only => [:update] + end + + private +end \ No newline at end of file diff --git a/lib/spree/paypal_express.rb b/lib/spree/paypal_express.rb index 92814fc..41a0e14 100644 --- a/lib/spree/paypal_express.rb +++ b/lib/spree/paypal_express.rb @@ -2,7 +2,11 @@ module Spree::PaypalExpress include ERB::Util include ActiveMerchant::RequiresParameters - + + def self.included(target) + target.before_filter :redirect_to_paypal_express_form_if_needed, :only => [:update] + end + def paypal_checkout load_object opts = all_opts(@order, params[:payment_method_id], 'checkout') @@ -143,6 +147,18 @@ module Spree::PaypalExpress end private + def redirect_to_paypal_express_form_if_needed + return unless params[:step] == "payment" + + load_object + + payment_method = PaymentMethod.find(params[:checkout][:payments_attributes].first[:payment_method_id]) + + if payment_method.kind_of?(BillingIntegration::PaypalExpress) || payment_method.kind_of?(BillingIntegration::PaypalExpressUk) + redirect_to paypal_payment_order_checkout_url(@checkout.order, :payment_method_id => payment_method) + end + end + def fixed_opts if Spree::Config[:paypal_express_local_confirm].nil? user_action = "continue"