I'm receiving an HTTP Post with the following JSON object:
{"notification":{"version":6.0,"attemptCount":0,"role":"VENDOR","site":"nicholeen","receipt":"********","currency":"USD","transactionType":"TEST","transactionTime":1406070122781,"paymentMethod":"VISA","totalProductAmount":1.00,"totalTaxAmount":0.00,"totalShippingAmount":0.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":{}}},"lineItems":[{"itemNo":"1","productTitle":"A passed in title","shippable":false,"recurring":false,"customerProductAmount":1.00,"customerTaxAmount":0.00}]},"verification":"2745A502"}
I need to Convert the "notification" JSON object into a JSON string assigned to a PHP variable without losing any data, including the decimals.
Currently I'm receiving the IPN using $ipn_raw = file_get_contents('php://input');.
Then I json_decode the JSON to a PHP variable, then re-encode the notification portion using json_encode. Here's the code:
$ipn_raw = file_get_contents('php://input');
$ipn = json_decode($ipn_raw);
$notification = $ipn['notification'];
$result = json_encode($notification);
However, the result strips some values giving me the following:
{"version":6,"attemptCount":0,"role":"VENDOR","site":"nicholeen","receipt":"********","currency":"USD","transactionType":"TEST","transactionTime":1406095846441,"paymentMethod":"VISA","totalProductAmount":1,"totalTaxAmount":0,"totalShippingAmount":0,"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":[]}},"lineItems":[{"itemNo":"1","productTitle":"A passed in title","shippable":false,"recurring":false,"customerProductAmount":1,"customerTaxAmount":0}]}
You can see that version 6.0 is now just version 6, totalProductAmount was 1.00 and is now 1, etc.
How can I do this without any values changing in the result?
Thanks!
Per request, here's some extra background information for why I need everything to be unchanged from the original. Clickbank has given me the following information in order to create the necessary SHA 1 hash to validate the Version 6 IPN I receive from them (see https://support.clickbank.com/entries/22803622-Instant-Notification-Service)
1) Use a JSON library/DSL to extract the “notification” JSON object from the IPN. 2) Convert the "notification" JSON object into a JSON string. The string should begin with a curly brace { and end with a curly brace } as it is a representation of a JSON object. 3) Append the secret key directly onto the string after the end curly brace of the notification object. No spaces or separator characters. 4) SHA 1 hash the string created in step 3. 5) Take the first 8 characters of the hash created in step 4. That’s the value of the "verification" field in the v6 IPN.
If needed I could provide all my code for the rest of the steps, but at this point the only part I'm having problems with is getting the notification object in a string by itself.
6.0and6are just two different respresentations of the same number. You can even try with PHP:var_dump(6.0 == 6); // will print true{ "v" : 1 }and{"v":1}describe the same object too.