Checkout: Unable to get line1 & line2 of shipping address on shipping change

hkvp
Contributor
Contributor

Hi there,

 

I am integrating smart checkout button (documentation: https://developer.paypal.com/docs/checkout/integrate/#3-render-the-smart-payment-buttons) and listening to shipping address change. I am using below js code for rendering the button 

<script src="https://www.paypal.com/sdk/js?intent=authorize&client-id=MY_CLIENT_ID"> </script>

<scipt>
window.onload = function() {
paypal.Buttons({
createOrder: function(data, actions) {

/*below code can be replaced with an ajax call to server to create order request.

refer https://developer.paypal.com/docs/checkout/reference/server-integration/set-up-transaction/#on-the-c... for info */
console.log('createOrder with payAmt: '+payAmt);
return actions.order.create({
purchase_units: [{
amount: {
value: payAmt
}
}]
});
},


onApprove: function(data, actions) {

// Authorize the transaction
actions.order.authorize().then(function(authorization) {

// Get the authorization id
var authorizationID = authorization.purchase_units[0]
.payments.authorizations[0].id

// Call your server to validate and capture the transaction
return fetch('/paypal-transaction-complete', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
orderID: data.orderID,
authorizationID: authorizationID
})
});
});
},

onShippingChange: function(data, actions) {


console.log('shipping changed: '+JSON.stringify(data));
// Reject all countries other than US
if (data.shipping_address.country_code !== 'US' ) {
return actions.reject();
}


}
}
}).render('#paypal-button-container');
};

</script>

 

During the checkout when shipping address is changed, the data I am getting in onShippingChange doesn't have the complete shipping address. It is missing a few fields like line1, line2. How can I get the complete shipping address here?

 

Any help would be greatly appreciated

 

Thanks & Regards,

HKVP

 

 

Login to Me Too
2 REPLIES 2

Brisbane22
Contributor
Contributor

Hi,

I notice the same thing.

The data.shipping_address in onShippingChange

only has the keys

city, state, country_code, postal_code

 

My guess is Paypal are being ultra careful and not revealing a full address until the payment is executed.

They do send the full address in the payment (I have not tried authorize as you are doing).

Login to Me Too

wild-harts
New Community Member

So what is the solution? There is no solution?
Then what is the point of this function, aren't we supposed to calculate tax/shipping costs based on this function? 
How will we determine tax if we can't know the customer's address? Tax can not be calculated based on city, state and zip code only. 

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.