Skip to content

Commit

Permalink
Add Venmo as payment option on checkout
Browse files Browse the repository at this point in the history
Resolves issue/ticket:
- solidusio#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).
  • Loading branch information
RyanofWoods committed Nov 23, 2021
1 parent 35524e8 commit 1abd542
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 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: false

def partial_name
"paypal_commerce_platform"
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1abd542

Please sign in to comment.