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 #112 from tvdeyen/fix-paypal-address-retrievel
Browse files Browse the repository at this point in the history
Fix the address retrieval on the PayPal payload
  • Loading branch information
adammathys authored Oct 11, 2017
2 parents 8c9805b + 69e28ca commit c1493eb
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions app/assets/javascripts/solidus_paypal_braintree/paypal_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,27 @@ SolidusPaypalBraintree.PaypalButton.prototype._transactionParams = function(payl
* @param {object} payload - The payload returned by Braintree after tokenization
*/
SolidusPaypalBraintree.PaypalButton.prototype._addressParams = function(payload) {
if (payload.details.shippingAddress.recipientName) {
var first_name = payload.details.shippingAddress.recipientName.split(" ")[0];
var last_name = payload.details.shippingAddress.recipientName.split(" ")[1];
var first_name, last_name;
var payload_address = payload.details.shippingAddress || payload.details.billingAddress;

if (payload_address.recipientName) {
first_name = payload_address.recipientName.split(" ")[0];
last_name = payload_address.recipientName.split(" ")[1];
}
if (first_name == null || last_name == null) {
var first_name = payload.details.firstName;
var last_name = payload.details.lastName;

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.details.shippingAddress.line1,
"address_line_2" : payload.details.shippingAddress.line2,
"city" : payload.details.shippingAddress.city,
"state_code" : payload.details.shippingAddress.state,
"zip" : payload.details.shippingAddress.postalCode,
"country_code" : payload.details.shippingAddress.countryCode
}
"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
};
};

0 comments on commit c1493eb

Please sign in to comment.