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 #81 from tvdeyen/transfer-billing-address
Browse files Browse the repository at this point in the history
Send billing address with credit card transactions
  • Loading branch information
adammathys authored May 5, 2017
2 parents d770809 + adac861 commit ad38dec
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/models/solidus_paypal_braintree/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ def transaction_options(source, options, submit_for_settlement = false)
params[:shipping] = braintree_shipping_address(options)
end

if source.credit_card?
params[:billing] = braintree_billing_address(options)
end

if source.customer.present?
params[:customer_id] = source.customer.braintree_customer_id
end
Expand All @@ -273,7 +277,14 @@ def transaction_options(source, options, submit_for_settlement = false)
end

def braintree_shipping_address(options)
address = options[:shipping_address]
braintree_address_attributes(options[:shipping_address])
end

def braintree_billing_address(options)
braintree_address_attributes(options[:billing_address])
end

def braintree_address_attributes(address)
first, last = address[:name].split(" ", 2)
{
first_name: first,
Expand Down
116 changes: 116 additions & 0 deletions spec/fixtures/cassettes/gateway/authorize/credit_card/address.yml

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

32 changes: 32 additions & 0 deletions spec/models/solidus_paypal_braintree/gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
payment_type: payment_type
)
end

let(:payment_type) { SolidusPaypalBraintree::Source::PAYPAL }

describe "saving preference hashes as strings" do
Expand Down Expand Up @@ -115,6 +116,7 @@
end

let(:currency) { 'USD' }

let(:gateway_options) do
{
currency: currency,
Expand All @@ -126,6 +128,15 @@
state: "CA",
zip: "90210",
country: "US"
},
billing_address: {
name: "Dick Grayson",
address1: "15 Robin Walk",
address2: "Apt 123",
city: "Blüdhaven",
state: "CA",
zip: "90210",
country: "US"
}
}
end
Expand Down Expand Up @@ -210,6 +221,27 @@
end
end
end

context "CreditCard transaction", vcr: { cassette_name: 'gateway/authorize/credit_card/address' } do
let(:payment_type) { SolidusPaypalBraintree::Source::CREDIT_CARD }

it 'includes the billing address in the request' do
expect_any_instance_of(Braintree::TransactionGateway).
to receive(:sale).
with(hash_including({
billing: {
first_name: "Dick",
last_name: "Grayson",
street_address: "15 Robin Walk Apt 123",
locality: "Blüdhaven",
postal_code: "90210",
region: "CA",
country_code_alpha2: "US"
}
})).and_call_original
authorize
end
end
end

describe "#capture", vcr: { cassette_name: 'gateway/capture' } do
Expand Down

0 comments on commit ad38dec

Please sign in to comment.