IPN (Instant Payment Notification)
Payment notification
The process of payment and confirmation of payment can take from several minutes to several hours. Our service will notify you when the transaction is credited, by sending a POST request with the information to the address you specified. The notification will be twice: after the transaction appears on the network and after its 12th confirmation.
Data structure
Data in JSON-format:
{
etherapi.net: version
type: notification type = (in / track / out)
date: date
from: payer address
to: destination address
amount: amount
txid: hash of transaction
confirmations: number of confirmations = (0 / 12)
tag: label
sign: signature
}
Signature verification
To verify the signature, you must obtain a hash from the incoming data and compare it with the value in the sign field. The hash is the result of the function sha1 from the string received by connecting through the colon (:) of the values of the fields type, date, from, to, amount, txid, confirmations, tag and token.
Example code for an IPN handler in PHP:
...
if (!$_POST)
$_POST = @json_decode(file_get_contents('php://input'), true);
if (!$_POST['etherapi.net'])
return;
$sign = sha1(implode(':', array(
$_POST['type'],
$_POST['date'],
$_POST['from'],
$_POST['to'],
$_POST['amount'],
$_POST['txid'],
$_POST['confirmations'],
$_POST['tag'],
$cfg['token'] // API access token
)));
if ($sign !== $_POST['sign'])
die('Sign wrong'); // this answer will be visible in the office
echo('OK');
...