Checking payment status
Checking payment status
URL | POST https://api-merchant.alikassa.com/v1/payment/status |
HEADER | |
Content-Type | application/json |
Account | Your account uuid, you can find in Accounts https://merchant.alikassa.com/cabinet/resources/project-accounts |
Sign | Request signature |
Link https://merchant.alikassa.com/cabinet/form/setting-api-certs generate "API certificate for payment", save the archive, unpack
- password.txt
- private.pem
- public.pem
We keep only public.pem for signature verification.
Wrap all POST data in json (in the same order) and sign
$data = json_encode($data);
$privateKey = openssl_pkey_get_private(
file_get_contents('private.pem'),
file_get_contents('password.txt')
);
if ($privateKey===false) {
throw new \Exception('Error cert.');
}
openssl_sign($data, $sign, $privateKey);
$sign = base64_encode($sign);
Pass the received $sign in the Sign header. You can find a sample code at the end of the document.
Name | Type | Description |
order_id | string (128) | Your id specified during creation |
id | string (128) | AliKassa payment id |
You must pass order_id or id.
Response
Name | Description |
order_id | Your id specified during creation |
id | AliKassa payment id |
url | Link to payment |
payment_status | Payment status wait — in the process of payment paid — successfully paid (final status) cancel — canceled (final status) fail — error (final status) |
card_mask | Card mask when paying by card |
amount | Amount |
payment_amount | Фактическая сумма оплаты |
hold_amount | Hold amount |
hold_at | Date credited from hold to balance |
account_payment_amount | Amount credited to the account |
commission_amount | Commission |
service_code | Service |
account_old_balance | Balance before making a request |
account_new_balance | Balance after request processing |
Example of a successful HTTP CODE 200 response:
{
"url": "https://pay-merchant.alikassa.com/b05119d2-206b-3d04-8365-293b3008b8b0",
"payment_status": "paid",
"id": 100000536,
"order_id": "6422494",
"card_mask": "516874******8284",
"amount": "300",
"payment_amount": "350",
"hold_amount": "0",
"hold_at": null,
"account_payment_amount": "290",
"commission_amount": "10",
"service_code": "payment_card_rub",
"account_old_balance": "1000",
"account_new_balance": "1290"
}
An example of an unsuccessful HTTP CODE 400 response:
{
"message": "The given data was invalid.",
"errors": {
...
}
}
If you passed notification_endpoint_id, then you will receive a notification about the change in the payment status.
Example
Unpack the downloaded archive into the folder "path to script/cert/payment /"
function requestPayment(string $method, string $account, array $data)
{
$data = json_encode($data);
$privateKey = openssl_pkey_get_private(
file_get_contents(__DIR__ . '/cert/payment/private.pem'),
file_get_contents(__DIR__ . '/cert/payment/password.txt')
);
if ($privateKey===false) {
throw new \Exception('Error cert.');
}
openssl_sign($data, $sign, $privateKey);
$sign = base64_encode($sign);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api-merchant.alikassa.com/' . $method);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Account: ' . $account,
'Sign: ' . $sign,
]);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_USERAGENT, 'AliKassa2.0 API');
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$response = curl_exec($ch);
return json_decode($response, true);
}
$payment = requestPayment('v1/payment/status', '93d5df06-996c-48c3-9847-348d6b580b80', [
'id' => '100000536',
]);
var_dump($payment);