From c1f8854e1525d37404964e215589e8c9171c9f69 Mon Sep 17 00:00:00 2001 From: Bounmy Stephane Date: Mon, 9 Apr 2012 19:53:31 +0200 Subject: [PATCH] cache payment_method and can now set paypal's landing page by setting allow_guest_checkout --- .../spree/checkout_controller_decorator.rb | 4 ++-- .../spree/billing_integration/paypal_express.rb | 2 +- spec/controllers/checkout_controller_spec.rb | 11 ++++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/spree/checkout_controller_decorator.rb b/app/controllers/spree/checkout_controller_decorator.rb index c516699..ad3d68f 100644 --- a/app/controllers/spree/checkout_controller_decorator.rb +++ b/app/controllers/spree/checkout_controller_decorator.rb @@ -226,7 +226,7 @@ module Spree # hook to override paypal site options def paypal_site_opts - {:currency => payment_method.preferred_currency} + {:currency => payment_method.preferred_currency, :allow_guest_checkout => payment_method.preferred_allow_guest_checkout } end def order_opts(order, payment_method, stage) @@ -362,7 +362,7 @@ module Spree # create the gateway from the supplied options def payment_method - Spree::PaymentMethod.find(params[:payment_method_id]) + @payment_method ||= Spree::PaymentMethod.find(params[:payment_method_id]) end def paypal_gateway diff --git a/app/models/spree/billing_integration/paypal_express.rb b/app/models/spree/billing_integration/paypal_express.rb index 635dee8..cdf5492 100644 --- a/app/models/spree/billing_integration/paypal_express.rb +++ b/app/models/spree/billing_integration/paypal_express.rb @@ -5,9 +5,9 @@ class Spree::BillingIntegration::PaypalExpress < Spree::BillingIntegration preference :review, :boolean, :default => false preference :no_shipping, :boolean, :default => false preference :currency, :string, :default => 'USD' + preference :allow_guest_checkout, :boolean, :default => false def provider_class ActiveMerchant::Billing::PaypalExpressGateway end - end diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index 4bcfc21..e559811 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -6,7 +6,7 @@ module Spree let(:order) { Factory(:ppx_order_with_totals, :state => "payment") } let(:order_total) { (order.total * 100).to_i } let(:gateway_provider) { mock(ActiveMerchant::Billing::PaypalExpressGateway) } - let(:paypal_gateway) { mock(BillingIntegration::PaypalExpress, :id => 123, :preferred_review => false, :preferred_no_shipping => true, :provider => gateway_provider, :preferred_currency => "US" + let(:paypal_gateway) { mock(BillingIntegration::PaypalExpress, :id => 123, :preferred_review => false, :preferred_no_shipping => true, :provider => gateway_provider, :preferred_currency => "US", :preferred_allow_guest_checkout => true ) } let(:details_for_response) { mock(ActiveMerchant::Billing::PaypalExpressResponse, :success? => true, @@ -289,5 +289,14 @@ module Spree end + + describe "#paypal_site_opts" do + it "returns opts to allow guest checkout" do + controller.should_receive(:payment_method).at_least(1).and_return(paypal_gateway) + + opts = controller.send(:paypal_site_opts) + opts[:allow_guest_checkout].should be_true + end + end end end \ No newline at end of file