Subscriptions

Subscription payment widget

Protocol: JSON v3 · XML 2.9OpenAPI

Subscription sign-up on the partner page: SBP, Alfa Pay, SberPay, SDK and own buttons.

The widget lets a customer take out a subscription on the partner's page with SBP, Alfa Pay or SberPay — depending on the project settings and the subscription terms. T-Pay is temporarily disabled.

If the first period is paid at sign-up, the chosen method starts the first payment and saves a binding for later charges. If the first payment is deferred, only SBP is available: the customer confirms a binding without a charge, and the platform starts the first payment later on schedule. A free binding must be enabled and supported by the payment provider for the project.

How to embed

  1. Call CreateSubscription from your server: the project password and signature never reach the browser. The response contains AuthorizeUrl with the token inside — 32 hexadecimal characters.

  2. Load embed.js from the payment domain and call SbpWidget.mount() with that token. When you embed the widget, do not open AuthorizeUrl: it is a separate payment flow and conflicts with the widget on the same token.

  3. The page with the widget must be served over https, or the browser blocks the embed.

HTML · production (sandbox: subs-sandbox.digitalspb.com)
<div id="pay"></div><script src="https://subs.digitalspb.com/Cards/Sbp/embed.js"></script><script>  var widget = SbpWidget.mount('#pay', {    token: 'TOKEN_FROM_CREATE_SUBSCRIPTION', // 32 hex characters from AuthorizeUrl    methods: ['sbp', 'sberpay'],             // optional: narrow the set of methods    brand: { name: 'My service', logo: '/logo.png', primary: '#1756ef', background: '#ffffff' },    onSuccess: function () { location.href = '/thanks'; },    onFail: function () {},    onExpired: function () {},    onError: function (error) { console.error(error.message, error.code); }  });  // widget.destroy() — remove the widget from the page</script>

mount() inserts an iframe with the widget page; the partner page styles and scripts do not affect it. The token goes to the server in the Authorization: Bearer header, not in the address bar.

mount() options

OptionRequiredDescription
tokenYesToken from AuthorizeUrl of the CreateSubscription response
apiBaseNoPayment domain address; defaults to the origin embed.js was loaded from
methodsNoMethod filter: an array of codes or a comma-separated string. Codes: sbp, alfapay, sberpay. Defaults to the server set. Never enables methods the server forbids; the order stays server-side
webviewNotrue turns WebView mode on, false off; without it the widget detects the mode itself. In WebView mode bank payment opens by a button, without opening a new tab automatically
brandNoLook: name, logo, primary, background, textColor
pollNofalse turns status auto-check off; on by default
onSuccessNoThe initial step succeeded: the first payment, or a binding without a charge when payment is deferred. Does not replace server notifications
onFailNoThe initial step failed
onExpiredNoThe QR code lifetime expired
onErrorNoWidget load or runtime error. Receives an Error: the message is in error.message, some events carry error.code (not guaranteed)

The SDK has no lang option. The logo is accepted only with an http(s):// or data:image/ scheme; an invalid color is replaced with the default. Without textColor the text color follows the background; when you set your own, contrast is on you. The QR code keeps a white background, and branded method buttons are not recolored with brand.primary.

Payment methods and errors

CodeMethod
sbpSBP
alfapayAlfa Pay
sberpaySberPay

The set and order of methods are defined by the platform and depend on the subscription terms. With a single method there is no choice screen. methods narrows the set to its intersection with the server set; case and surrounding spaces do not matter; it never enables forbidden methods or the disabled T-Pay.

If the intersection is empty, the widget shows the server set and calls onError with code method_unavailable — a non-fatal event, the widget keeps working. Do not create a new subscription automatically on any error: the previous payment operation may have started and its result may not have arrived yet.

First charge and trial period

The moment of the first payment follows the subscription terms, BillingStartTimeUtc and the project settings. BillingStartTimeUtc is passed to CreateSubscription as yyyy-mm-dd hh:mm, UTC.

Subscription termsAvailable methodsInitial step
First period paid at sign-upEnabled SBP, Alfa Pay, SberPayFirst payment saving a binding for later charges
First payment deferredSBP onlyBinding without a charge; the platform starts the first payment later on schedule

A free trial is the time before the first scheduled payment; its minimum length may be limited by project settings. BillingStartTimeUtc alone does not guarantee that a free SBP binding is available to the project.

Reopening

Within its lifetime, reopening reuses the operation already started with the same method: the server returns the same QR code or link. For a paid first payment already started no new authorization is sent — for SBP, Alfa Pay and SberPay alike. A timeout or a missing link does not prove the payment did not go through.

Before creating a new subscription, check the result of the previous operation by server data and notifications. Do not call CreateSubscription automatically after an error or an expired timer: a page reload that creates a subscription again shows a new QR code, while paying by the old one confirms the previous subscription. Closing the widget cancels neither the subscription, the binding nor a started operation.

Ready-made button — renderButton()

SbpWidget.renderButton('#pay', { createInvoice, text, brand, ... }) draws a ready-made button: the createInvoice callback creates the subscription on your server and returns an object with a token field, then the button opens the widget. Shared options: apiBase, methods, webview, poll, onSuccess, onFail, onExpired, onError. It is not a button for a specific method: only methods limits the set. The result has reset() and destroy().

Shop's own buttons

Your own method buttons use a redirect route. The subscription is created on your server with CreateSubscription; the link carries the token from AuthorizeUrl.

HTML · production
<a href="https://subs.digitalspb.com/Cards/Sbp/pay?token=TOKEN&amp;method=sbp">Pay with SBP</a><a href="https://subs.digitalspb.com/Cards/Sbp/pay?token=TOKEN&amp;method=alfapay">Pay with Alfa Pay</a><a href="https://subs.digitalspb.com/Cards/Sbp/pay?token=TOKEN&amp;method=sberpay">Pay with SberPay</a>
ParameterRequiredDescription
tokenYes32 hexadecimal characters from AuthorizeUrl, without dashes
methodYessbp, alfapay or sberpay; the method must be available for this subscription

The route answers HTTP 302: sbp — to the SBP widget screen without method choice, alfapay and sberpay — to the bank payment page. Following the link starts the initial payment operation, so never open these links automatically, preload them or hit them as a check — only on an explicit customer action. The method list comes from GET /Cards/Sbp/methods with Authorization: Bearer TOKEN; it creates no payment.

Once the operation has started, the method cannot change on the same token. An invalid token or unavailable method gives HTTP 400, a payment provider error HTTP 500; the route returns an HTML page, not JSON. Going to the bank creates no SDK instance and no onSuccess/onFail callbacks: check the result by server notifications and subscription state. The token in the URL is sensitive; build links with encodeURIComponent.

Endpoints

MethodPathPurpose
GET/Cards/Sbp/embed.jsEmbed SDK
GET/Cards/Sbp/widget.htmlIframe content
POST/Cards/Sbp/createInitial step: QR or link
GET/Cards/Sbp/statusPoll status
GET/Cards/Sbp/methodsAvailable methods, creates no payment
GET/Cards/Sbp/payRedirect route for own buttons