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

Stop importing address from PayPal #227

Closed
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
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,13 @@ A PayPal button can also be included on the cart view to enable express checkout
render "spree/shared/paypal_cart_button"
```

#### PayPal configuration
#### PayPal

If your store requires the [phone number into user addresses](https://github.com/solidusio/solidus/blob/859143f3f061de79cc1b385234599422b8ae8e21/core/app/models/spree/address.rb#L151-L153)
you'll need to configure PayPal to return the phone back when it returns the
address used by the user:
##### Known limitations

1. Log into your PayPal account
2. Go to Profile -> My Selling Tools -> Website preferences
3. Set Contact Telephone to `On (Required Field)` or `On (Optional Field)`

Using the option `Off` will not make the address valid and will raise a
validation error.
It's not possible to let the user update the address via PayPal, because of
storing formats incompatibilities between PayPal and Solidus; thus be sure that
the PayPal client configuration has `shippingAddressEditable` set to `false`.

## Optional configuration

Expand Down
36 changes: 1 addition & 35 deletions app/assets/javascripts/solidus_paypal_braintree/paypal_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,41 +104,7 @@ SolidusPaypalBraintree.PaypalButton.prototype._transactionParams = function(payl
"email" : payload.details.email,
"phone" : payload.details.phone,
"nonce" : payload.nonce,
"payment_type" : payload.type,
"address_attributes" : this._addressParams(payload)
"payment_type" : payload.type
}
};
};

/**
* Builds the address parameters to submit to Solidus using the payload
* returned by Braintree
*
* @param {object} payload - The payload returned by Braintree after tokenization
*/
SolidusPaypalBraintree.PaypalButton.prototype._addressParams = function(payload) {
var first_name, last_name;
var payload_address = payload.details.shippingAddress || payload.details.billingAddress;
if (!payload_address) return {};

if (payload_address.recipientName) {
first_name = payload_address.recipientName.split(" ")[0];
last_name = payload_address.recipientName.split(" ")[1];
}

if (!first_name || !last_name) {
first_name = payload.details.firstName;
last_name = payload.details.lastName;
}

return {
"first_name" : first_name,
"last_name" : last_name,
"address_line_1" : payload_address.line1,
"address_line_2" : payload_address.line2,
"city" : payload_address.city,
"state_code" : payload_address.state,
"zip" : payload_address.postalCode,
"country_code" : payload_address.countryCode
};
};
2 changes: 1 addition & 1 deletion app/models/solidus_paypal_braintree/transaction_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def import!(end_state, restart_checkout: false)
if valid?
order.email = user.try!(:email) || transaction.email

if address
if address && !source.paypal?
order.shipping_address = order.billing_address = address
# work around a bug in most solidus versions
# about tax zone cachine between address changes
Expand Down
48 changes: 36 additions & 12 deletions spec/models/solidus_paypal_braintree/transaction_import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,47 @@
state_code: 'NY', address_line_1: '350 5th Ave', zip: '10118'
end

it 'uses the new address', aggregate_failures: true do
subject
expect(order.shipping_address.address1).to eq '350 5th Ave'
expect(order.shipping_address.country).to eq country
expect(order.shipping_address.state).to eq new_york
context 'when the transaction payment method is ApplePay' do
let(:transaction) do
SolidusPaypalBraintree::Transaction.new nonce: 'fake-valid-nonce',
payment_method: payment_method, address: transaction_address,
payment_type: SolidusPaypalBraintree::Source::APPLE_PAY,
phone: '123-456-7890', email: '[email protected]'
end

it 'uses the new address', aggregate_failures: true do
subject
expect(order.shipping_address.address1).to eq '350 5th Ave'
expect(order.shipping_address.country).to eq country
expect(order.shipping_address.state).to eq new_york
end

context 'with a tax category' do
before do
zone = Spree::Zone.create name: 'nyc tax'
zone.members << Spree::ZoneMember.new(zoneable: new_york)
create :tax_rate, zone: zone
end

it 'includes the tax in the payment' do
subject
expect(order.payments.first.amount).to eq 16
end
end
end

context 'with a tax category' do
before do
zone = Spree::Zone.create name: 'nyc tax'
zone.members << Spree::ZoneMember.new(zoneable: new_york)
create :tax_rate, zone: zone
context 'when the transaction payment method is PayPal' do
let(:transaction) do
SolidusPaypalBraintree::Transaction.new nonce: 'fake-valid-nonce',
payment_method: payment_method, address: transaction_address,
payment_type: SolidusPaypalBraintree::Source::PAYPAL,
phone: '123-456-7890', email: '[email protected]'
end

it 'includes the tax in the payment' do
it 'skips the address importing', aggregate_failures: true do
subject
expect(order.payments.first.amount).to eq 16
expect(order.shipping_address.address1).not_to eq '350 5th Ave'
expect(order.shipping_address.state).not_to eq new_york
end
end

Expand Down