H2H payments
- 1. Create payment, get uuid
- 2. Send details to https://api-h2h.alikassa.com/v1/payment
- 3. Redirect client to 3ds
- 4. After payment, the payer will return to your specified page return_url
- 5. Send confirm request, confirm payment
URL | POST https://api-merchant.alikassa.com/v1/payment |
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 |
Application | Issued Application UUID |
1. Create payment, get uuid
Create payment using API
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);
}
requestPayment('v1/payment', '93d5df06-996c-48c3-9847-348d6b580b80', [
'order_id' => (string)time(),
'amount' => 500,
'customer_browser_user_agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0',
'customer_ip' => '18.191.80.10',
'success_redirect_id' => 1,
'fail_redirect_id' => 1,
'notification_endpoint_id' => 5,
'service' => 'payment_card_rub_hpp',
'customer_browser_accept_header' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'customer_browser_color_depth' => '32',
'customer_browser_language' => 'ru',
'customer_browser_screen_height' => 1080,
'customer_browser_screen_width' => 1920,
'customer_browser_window_width' => 900,
'customer_browser_window_height' => 640,
'customer_browser_time_different' => -180,
'customer_browser_java_enabled' => 1,
'customer_browser_user_agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0',
]);
2. Send details to https://api-h2h.alikassa.com/v1/payment
* - Required fieldsName | Type | Description | Example |
card_first_name* | string | Card first name | Ivan |
card_last_name* | string | Card last name | Ivanov |
card_number* | int | Card number | 4242 4242 4242 4242 |
card_year* | int (2) | End date, year, last 2 digits | 29 |
card_month* | int (2) | End date, month | 08 |
card_cvc* | int (3) | CVC cards | 077 |
payment_uuid* | int | AliKassa Uuid | |
return_url* | string | Return URL (In the link, specify the uuid of the payment) |
|
browser_user_agent* | string | Browser user agent | Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0 |
browser_accept_header* | string | Browser accept header | text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 |
browser_language* | string | Browser language | ru |
browser_color_depth* | int | (Color depth) - the number of bits that fit into one pixel | screen.colorDepth |
browser_screen_height* | int | Browser screen height | screen.height |
browser_screen_width* | int | Browser screen width | screen.width |
browser_window_width* | int | Browser window width | window.innerWidth |
browser_window_height* | int | Browser window height | window.innerHeight |
browser_time_different* | int | Time difference in browser | (new Date()).getTimezoneOffset() |
browser_java_enabled* | int | Is java enabled in browser | 1 |
browser_ip* | ip | Payer's IP | REMOTE_ADDR |
Response
Name | Description |
success | true — successfully completed false — runtime error |
redirect | Object of the payer's order for payment url — ссылка method — get | post params — parameters for get or post |
Test Cards
4242 4242 4242 4242 — successful payment5555 5555 5555 4444 — payment error
Validity period - any unexpired,
arbitrary CVV code.
Example of a successful HTTP CODE 200 response:
{
"success": true,
"redirect": {
"url":"https://payment.com/3ds",
"method":"get",
"params":[
]
}
An example of an unsuccessful HTTP CODE 400 response:
{
"success": false,
"error": "...",
"errorCode": "..."
}
3. Redirect client to 3ds
After receiving the url, redirect the payer.
Example:
function requestH2H(string $method, string $account, array $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((string)$data['payment_uuid'], $sign, $privateKey);
$sign = base64_encode($sign);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api-h2h.alikassa.com/' . $method);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Account: ' . $account,
'Sign: ' . $sign,
'Application: {APPLICATION_UUID}',
]);
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);
return json_decode(curl_exec($ch), true);
}
$payment = requestH2H('v1/payment', '93d5df06-996c-48c3-9847-348d6b580b80', [
'payment_uuid' => 'a0c0809e-9121-0c08-8fba-ef0227083121',
'return_url' => 'http://site.ru/confirm',
'card_number' => '506900010009002',
'card_year' => '20',
'card_month' => '07',
'card_cvc' => '704',
]);
You only need to sign payment_uuid.
4. After payment, the payer will return to your specified page return_url
After payment, the payer will return to your specified page return_url.
5. Send confirm request, confirm payment
After payment, the payer will return to the return_url page, before checking the status of the payment, send us a confirmation
Send all the POST data you received and also the uuid of the payment.
* - Required fieldsName | Type | Description |
payment_uuid* | string | AliKassa Uuid |
data | array | POST data |
Response
Name | Description |
success | true — successfully completed false — runtime error |
Example:
requestH2H('v1/payment/confirm', '93d5df06-996c-48c3-9847-348d6b580b80', [
'payment_uuid' => $_GET['uuid'],
'data' => $_POST,
]);