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 #175 from alepore/add-existing-payment-partial
Browse files Browse the repository at this point in the history
Add existing payments partial
  • Loading branch information
kennyadsl authored Nov 23, 2018
2 parents ce57527 + e2a57d6 commit 3242cb8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
10 changes: 7 additions & 3 deletions app/models/solidus_paypal_braintree/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Source < SolidusSupport.payment_source_parent_class
scope(:with_payment_profile, -> { joins(:customer) })
scope(:credit_card, -> { where(payment_type: CREDIT_CARD) })

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

# Aliases to match Spree::CreditCard's interface
Expand Down Expand Up @@ -75,13 +75,17 @@ def credit_card?
end

def display_number
"XXXX-XXXX-XXXX-#{last_digits.to_s.rjust(4, 'X')}"
if paypal?
email
else
"XXXX-XXXX-XXXX-#{last_digits.to_s.rjust(4, 'X')}"
end
end

private

def braintree_payment_method
return unless braintree_client && credit_card?
return unless braintree_client
@braintree_payment_method ||= protected_request do
braintree_client.payment_method.find(token)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<tr id="<%= dom_id(wallet_payment_source, 'spree')%>" class="<%= cycle('even', 'odd') %>">
<td>
<%= radio_button_tag "order[wallet_payment_source_id]",
wallet_payment_source.id,
default,
class: "existing-cc-radio" %>
</td>
<td><%= wallet_payment_source.payment_source.friendly_payment_type %></td>
<td><%= wallet_payment_source.payment_source.display_number %></td>
</tr>
13 changes: 12 additions & 1 deletion spec/models/solidus_paypal_braintree/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@
end

describe "#display_number" do
let(:payment_source) { described_class.new }
let(:type) { nil }
let(:payment_source) { described_class.new(payment_type: type) }
subject { payment_source.display_number }

context "when last_digits is a number" do
Expand All @@ -281,6 +282,16 @@

it { is_expected.to eq 'XXXX-XXXX-XXXX-XXXX' }
end

context "when is a PayPal source" do
let(:type) { "PayPalAccount" }

before do
allow(payment_source).to receive(:email).and_return('[email protected]')
end

it { is_expected.to eq '[email protected]' }
end
end

describe "#card_type" do
Expand Down

0 comments on commit 3242cb8

Please sign in to comment.