# Host-to-host payment creation (GATE) **GATE** integration lets you create a payment directly from your server and receive a ready-made payment link in the **Faster Payments System (SBP)**. You control the UI entirely: render the link as a QR code on your site or use a Pay button that opens the customer's bank app. ## How it works The API payment flow consists of four steps: 1. **Initialization** — your server builds a request with order parameters and sends it to the 1Payment endpoint. 2. **Receiving the link** — the system returns a direct SBP payment link (`redirect_url`). 3. **Payment** — you render the link as a QR code on your site or use it for a Pay button in the mobile version; the customer opens the bank app and confirms payment. 4. **Notification (callback)** — after the operation status changes, we send a **POST** notification to your `notify_url` with the final transaction result. ## Technical details | | | | --- | --- | | **Endpoint** | `https://api.1payment.com/init_payment` | | **Methods** | `GET`, `POST` | | **Response format** | JSON | | **Payment type** | The request must include `payment_type=sbp` | ## Request parameters ### Required These fields must be present in every request to create a payment correctly. | Parameter | Type | Description | | --- | --- | --- | | `partner_id` | Integer | Your unique ID in the 1Payment system. | | `project_id` | Integer | Your project identifier. | | `amount` | Number | Payment amount (for example, `100.00`). | | `payment_type` | String | For SBP, always pass `sbp`. | | `user_data` | String | Your internal order ID (returned in the callback). | | `shop_url` | String | URL of the site where the purchase is made. | | `sign` | String | Request signature (see the "Signature" section). | ### Optional Pass extended customer information or enable a subscription. | Parameter | Type | Description | | --- | --- | --- | | `description` | String | Order description shown to the customer in the bank app. | | `phone` | String | Payer phone number. | | `email` | String | Payer email address. | | `user_id` | String | Customer ID in your database. | | `subscribe` | Integer | Pass `1` to create a token for recurring payments. | ## Signature generation (`sign`) Signature: MD5, lowercase (hex). General rules — [API request format](../init-request.md#request-signature-sign). **Formula:** ```text MD5(init_payment + <параметры_без_sign_в_алфавитном_порядке_через_&> + ) ``` **Scenario 1 — required parameters only** Parameters: `amount=50`, `partner_id=1`, `payment_type=sbp`, `project_id=5678`, `shop_url=test.com`, `user_data=order123`. ```text init_paymentamount=50&partner_id=1&payment_type=sbp&project_id=5678&shop_url=test.com&user_data=order123secret_key ``` **Scenario 2 — with `description`** When adding `description=Payment1`, the field is included in the string alphabetically: ```text init_paymentamount=50&description=Payment1&partner_id=1&payment_type=sbp&project_id=5678&shop_url=test.com&user_data=order123secret_key ``` ### Signature verification in the documentation {% signatureVerifier method="init_payment" preset="sbp_init_payment" /%} ## Request examples {% codeTabs %} {% tab label="Node.js" %} ```javascript const crypto = require('crypto'); const axios = require('axios'); async function createSbpPayment(apiKey, params) { // 1. Сортируем параметры по алфавиту const sortedKeys = Object.keys(params).sort(); const queryString = sortedKeys.map((key) => `${key}=${params[key]}`).join('&'); // 2. Формируем подпись с префиксом init_payment const baseString = `init_payment${queryString}${apiKey}`; params.sign = crypto.createHash('md5').update(baseString).digest('hex'); // 3. Отправляем POST-запрос try { const response = await axios.post('https://api.1payment.com/init_payment', params); return response.data; // order_id, status, redirect_url } catch (error) { console.error('Ошибка при создании платежа:', error.message); } } // Пример данных запроса const apiKey = process.env.ONEPAYMENT_API_KEY; const data = { partner_id: 1234, payment_type: 'sbp', project_id: 5678, amount: 50.0, user_data: 'inv_12345', shop_url: 'https://myshop.com', }; createSbpPayment(apiKey, data).then((result) => console.log('Ответ системы:', result)); ``` {% /tab %} {% tab label="Python" %} ```python import hashlib import os import requests def create_sbp_payment(api_key: str, params: dict) -> dict: # 1. Сортировка параметров по алфавиту sorted_keys = sorted(params.keys()) query_string = "&".join(f"{k}={params[k]}" for k in sorted_keys) # 2. Формирование подписи (префикс init_payment) base_string = f"init_payment{query_string}{api_key}" params["sign"] = hashlib.md5(base_string.encode("utf-8")).hexdigest() # 3. Запрос к API response = requests.post("https://api.1payment.com/init_payment", data=params) response.raise_for_status() return response.json() api_key = os.environ["ONEPAYMENT_API_KEY"] data = { "partner_id": 1234, "payment_type": "sbp", "project_id": 5678, "amount": 50.00, "user_data": "inv_12345", "shop_url": "https://myshop.com", } print(create_sbp_payment(api_key, data)) ``` {% /tab %} {% tab label="PHP" %} ```php $v) { if ($k === 'sign') { continue; } $tail .= "{$k}={$v}&"; } $tail = substr($tail, 0, -1); // 2. Формирование подписи (префикс init_payment) $params['sign'] = md5('init_payment' . $tail . $apiKey); // 3. Запрос к API $ch = curl_init('https://api.1payment.com/init_payment'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); return $response; } // Пример данных запроса (обязательные поля) $apiKey = getenv('ONEPAYMENT_API_KEY'); $data = [ 'partner_id' => 1234, 'payment_type' => 'sbp', 'project_id' => 5678, 'amount' => 50.00, 'user_data' => 'inv_12345', 'shop_url' => 'https://myshop.com', ]; echo createSbpPayment($apiKey, $data); ``` {% /tab %} {% tab label="cURL" %} ```bash # 1–2. Подпись: md5("init_payment" + amount=50&partner_id=1&payment_type=sbp&project_id=5678&shop_url=test.com&user_data=order123 + API_KEY) # 3. POST-запрос (можно также GET с теми же query-параметрами) curl -sS -X POST "https://api.1payment.com/init_payment" \ -d "partner_id=1234&project_id=5678&amount=50&payment_type=sbp&user_data=inv_12345&shop_url=https%3A%2F%2Fmyshop.com&sign=PASTE_MD5_HEX" ``` {% /tab %} {% /codeTabs %} ## API response Successful response (`200`): ```json { "order_id": "8p3brmb19gfg0sg8gcwhws8kgc748s87", "status": 2, "status_description": "PENDING", "redirect_url": "https://qr.nspk.ru/XXX" } ``` | Field | Description | | --- | --- | | `order_id` | Unique transaction ID in the 1Payment system. | | `status` | Numeric state code (`2` — awaiting payment). | | `status_description` | Text status description (`PENDING`, etc.). | | `redirect_url` | Direct SBP link: render a QR code or use it as the Pay button URL. | Request error (`400`): ```json { "error_code": 2 } ``` ## Status notifications (callbacks) After the operation status changes, our server sends a **POST** request in JSON format to your `notify_url`. | Parameter | Type | Req. | Description | | --- | --- | --- | --- | | `payment_type` | String | Yes | Payment type (`sbp`). | | `order_id` | String | Yes | Payment identifier in the 1Payment system. | | `project_id` | Integer | Yes | Your project ID. | | `status` | Integer | Yes | State: `2` (pending), `3` (success), `4` (failure). | | `status_description` | String | Yes | `PENDING`, `SUCCESS`, or `FAILURE`. | | `init_time` | String | Yes | Payment creation time. | | `status_time` | String | Yes | Time the final status was received. | | `merchant_price` | Number | Yes | Payment amount. | | `user_price` | Number | Yes | Partner payout. | | `currency` | String | Yes | Payment currency (ISO 4217). | | `account` | String | Yes | SBP account details (value `sbp`). | | `user_data` | String | Yes | Transaction ID passed at initiation. | | `sign` | String | Yes | Callback signature. | | `redirect_url` | String | No | QR code URL if not sent earlier. | | `status_code` | String | No | Error code on decline. | | `token` | String | No | Subscription identifier for recurring payments. | | `test` | Integer | No | `1` for test operations. | **Important:** your server must return **HTTP 200 OK**. Otherwise the system retries the callback **once per minute for 10 minutes**. **Callback signature verification:** MD5 of all parameters in alphabetical order joined by `&` + `API_KEY` (**without** the `init_payment` prefix). See [API request format](../init-request.md#callbacks-notifications). ## Related sections - [Form payment creation](./init-form.md) - [Payment status](./status.md) - [Payment refunds](./refund.md) - [Subscription payment creation (recurring)](./recurring.md) - [Transaction statuses](../transaction-statuses.md) - [Error codes (API)](../error-codes-api.md) - [Decline error codes](../decline-error-codes.md)