Skip to main content

Payment Handler Sample

There is a sample code in popular languages to implement payment handling.

$private_key = '8c29558bjiiiif354ccd22629207dd8';
$parameters = $_POST;
$signature = '';
unset($parameters['sign']);
ksort($parameters);
foreach ($parameters as $k => $v) {
$signature .= $k . '=' . $v;
}
$signature = hash('md5', $signature . $private_key);
if ($_POST['sign'] == $signature) {
// check if transaction_id was successful
$localTransaction = []; // get it from your database by $parameters['transaction_id']
if($localTransaction && $localTransaction['status'] == 'success'){
$result = [
'status' => 'success',
'transaction_id' => $localTransaction['id'],
];
echo json_encode($result);
exit;
}
// if $parameters['transaction_id'] is new - you'll need to try handle
// it in next steps

// your code here

$successfulGameCharge = true;
if ($successfulGameCharge) {
$result = [
'status' => 'success',
'transaction_id' => $localTransaction['id'],
];
} else {
$result = [
'status' => 'error',
'error_message' => 'Payment was not charged.',
];
}
} else {
$result = [
'status' => 'error',
'error_message' => 'Signature is incorrect.',
];
}
echo json_encode($result);