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 #310 from RyanofWoods/add-email-to-braintree-customer
Browse files Browse the repository at this point in the history
Add email to Braintree customer
  • Loading branch information
kennyadsl authored May 9, 2022
2 parents c8000c5 + 384490e commit 42e3a0a
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/solidus_paypal_braintree/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ def paypal_payee_email_for(source, options)
def customer_profile_params(payment)
params = {}

params[:email] = payment&.order&.email

if store_in_vault && payment.source.try(:nonce)
params[:payment_method_nonce] = payment.source.nonce
end
Expand Down
79 changes: 79 additions & 0 deletions spec/fixtures/cassettes/gateway/customer.yml

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

50 changes: 50 additions & 0 deletions spec/models/solidus_paypal_braintree/gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,56 @@
end
end

describe '#customer_profile_params' do
subject(:params) { gateway.send(:customer_profile_params, payment) }

let(:payment) do
build(:payment, {
payment_method: gateway,
source: source
})
end

context 'when payment does not belong to an order' do
before { allow(payment).to receive(:order).and_return(nil) }

it 'has the email param as nil' do
expect(subject[:email]).to be_nil
end
end

context 'when payment belongs to an order' do
it 'has no email param' do
expect(subject[:email]).to eq(payment.order.email)
end
end
end

describe "Braintree Customer" do
subject(:customer) { braintree.customer.create(params).customer }

let(:params) { gateway.send(:customer_profile_params, payment) }

let(:payment) do
build(:payment, {
payment_method: gateway,
source: source
})
end

cassette_options = {
cassette_name: 'gateway/customer',
match_requests_on: [:braintree_uri]
}

context "with customer", vcr: cassette_options do
it 'saves the customer email correctly' do
allow(payment.order).to receive(:email).and_return('[email protected]')
expect(subject.email).to eq(payment.order.email)
end
end
end

shared_examples "sources_by_order" do
let(:order) { FactoryBot.create :order, user: user, state: "complete", completed_at: Time.current }
let(:gateway) { new_gateway.tap(&:save!) }
Expand Down

0 comments on commit 42e3a0a

Please sign in to comment.