1

I'm new to using PayPal API Express Checkout, i have a question. How to convert/get the response value from paypal. here is my response string;

{ "id": "PAY-XXXXXXXXXX272783PKXTZ4NI", "create_time": "2015-09-03T01:11:17Z", "update_time": "2015-09-03T01:12:21Z", "state": "approved", "intent": "sale", "payer": { "payment_method": "paypal", "payer_info": { "email": "XXXXXXXXX-buyer@gmail.com", "first_name": "test", "last_name": "buyer", "payer_id": "PJ9LKYDVZXXXX", "shipping_address": { "line1": "1 Main St", "city": "San Jose", "state": "CA", "postal_code": "95131", "country_code": "US", "recipient_name": "test buyer" } } }, "transactions": [ { "amount": { "total": "700.00", "currency": "PHP", "details": { "subtotal": "590.00", "shipping": "110.00" } }, "description"...

I want to get it like this:

$ID  = $response["id"];
$shipping_add_array  = $response["shipping_address"];
echo $shipping_add_array["state"];

Thank you for your help. i have not been able to figure this out for a week

NightShadeQueen
  • 3,284
  • 3
  • 24
  • 37
J.Aries
  • 99
  • 7

1 Answers1

3

You are close - add json_decode():

$response = json_decode($paypal_response, true);
$ID  = $response["id"];

To get shipping address, you will need to dig deeper:

$shipping_add_array  = $response["payer"]["payer_info"]["shipping_address"];
echo $shipping_add_array["state"];

You could get JSON formatter to help you figure out the nested levels of the object (easier to visualize nested json data) - example plugin I found: (no affiliation with the developer)

chrome.google.com/webstore/detail/json-formatter/bcjindcccaagfpapjjmafapmmgkkhgoa?hl=en

Songshu
  • 41
  • 3