I'm trying to save my customer details into a database. How can I get other customer details like shipping address?
I'm using the following to get the name and order id of the transaction
return actionsenter code here.order.capture().then(function(details) {
> var order_id = details.id;
> var name = details.payer.name.given_name +" "+details.payer.name.surname; }
But when I try to get the address based on the json pattern to get other details its returning undefined
.
var name = details.purchase_units.shipping.address.address_line_1;
https://developer.paypal.com/docs/api/orders/v2/#definitions
Don't use JavaScript to do a capture and then relay details to save it to a database.
Instead, use a server-side integration. Here's the UI code: https://developer.paypal.com/demo/checkout/#/pattern/server
On the server end you will need two corresponding routes, one to 'Set Up Transaction' and one to 'Capture Transaction', documented here: https://developer.paypal.com/docs/checkout/reference/server-integration/
This way, you won't be sending captured details to a server, because the capture will be occurring from a server--and there will be an immediate API response on the server with all the details.
Your particular question about things being undefined just means you need to do better troubleshooting of a console.log(details)
or equivalent to find out the precise location of what you're looking for. It's probably something trivial like needing purchase_units[0]