Skip to content

Commit

Permalink
Allow control over Venmo PayPal financing option
Browse files Browse the repository at this point in the history
Resolves issue/ticket:
- solidusio#136

If a transaction meets Venmo prerequisites [1], then Venmo button
should appear already on checkout, cart and product page depending
on payment method preferences.

These changes is to give more control to the developer so that they can
disable Venmo by setting the `enable_venmo` to false.
https://developer.paypal.com/docs/business/javascript-sdk/javascript-sdk-configuration/#disable-funding

As it Venmo may have already been showing for developers, the default
was set to true.

The enable-funding option is now also sent over to ensure that the Venmo
button gets rendered if eligible:
https://developer.paypal.com/docs/business/javascript-sdk/javascript-sdk-configuration/#enable-funding
https://developer.paypal.com/docs/business/checkout/pay-with-venmo/integrate-pay-with-venmo/#always-request-venmo

[1] https://developer.paypal.com/docs/business/checkout/pay-with-venmo/#eligibility
  • Loading branch information
RyanofWoods committed Dec 2, 2021
1 parent d22dd9d commit 5f5baef
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ 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
Venmo is currently available to US merchants and buyers. There are also other [prequisites](https://developer.paypal.com/docs/business/checkout/pay-with-venmo/#eligibility).

If the transaction supports Venmo then a button should appear for it on checkout, cart and product page, depending on your `Payment Method` preferences.

If you wish to disable Venmo, then set your `Payment Methods`'s `enable_venmo` preference to `false`. See more about preferences([Configuration](#configuration)) below.

## 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
Expand Down
3 changes: 3 additions & 0 deletions app/models/solidus_paypal_commerce_platform/payment_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: true

def partial_name
"paypal_commerce_platform"
Expand Down Expand Up @@ -73,6 +74,8 @@ 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]
parameters['disable-funding'] = 'venmo' unless options[:enable_venmo]

"https://www.paypal.com/sdk/js?#{parameters.to_query}"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,30 @@ 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 "enable-funding=venmo" as a parameter' do
expect(url.query.split('&')).not_to include('enable-funding=venmo')
end

it 'includes "disable-funding=venmo" as a parameter' do
expect(url.query.split('&')).to include('disable-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

it 'does not include "disable-funding=venmo" as a parameter' do
expect(url.query.split('&')).not_to include('disable-funding=venmo')
end
end
end

private
Expand Down

0 comments on commit 5f5baef

Please sign in to comment.