How to understand a response received from a CC processing operation?

Hi All,

I am writing a “pay your invoice on-line” application.

When a payment has been accepted by the processing company a response is received that contains the information on the transaction. Problem is I am not sure how to read it.

I have posted a small piece of the response below

{“Transactions”:“AuthorisationCode”:“264554”,
“ResponseCode”:“00”,
“ResponseMessage”:“A2000”,
“InvoiceNumber”:“23802”,
“InvoiceReference”:“238027264”,
“TotalAmount”:100,
“TransactionID”:241458162,
“TransactionStatus”:true}

What is all of the colons for, and how do you obtain only the data (at the end of each entry. eg. 264554

Thanks

Tony

That format is called JSON. You can use the PHP function json_decode to decode it into an array or object and then use its values.

Thanks Mamede,
I have progressed a small amount, but I am struggling a bit with the getting the data from the JSON string

This is the code I use to try to parse it.
$client = \Eway\Rapid::createClient($apiKey, $apiPassword, $apiEndpoint);
$response = $client->queryTransaction($access_code);
$transactionResponse = $response->Transactions[0];

echo 'Payment successful! ID: '.$transactionResponse->TransactionID;
{tran_code} = $transactionResponse->TransactionID;
{tran_aprove} = $transactionResponse->AuthorisationCode;
{inv_amount} = $transactionResponse->TotalAmount;
{inv_amount} = {inv_amount} / 100;
{inv_num} = $transactionResponse->InvoiceNumber;
{inv_paynum} = $transactionResponse->InvoiceReference;

Strangely, the echo statement works and returns the correct information, but when I try to get that result into a variable and display it, it does not display anything in the fields.

Is there anything obvious that I have missed?
Thanks
Tony

The code you posted should have worked.
Can you run the code above and post a print screen of the result?

$client = \Eway\Rapid::createClient($apiKey, $apiPassword, $apiEndpoint);
$response = $client->queryTransaction($access_code);

echo "<pre>";
var_dump($response);
die();

Here is the text (it is very long - so placed it in a text file.
See ya
Tony [ATTACH]n80739[/ATTACH]

response.txt (10.8 KB)

It is the attributes section that contains the data I need.

Thanks

Try this code and see if tran_code is correct:

{tran_code} = (string)$transactionResponse->TransactionID;