From 1abd542404de77177e8b7275626e0eb0adf10251 Mon Sep 17 00:00:00 2001 From: Ryan Woods Date: Mon, 22 Nov 2021 15:06:46 +0100 Subject: [PATCH] Add Venmo as payment option on checkout Resolves issue/ticket: - https://github.com/solidusio-contrib/solidus_paypal_commerce_platform/issues/136 Setting the payment method preference `enable_venmo` to true will now show a Venmo payment option on checkout for customers whom it is available to (currently only US). --- .../payment_method.rb | 2 ++ .../payment_method_spec.rb | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/models/solidus_paypal_commerce_platform/payment_method.rb b/app/models/solidus_paypal_commerce_platform/payment_method.rb index 600bebfe..0debc6f5 100644 --- a/app/models/solidus_paypal_commerce_platform/payment_method.rb +++ b/app/models/solidus_paypal_commerce_platform/payment_method.rb @@ -12,6 +12,7 @@ class PaymentMethod < SolidusSupport.payment_method_parent_class preference :display_on_cart, :boolean, default: true preference :display_on_product_page, :boolean, default: true preference :display_credit_messaging, :boolean, default: true + preference :enable_venmo, :boolean, default: false def partial_name "paypal_commerce_platform" @@ -73,6 +74,7 @@ def javascript_sdk_url(order: nil, currency: nil) } parameters[:shipping_preference] = 'NO_SHIPPING' if step_names.exclude? 'delivery' + parameters['enable-funding'] = 'venmo' if options[:enable_venmo] "https://www.paypal.com/sdk/js?#{parameters.to_query}" end diff --git a/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb b/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb index dc7ea436..301a17ae 100644 --- a/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb +++ b/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb @@ -119,6 +119,23 @@ def Struct(data) # rubocop:disable Naming/MethodName expect(url.query.split("&")).to include("components=buttons") end end + + context 'when enable_venmo is false' do + let(:order) { instance_double(Spree::Order, checkout_steps: { "foo" => "bar" }) } + + it 'does not include the "enable-funding=venmo" parameter' do + expect(url.query.split("&")).not_to include("enable-funding=venmo") + end + end + + context 'when enable_venmo is true' do + let(:order) { instance_double(Spree::Order, checkout_steps: { "foo" => "bar" }) } + + it 'includes "enable-funding=venmo" as a parameter' do + paypal_payment_method.preferences.update(enable_venmo: true) + expect(url.query.split("&")).to include("enable-funding=venmo") + end + end end private