Get buyer information via javascript function

ajarrow
Contributor
Contributor

In my checkout flow, I am redirecting to a confirmation page where I would like to show the buyer name and address. Is there any way to get that information and insert it via javascript? I just need to know how to get the info in my PayPal checkout function in javascript. Thanks

Login to Me Too
1 ACCEPTED SOLUTION

Accepted Solutions
Solved

ajarrow
Contributor
Contributor

Actually, I got most of this figured out by studying the docs. As for the buyer address, I got that (and the full name as well) by going into this:

details.purchase_units[0].shipping

Then, as I am using vanilla Javascript, I created this:

var buyerInfo = [details.purchase_units[0].shipping.name.full_name, details.purchase_units[0].shipping.address.address_line_1, details.purchase_units[0].shipping.address.admin_area_2, details.purchase_units[0].shipping.address.admin_area_1, details.purchase_units[0].shipping.address.postal_code, details.id];

And then I added it to sessionStorage and went from there. This way I was able to get the full name with one line and it was the only place I could find an address. Thanks so much for your help!

View solution in original post

Login to Me Too
3 REPLIES 3

JackieDaytona
Contributor
Contributor

Buyer name gets returned in onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {

The buyer first name and last name are in the details function

So using JQuery to get them 

        $('#transmsg').html('<b>' + 'AUTHORIZED...' + '</b>');
        $('#transmsg').append('<br>'+'Transaction completed by: ' + details.payer.name.given_name +' '+ details.payer.name.surname + '<br>' + "Order Id: "          + details.id + '<br>' + 'Status: PAID & APPROVED' + '<br>'+ 'Thank You For Your Order'+ '<br>');

Now the address is a bit tricky as you to get that from an IPN call.  Personally, IPN were a PAIN in the **bleep** so I deccided NOT to use them/it.

But if you REALLY need the address go for it. 

 

 

Login to Me Too
Solved

ajarrow
Contributor
Contributor

Actually, I got most of this figured out by studying the docs. As for the buyer address, I got that (and the full name as well) by going into this:

details.purchase_units[0].shipping

Then, as I am using vanilla Javascript, I created this:

var buyerInfo = [details.purchase_units[0].shipping.name.full_name, details.purchase_units[0].shipping.address.address_line_1, details.purchase_units[0].shipping.address.admin_area_2, details.purchase_units[0].shipping.address.admin_area_1, details.purchase_units[0].shipping.address.postal_code, details.id];

And then I added it to sessionStorage and went from there. This way I was able to get the full name with one line and it was the only place I could find an address. Thanks so much for your help!

Login to Me Too

JackieDaytona
Contributor
Contributor
Ah thanx for that address bit. Did not know it got returned like that. Might need it in the future ..:) JD
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.