Since you are using the data-resulturl
parameter, once a transaction is complete the user will be redirected to the page you specify (in your example it is http://
www.mysite.com/responseMsg.php
). On this page, an AccessCode will be added to the query string - this can be used to fetch the result of the transaction.
So you can use the AccessCode in your code as you would any query variable: $_GET['AccessCode']
.
You can fetch the result of the transaction using eWAY's Transaction Query API. An example of doing this would look like:
<?php
// eWAY API key & Password
$api_key = '60CF3Ce97nRS1Z1Wp5m9kMmzHHEh8Rkuj31QCtVxjPWGYA9FymyqsK0Enm1P6mHJf0THbR';
$api_password = 'API-P4ss';
$ch = curl_init();
// Note: using the Sandbox API endpoint
curl_setopt($ch, CURLOPT_URL, 'https://api.sandbox.ewaypayments.com/Transaction/'.$_GET['AccessCode']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $api_key . ":" . $api_password);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$output = curl_exec($ch);
curl_close($ch);
$result = json_decode($output);
if ($result->Transactions[0]->TransactionStatus) {
echo "Transaction successful";
} else {
echo "Transaction declined";
}