From edd702e63cf88255ff62d3079fc4f4419471d389 Mon Sep 17 00:00:00 2001 From: fastjames Date: Mon, 7 Jan 2019 14:05:06 -0600 Subject: [PATCH] Make nonce-only payment sources non-reusable Solidus tries to present reusable payment sources to customers from their wallet. Subscriptions can cause a non-reusable payment source to be added to the user's wallet. We need to prevent that source from being made available to users, since the nonce will almost certainly fail. --- app/models/solidus_paypal_braintree/source.rb | 2 +- .../solidus_paypal_braintree/source_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/solidus_paypal_braintree/source.rb b/app/models/solidus_paypal_braintree/source.rb index 9719111c..75c80157 100644 --- a/app/models/solidus_paypal_braintree/source.rb +++ b/app/models/solidus_paypal_braintree/source.rb @@ -67,7 +67,7 @@ def paypal? end def reusable? - true + token.present? end def credit_card? diff --git a/spec/models/solidus_paypal_braintree/source_spec.rb b/spec/models/solidus_paypal_braintree/source_spec.rb index d0c09f4a..b5487823 100644 --- a/spec/models/solidus_paypal_braintree/source_spec.rb +++ b/spec/models/solidus_paypal_braintree/source_spec.rb @@ -332,4 +332,20 @@ it { is_expected.to be_nil } end end + + describe '#reusable?' do + let(:payment_source) { described_class.new(token: token, nonce: nonce) } + let(:nonce) { 'nonce67890' } + subject { payment_source.reusable? } + + context 'when source token is present' do + let(:token) { 'token12345' } + it { is_expected.to be_truthy } + end + + context 'when source token is nil' do + let(:token) { nil } + it { is_expected.to be_falsy } + end + end end