Reputation: 620
I added PayPal button to React and I want to be able to get the billing address from PayPal
React.useEffect(() => {
window.paypal
.Buttons({
createOrder: (data, actions, err) => {
return actions.order.create({
intent: 'CAPTURE',
purchase_units: [
{
amount: {
currency_code: 'GBP',
value: Math.ceil(total * 0.72411175 * 100) / 100,
},
},
],
})
},
onApprove: async (data, actions) => {
const order = await actions.order.capture()
//console.log(order)
},
onError: (err) => {
console.log(err)
},
})
.render(paypal.current)
}, []) // eslint-disable-line
but this only returns an object with the ID, Name and Email, and I want to be able to get the address, phone number and postal code. How should I do that?
Upvotes: 2
Views: 480
Reputation: 30377
There will be a shipping address in the response. Blow it up to formatted JSON with:
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
console.log(details);
console.log(JSON.stringify( JSON.parse(details) ,null,2) );
//This is where you should show a success message or redirect.
//If you need to anything that touches a server database, use a server-side create and capture instead of the client-side actions.order.create() / .capture()
});
}
Billing information is kept private at PayPal by design, not shared.
Upvotes: 2