PayerOne will send order events with the final status to the URL specified during order creation (ipn_url) whenever the payment status changes. This ensures you receive timely updates on the progress of the payment.
When an order is paid successfully, the event charge:confirmed will be sent in the raw body. After receiving this event, follow up by verifying the order to process the invoice as paid.
Event Raw JSON formate
{
"event": {
"type": "charge:confirmed",
"data": {
"order_id": "f099ce1e-45be-4373-b08f-485be22fcc51"
}
}
}
Example source code.
$_token = 'aaaa.bbbb.ccccc'; // Token can we found in https://account.gsmcoin.com/merchant
$rawBody = trim(file_get_contents("php://input"));
$decodedBody = json_decode($rawBody, true);
$event = $decodedBody['event']['type'];
$order_id = $decodedBody['event']['data']['order_id'];
// if event is order is paid
if ($event == 'charge:confirmed') {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.gsmcoin.com//checkout//v1/orders?order_id=$order_id",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer $_token"
),
));
$response = curl_exec($curl);
curl_close($curl);
$Result = json_decode($response, true)['data'];
if ($Result['status']==='Paid') {
print_r($Result);
}
}
const token = 'aaaa.bbbb.ccccc'; // Token can we found in https://account.gsmcoin.com/merchant
const rawBody = await (await fetch('https://your-server-endpoint', { method: 'POST' })).text();
const decodedBody = JSON.parse(rawBody);
const event = decodedBody.event.type;
const order_id = decodedBody.event.data.order_id;
// if event is order is paid
if (event === 'charge:confirmed') {
const response = await fetch(`https://api.gsmcoin.com/checkout/v1/orders?order_id=${order_id}`, {
method: 'GET',
headers: {
"Authorization": `Bearer ${token}`
}
});
const result = await response.json();
const data = result.data;
if (data.status === 'Paid') {
console.log(data);
}
}