{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["signatureVerifier","codeTabs","tab"]},"type":"markdown"},"seo":{"title":"Создание платежа по подписке (рекурренты)","description":"Документация API 1Payment — приём платежей и выплаты.","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"создание-платежа-по-подписке-рекурренты","__idx":0},"children":["Создание платежа по подписке (рекурренты)"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Рекуррентные платежи через СБП позволяют автоматически списывать средства со счёта клиента в банковском приложении без его повторного участия. Идентификация счёта выполняется по ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["токену"]},", который выдаётся при первичной привязке."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Для активации функционала в проекте обратитесь к сопровождающему менеджеру 1Payment."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"принцип-работы","__idx":1},"children":["Принцип работы"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Процесс работы с подписками СБП состоит из четырёх этапов:"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Привязка счёта (первый запрос)"]}," — вы проводите успешный платёж с суммой ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["больше ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["0"]}]}," и параметром ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["subscribe=1"]}," через ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/pages/sbp/init-form"},"children":["форму оплаты"]}," или ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/pages/sbp/host2host"},"children":["GATE"]},". Плательщик подтверждает привязку в приложении банка."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Получение токена"]}," — после подтверждения банком 1Payment отправляет колбек с уникальным ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["token"]},". Сохраните его для последующих списаний."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Автосписание (рекуррент)"]}," — для повторных оплат ваш сервер вызывает GATE (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["init_payment"]},"), передавая сохранённый ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["token"]},". Списание проходит без участия плательщика."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Уведомление"]}," — после каждой попытки списания приходит колбек с финальным результатом транзакции."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"техническая-информация","__idx":2},"children":["Техническая информация"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Этап"},"children":["Этап"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Эндпоинт"},"children":["Эндпоинт"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Методы"},"children":["Методы"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Регистрация подписки (форма)"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://api.1payment.com/init_form"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["GET"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Регистрация подписки (GATE)"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://api.1payment.com/init_payment"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["GET"]},", ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Рекуррентное списание (GATE)"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://api.1payment.com/init_payment"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST"]}," (рекомендуется), ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["GET"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Формат ответа: ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["JSON"]},". Для СБП в запросах указывайте ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["payment_type=sbp"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"1-регистрация-подписки-первый-запрос","__idx":3},"children":["1. Регистрация подписки (первый запрос)"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Для регистрации подписки проведите ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["успешный платёж"]}," с суммой ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["больше ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["0"]}]}," и параметром ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["subscribe=1"]},". Подробнее о параметрах формы и GATE — в разделах ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/pages/sbp/init-form"},"children":["Создание платежа по форме"]}," и ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/pages/sbp/host2host"},"children":["Создание платежа по host2host (GATE)"]},". Ниже — обязательный набор для привязки."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"обязательные-параметры-инициация","__idx":4},"children":["Обязательные параметры (инициация)"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Параметр"},"children":["Параметр"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Тип"},"children":["Тип"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Описание"},"children":["Описание"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["partner_id"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Integer"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Ваш уникальный ID в системе 1Payment."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["project_id"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Integer"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Идентификатор вашего проекта."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["amount"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Number"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Сумма платежа при привязке — больше ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["0"]}," (например, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["50.00"]},")."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["subscribe"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Integer"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Флаг создания подписки. Всегда ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["1"]},"."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["payment_type"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Для СБП всегда ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sbp"]},"."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["user_data"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Ваш уникальный ID заказа для сопоставления."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["shop_url"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["URL сайта, на котором совершается покупка."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sign"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Контрольная подпись (см. ниже)."]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"дополнительные-параметры-инициация","__idx":5},"children":["Дополнительные параметры (инициация)"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Параметр"},"children":["Параметр"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Тип"},"children":["Тип"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Описание"},"children":["Описание"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["description"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Описание подписки для клиента."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["success_url"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["URL возврата клиента при успехе."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["failure_url"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["URL возврата клиента при ошибке."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["user_id"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["ID плательщика в вашей системе."]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Подпись при регистрации через форму"]}," — префикс ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["init_form"]},". ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Через GATE"]}," — префикс ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["init_payment"]},"."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"text","header":{"controls":{"copy":{}}},"source":"MD5(init_form + <параметры_без_sign_в_алфавитном_порядке_через_&> + <API_KEY>)\n","lang":"text"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"text","header":{"controls":{"copy":{}}},"source":"MD5(init_payment + <параметры_без_sign_в_алфавитном_порядке_через_&> + <API_KEY>)\n","lang":"text"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"2-рекуррентное-списание-повторные-платежи","__idx":6},"children":["2. Рекуррентное списание (повторные платежи)"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Для автоматического списания отправьте запрос на GATE с сохранённым ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["token"]},". При активной подписке участие клиента не требуется."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"обязательные-параметры-рекуррент","__idx":7},"children":["Обязательные параметры (рекуррент)"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Параметр"},"children":["Параметр"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Тип"},"children":["Тип"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Описание"},"children":["Описание"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["partner_id"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Integer"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Ваш уникальный ID в системе 1Payment."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["payment_type"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Всегда ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sbp"]},"."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["project_id"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Integer"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Идентификатор вашего проекта."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["amount"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Number"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Сумма очередного списания (например, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["50.00"]},")."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["token"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Токен, полученный при регистрации подписки (из колбека)."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["user_data"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Новый уникальный ID транзакции."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["shop_url"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["URL сайта источника платежа."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sign"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Контрольная подпись (префикс ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["init_payment"]},")."]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"формирование-подписи--sign-","__idx":8},"children":["Формирование подписи (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sign"]},")"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"text","header":{"controls":{"copy":{}}},"source":"MD5(init_payment + <параметры_без_sign_в_алфавитном_порядке_через_&> + <API_KEY>)\n","lang":"text"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"проверка-подписи-рекуррентное-списание","__idx":9},"children":["Проверка подписи (рекуррентное списание)"]},{"$$mdtype":"Tag","name":"SignatureVerifier","attributes":{"method":"init_payment","preset":"sbp_recurring_payment"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"примеры-запроса","__idx":10},"children":["Примеры запроса"]},{"$$mdtype":"Tag","name":"CodeTabs","attributes":{},"children":[{"$$mdtype":"Tag","name":"Tab","attributes":{"label":"Node.js"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"const crypto = require('crypto');\nconst axios = require('axios');\n\n// 1. Инициация подписки (первичная привязка)\nasync function setupSbpSubscription(apiKey, params) {\n  const sortedKeys = Object.keys(params).sort();\n  const queryString = sortedKeys.map((k) => `${k}=${params[k]}`).join('&');\n\n  const baseString = `init_form${queryString}${apiKey}`;\n  params.sign = crypto.createHash('md5').update(baseString).digest('hex');\n\n  const response = await axios.post('https://api.1payment.com/init_form', params);\n  return response.data; // ссылка для подтверждения в приложении банка\n}\n\n// 2. Рекуррентное списание (по токену)\nasync function chargeSbpByToken(apiKey, params) {\n  const sortedKeys = Object.keys(params).sort();\n  const queryString = sortedKeys.map((k) => `${k}=${params[k]}`).join('&');\n\n  const baseString = `init_payment${queryString}${apiKey}`;\n  params.sign = crypto.createHash('md5').update(baseString).digest('hex');\n\n  const response = await axios.post('https://api.1payment.com/init_payment', params);\n  return response.data;\n}\n\nconst secretKey = process.env.ONEPAYMENT_API_KEY;\n\n// Пример: привязка\nconst setupData = {\n  partner_id: 1234,\n  project_id: 5678,\n  amount: '50.00',\n  subscribe: 1,\n  payment_type: 'sbp',\n  user_data: 'sbp_setup_777',\n  shop_url: 'http://myshop.ru',\n};\n// setupSbpSubscription(secretKey, setupData).then(console.log);\n\n// Пример: списание\nconst recurringData = {\n  partner_id: 1234,\n  payment_type: 'sbp',\n  project_id: 5678,\n  token: 'sbp_t_1a2b3c',\n  amount: '500.00',\n  user_data: 'sbp_order_888',\n  shop_url: 'http://myshop.ru',\n};\nchargeSbpByToken(secretKey, recurringData).then(console.log);\n","lang":"javascript"},"children":[]}]},{"$$mdtype":"Tag","name":"Tab","attributes":{"label":"Python"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"import hashlib\nimport os\nimport requests\n\ndef charge_sbp_by_token(api_key: str, params: dict) -> dict:\n    # 1. Сортировка параметров\n    sorted_keys = sorted(params.keys())\n    query_string = \"&\".join(f\"{k}={params[k]}\" for k in sorted_keys)\n\n    # 2. Подпись init_payment\n    base_string = f\"init_payment{query_string}{api_key}\"\n    params[\"sign\"] = hashlib.md5(base_string.encode(\"utf-8\")).hexdigest()\n\n    # 3. POST-запрос (рекуррент)\n    response = requests.post(\"https://api.1payment.com/init_payment\", data=params)\n    response.raise_for_status()\n    return response.json()\n\napi_key = os.environ[\"ONEPAYMENT_API_KEY\"]\ndata = {\n    \"partner_id\": 1234,\n    \"payment_type\": \"sbp\",\n    \"project_id\": 5678,\n    \"token\": \"sbp_t_1a2b3c\",\n    \"amount\": \"500.00\",\n    \"user_data\": \"sbp_order_888\",\n    \"shop_url\": \"http://myshop.ru\",\n}\nprint(charge_sbp_by_token(api_key, data))\n","lang":"python"},"children":[]}]},{"$$mdtype":"Tag","name":"Tab","attributes":{"label":"PHP"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"php","header":{"controls":{"copy":{}}},"source":"<?php\n\nfunction chargeSbpByToken(string $apiKey, array $params): string\n{\n    // 1. Сортировка параметров по алфавиту\n    ksort($params, SORT_LOCALE_STRING);\n    $tail = '';\n    foreach ($params as $k => $v) {\n        if ($k === 'sign') {\n            continue;\n        }\n        $tail .= \"{$k}={$v}&\";\n    }\n    $tail = substr($tail, 0, -1);\n\n    // 2. Формирование подписи (префикс init_payment)\n    $params['sign'] = md5('init_payment' . $tail . $apiKey);\n\n    // 3. Запрос к API\n    $ch = curl_init('https://api.1payment.com/init_payment');\n    curl_setopt($ch, CURLOPT_POST, true);\n    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));\n    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n    $response = curl_exec($ch);\n    curl_close($ch);\n\n    return $response;\n}\n\n// Пример данных запроса\n$apiKey = getenv('ONEPAYMENT_API_KEY');\n$data = [\n    'partner_id' => 1234,\n    'payment_type' => 'sbp',\n    'project_id' => 5678,\n    'token' => 'sbp_t_1a2b3c',\n    'amount' => '500.00',\n    'user_data' => 'sbp_order_888',\n    'shop_url' => 'http://myshop.ru',\n];\n\necho chargeSbpByToken($apiKey, $data);\n","lang":"php"},"children":[]}]},{"$$mdtype":"Tag","name":"Tab","attributes":{"label":"cURL"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"# Рекуррент: sign = md5(\"init_payment\" + amount=500.00&partner_id=1234&payment_type=sbp&project_id=5678&shop_url=...&token=...&user_data=... + API_KEY)\ncurl -sS -X POST \"https://api.1payment.com/init_payment\" \\\n  -d \"partner_id=1234&payment_type=sbp&project_id=5678&token=sbp_t_1a2b3c&amount=500.00&user_data=sbp_order_888&shop_url=http%3A%2F%2Fmyshop.ru&sign=PASTE_MD5_HEX\"\n","lang":"bash"},"children":[]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"ответ-api","__idx":11},"children":["Ответ API"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["При успешном ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["рекуррентном"]}," запросе (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["200"]},"):"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n  \"order_id\": \"8p3brmb19gfg0sg8gcwhws8kgc748s87\",\n  \"status\": 2,\n  \"status_description\": \"PENDING\"\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["При ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["регистрации через форму"]}," в ответе будет поле ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["url"]}," (см. ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/pages/sbp/init-form"},"children":["Создание платежа по форме"]},"); через GATE — ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["redirect_url"]}," (см. ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/pages/sbp/host2host"},"children":["Создание платежа по host2host (GATE)"]},")."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Ошибка запроса (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["400"]},"):"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n  \"error_code\": 2\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"уведомления-о-статусе-колбеки","__idx":12},"children":["Уведомления о статусе (колбеки)"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["При успешной привязке или списании система отправляет ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["POST"]},"-запрос в формате JSON на ваш ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["notify_url"]},"."]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Параметр"},"children":["Параметр"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Тип"},"children":["Тип"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Обяз."},"children":["Обяз."]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Описание"},"children":["Описание"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["payment_type"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Да"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Тип платежа (",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sbp"]},")."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["order_id"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Да"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["ID платежа в системе 1Payment."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["project_id"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Integer"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Да"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["ID вашего проекта."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["status"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Integer"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Да"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Состояние: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["3"]}," (успех), ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["4"]}," (отказ)."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["status_description"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Да"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["SUCCESS"]}," или ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["FAILURE"]},"."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["init_time"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Да"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Время создания платежа."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["status_time"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Да"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Время получения финального статуса."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["merchant_price"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Number"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Да"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Сумма для плательщика."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["init_price"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Number"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Да"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Сумма при инициации."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["user_price"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Number"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Да"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Сумма к начислению партнёру."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["currency"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Да"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Валюта (ISO 4217)."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["account"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Да"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Для СБП — ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sbp"]},"."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["user_data"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Да"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Ваш ID транзакции, переданный при создании."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["sign"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Да"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Контрольная подпись колбека."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["token"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Нет"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Токен для последующих списаний — ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["сохраните"]}," при привязке."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["test"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Integer"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Нет"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["1"]}," для тестовых транзакций."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["status_code"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["String"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Нет"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Код причины отказа."]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Важно:"]}," ваш сервер должен вернуть ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["HTTP 200 OK"]},". Иначе система повторяет отправку колбека ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["раз в минуту в течение 10 минут"]},"."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Проверка подписи колбека:"]}," MD5 от параметров в алфавитном порядке через ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["&"]}," + ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["API_KEY"]}," (",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["без"]}," префикса ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["init_payment"]},"). Подробнее — в разделе ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/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"},"children":["Формат запроса к API"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"связанные-разделы","__idx":13},"children":["Связанные разделы"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/pages/sbp/init-form"},"children":["Создание платежа по форме"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/pages/sbp/host2host"},"children":["Создание платежа по host2host (GATE)"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/pages/sbp/status"},"children":["Статусы платежей"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/pages/sbp/refund"},"children":["Возвраты платежей"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/pages/transaction-statuses"},"children":["Статусы транзакций"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/pages/error-codes-api"},"children":["Коды ошибок (API)"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/pages/decline-error-codes"},"children":["Коды ошибок (отказы)"]}]}]}]},"headings":[{"value":"Создание платежа по подписке (рекурренты)","id":"создание-платежа-по-подписке-рекурренты","depth":1},{"value":"Принцип работы","id":"принцип-работы","depth":2},{"value":"Техническая информация","id":"техническая-информация","depth":2},{"value":"1. Регистрация подписки (первый запрос)","id":"1-регистрация-подписки-первый-запрос","depth":2},{"value":"Обязательные параметры (инициация)","id":"обязательные-параметры-инициация","depth":3},{"value":"Дополнительные параметры (инициация)","id":"дополнительные-параметры-инициация","depth":3},{"value":"2. Рекуррентное списание (повторные платежи)","id":"2-рекуррентное-списание-повторные-платежи","depth":2},{"value":"Обязательные параметры (рекуррент)","id":"обязательные-параметры-рекуррент","depth":3},{"value":"Формирование подписи ( sign )","id":"формирование-подписи--sign-","depth":3},{"value":"Проверка подписи (рекуррентное списание)","id":"проверка-подписи-рекуррентное-списание","depth":3},{"value":"Примеры запроса","id":"примеры-запроса","depth":2},{"value":"Ответ API","id":"ответ-api","depth":2},{"value":"Уведомления о статусе (колбеки)","id":"уведомления-о-статусе-колбеки","depth":2},{"value":"Связанные разделы","id":"связанные-разделы","depth":2}],"frontmatter":{"seo":{"title":"Создание платежа по подписке (рекурренты)"}},"lastModified":"2026-06-08T15:08:00.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/pages/sbp/recurring","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}