From 46a4b77806cf14a8e7c6c5d267ab98c9a48714bb 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). --- README.md | 10 ++++++++++ .../payment_method.rb | 2 ++ .../payment_method_spec.rb | 16 ++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/README.md b/README.md index 90442b3c..729781fb 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,16 @@ With product and cart page checkout, the user is directed to the checkout confir PayPals API does not allow for admin-side payments. Instead, backend users taking payments for customers will need to use the PayPal Virtual Terminal to take payments. [More info is available on the PayPal website.](https://www.paypal.com/merchantapps/appcenter/acceptpayments/virtualterminal?locale.x=en_US) +## Venmo +You can enable Venmo to appear as a funding source/a button below PayPal's button, by updating the Solidus PayPal Commerce `Payment Method`'s preference `enable_venmo` to `true`. See more about preferences below. + +Please note, there are prerequisites you must meet for Venmo to be available to your store and customers. [Read more here](https://developer.paypal.com/docs/business/checkout/pay-with-venmo/#eligibility). + +## Configuration +The easiest way to change the `Payment Method`'s preferences is through admin: `Settings > Payments > "PayPal Commerce Platform" > Edit`. + +See more about preferences [here](https://guides.solidus.io/developers/preferences/add-model-preferences.html#access-your-preferences)/ + ## Development ### Testing the extension 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 d5dff21d..1a8d1b9c 100644 --- a/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb +++ b/spec/models/solidus_paypal_commerce_platform/payment_method_spec.rb @@ -113,6 +113,22 @@ def Struct(data) # rubocop:disable Naming/MethodName expect(url.query.split("&")).to include("components=buttons") end end + + context 'when enable_venmo is false' do + before { paypal_payment_method.preferences.update(enable_venmo: false) } + + 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 + before { paypal_payment_method.preferences.update(enable_venmo: true) } + + it 'includes "enable-funding=venmo" as a parameter' do + expect(url.query.split('&')).to include('enable-funding=venmo') + end + end end private