Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #308 from RyanofWoods/add-bin-to-source
Browse files Browse the repository at this point in the history
Add BIN (bank identification number) to SolidusPaypalBraintree::Source
  • Loading branch information
elia authored Dec 6, 2022
2 parents 5c5c2be + c520a17 commit 6b1194e
Show file tree
Hide file tree
Showing 3 changed files with 336 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/solidus_paypal_braintree/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Source < ::Spree::PaymentSource
scope(:with_payment_profile, -> { joins(:customer) })
scope(:credit_card, -> { where(payment_type: CREDIT_CARD) })

delegate :last_4, :card_type, :expiration_month, :expiration_year, :email,
delegate :bin, :last_4, :card_type, :expiration_month, :expiration_year, :email,
:username, :source_description, to: :braintree_payment_method, allow_nil: true

# Aliases to match Spree::CreditCard's interface
Expand Down
295 changes: 295 additions & 0 deletions spec/fixtures/cassettes/source/bin.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions spec/models/solidus_paypal_braintree/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,46 @@
end
end

describe "#bin" do
subject { payment_source.bin }

let(:method) { new_gateway.tap(&:save!) }
let(:payment_source) { described_class.create!(payment_type: "CreditCard", payment_method: method) }
let(:braintree_client) { method.braintree }

context "when the token is known at braintree", vcr: {
cassette_name: "source/bin",
match_requests_on: [:braintree_uri]
} do
before do
customer = braintree_client.customer.create

method = braintree_client.payment_method.create({
payment_method_nonce: "fake-valid-country-of-issuance-usa-nonce", customer_id: customer.customer.id
})

payment_source.update!(token: method.payment_method.token)
end

it "delegates to the braintree payment method" do
method = braintree_client.payment_method.find(payment_source.token)
expect(subject).to eql(method.bin)
end
end

context 'when the source token is not known at Braintree' do
include_context 'with unknown source token'

it { is_expected.to be_nil }
end

context 'when the source token is nil' do
include_context 'with nil source token'

it { is_expected.to be_nil }
end
end

describe '#display_payment_type' do
subject { described_class.new(payment_type: type).display_payment_type }

Expand Down

0 comments on commit 6b1194e

Please sign in to comment.