This is an example of the instant payment notification (IPN) I receive from clickbank:
$decrypted = {"transactionTime":"2014-10-06T14:49:00-07:00","receipt":"********","transactionType":"TEST","vendor":"comclub","role":"VENDOR","totalAccountAmount":1.00,"paymentMethod":"VISA","totalOrderAmount":1.00,"totalTaxAmount":0.00,"totalShippingAmount":0.00,"currency":"USD","lineItems":[{"itemNo":"1","productTitle":"A passed in title","shippable":false,"recurring":false,"accountAmount":1.00}],"customer":{"shipping":{"firstName":"TEST","lastName":"USER","fullName":"Test User","email":"[email protected]","address":{}},"billing":{"firstName":"TEST","lastName":"USER","fullName":"Test User","email":"[email protected]","address":{}}},"version":6.0,"attemptCount":1}
so I do $order = json_decode($decrypted);
Now I want to get the individual variables out.
At first, it works fine. For example, I can do
$transactionTime = $order->transactionTime;
but when I get to the 2nd-level stuff with lineItems, I'm at a loss.
I've tried all kinds of things:
$itemNo = $order['lineItems']['itemNo'];
$itemNo = $order['lineItems']->itemNo;
$lineItems = $order['lineItems'];
$itemNo = $lineItems['itemNo'];
but nothing seems to work.
I've also tried
$order = json_decode($decrypted, TRUE);
but that didn't work either
Does anyone know how to get the itemNo variable for example?
thanks
You've decoded the JSON as an object, so you'll need to treat it as one.
To access
lineItems
, you'll need$order->lineItems
. You should also note thatlineItems
is an array of objects and handle it accordingly. For example$order->lineItems[0]->itemNo
.Here's a demo.
In the future, use
var_dump
if you're unsure of an object or array's structure. It will help you tremendously.