# Create payment via host2host (GATE)

This integration method lets you create a **SberPay** payment directly from your server. You receive two types of links: a regular web link and a **Deep Link** for instant navigation to the SberBank Online mobile app.

The main advantage is flexible control over the payment flow depending on the user's device (**App-to-App** or **Web-to-App**), which helps maximize conversion.

## How it works

1. **Request** — your server sends order data and the selected interaction type (`sberpay_type`) to the 1Payment endpoint.
2. **Receive links** — the response includes `redirect_url` and `deep_link`.
3. **Payment** — you redirect the customer. Using a Deep Link on smartphones opens the Sber app immediately for transaction confirmation.
4. **Notification (callback)** — we send a callback with the final status to your `notify_url`.


## Technical details

|  |  |
|  --- | --- |
| **Endpoint** | `https://api.1payment.com/init_payment` |
| **Methods** | `GET`, `POST` |
| **Response format** | JSON |
| **Payment type** | The request must include `payment_type=sberpay` |


## Request parameters

### Required

These fields are required to create the payment correctly.

| Parameter | Type | Description |
|  --- | --- | --- |
| `partner_id` | Integer | Your unique ID in the 1Payment system. |
| `payment_type` | String | Always `sberpay`. |
| `project_id` | Integer | Your project identifier. |
| `amount` | Number | Payment amount. Format: `100.00`. |
| `user_data` | String | Your internal order ID (returned in the callback). |
| `sberpay_type` | String | Interaction mode: `app2app` (from app), `web2app` (from browser), `mweb2app` (from mobile browser). |
| `sign` | String | Request signature (see the Signature section). |


### Optional

Pass extended customer information or configure return behavior.

| Parameter | Type | Description |
|  --- | --- | --- |
| `description` | String | Order description for the payer. |
| `deep_link` | String | Address to redirect to your app after payment. |
| `return_url` | String | URL to return the payer to after payment in the bank. |
| `phone` | String | Payer phone number. |
| `email` | String | Payer email address. |
| `user_id` | String | Internal payer ID in your system. |
| `subscribe` | Integer | Pass `1` to create a subscription. |
| `token` | String | Linked card token (for subscription payments). |


## Signature (`sign`)

The signature is an MD5 hash in lowercase. General rules — [API request format](/en/pages/init-request#%D0%BF%D0%BE%D0%B4%D0%BF%D0%B8%D1%81%D1%8C-%D0%B7%D0%B0%D0%BF%D1%80%D0%BE%D1%81%D0%B0-sign).

**Formula:**


```text
MD5(init_payment + <params_excluding_sign_in_alphabetical_order_joined_with_&> + <API_KEY>)
```

**Scenario 1 — required fields only**

Mock data: `amount=50`, `partner_id=1234`, `payment_type=sberpay`, `project_id=5678`, `sberpay_type=app2app`, `user_data=order_777`.


```text
init_paymentamount=50&partner_id=1234&payment_type=sberpay&project_id=5678&sberpay_type=app2app&user_data=order_777secret_key
```

### Verify signature in the documentation

## Request examples

Node.js

```javascript
const crypto = require('crypto');
const axios = require('axios');

async function createSberPayPayment(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;
  } catch (error) {
    console.error('Ошибка:', error.message);
  }
}

// Пример данных запроса
const mockApiKey = process.env.ONEPAYMENT_API_KEY;
const mockData = {
  partner_id: 1234,
  project_id: 5678,
  amount: '50.00',
  payment_type: 'sberpay',
  sberpay_type: 'app2app',
  user_data: 'order_777',
};

createSberPayPayment(mockApiKey, mockData).then(console.log);
```

Python

```python
import hashlib
import os
import requests

def create_sberpay_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,
    "project_id": 5678,
    "amount": "50.00",
    "payment_type": "sberpay",
    "sberpay_type": "app2app",
    "user_data": "order_777",
}

print(create_sberpay_payment(api_key, data))
```

PHP

```php
<?php

function createSberPayPayment(string $apiKey, array $params): string
{
    // 1. Сортировка параметров по алфавиту
    ksort($params, SORT_LOCALE_STRING);
    $tail = '';
    foreach ($params as $k => $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,
    'project_id' => 5678,
    'amount' => '50.00',
    'payment_type' => 'sberpay',
    'sberpay_type' => 'app2app',
    'user_data' => 'order_777',
];

echo createSberPayPayment($apiKey, $data);
```

cURL

```bash
# 1–2. Подпись: md5("init_payment" + amount=50&partner_id=1234&payment_type=sberpay&project_id=5678&sberpay_type=app2app&user_data=order_777 + 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.00&payment_type=sberpay&sberpay_type=app2app&user_data=order_777&sign=PASTE_MD5_HEX"
```

## API response

Successful response (`200`):


```json
{
  "order_id": "8p3brmb19gfg0sg8gcwhws8kgc748s87",
  "status": 2,
  "status_description": "PENDING",
  "redirect_url": "https://secure_link_to_sberpay",
  "deep_link": "sberpay://link_to_app"
}
```

| Field | Description |
|  --- | --- |
| `order_id` | Unique payment ID in the 1Payment system. |
| `status` | Numeric status code (`2` — pending). |
| `status_description` | Text status description (`PENDING`, etc.). |
| `redirect_url` | Web link for browser payment. |
| `deep_link` | Link for direct navigation to the Sber app. |


Request error (`400`):


```json
{
  "error_code": 2
}
```

## Status notifications (callbacks)

When the status changes, a **POST** notification in JSON format is sent to your `notify_url`.

| Parameter | Type | Req. | Description |
|  --- | --- | --- | --- |
| `payment_type` | String | Yes | Payment type (`sberpay`). |
| `order_id` | String | Yes | Payment identifier in the 1Payment system. |
| `project_id` | Integer | Yes | Your project ID. |
| `status` | Integer | Yes | `2` — pending, `3` — success, `4` — declined. |
| `status_description` | String | Yes | Status text: `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 | Final payment amount. |
| `user_price` | Number | Yes | Partner payout amount. |
| `currency` | String | Yes | ISO 4217 code. |
| `account` | String | Yes | Technical marker (`sberpay`). |
| `user_data` | String | Yes | Your order ID. |
| `sign` | String | Yes | Notification signature. |
| `status_code` | String | No | Error code on decline. |


**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 with `&` + `API_KEY` (**without** the `init_payment` prefix). See [API request format](/en/pages/init-request#%D0%BA%D0%BE%D0%BB%D0%B1%D0%B5%D0%BA%D0%B8-%D1%83%D0%B2%D0%B5%D0%B4%D0%BE%D0%BC%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F) for details.

## Related sections

- [Create payment via form](/en/pages/sberpay/init-form)
- [Payment statuses](/en/pages/sberpay/status)
- [Payment refunds](/en/pages/sberpay/refund)
- [Transaction statuses](/en/pages/transaction-statuses)
- [Error codes (API)](/en/pages/error-codes-api)
- [Error codes (declines)](/en/pages/decline-error-codes)