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

Add email to Braintree customer #310

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -398,6 +398,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