Subscription payment widget
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
Call
CreateSubscriptionfrom your server: the project password and signature never reach the browser. The response containsAuthorizeUrlwith the token inside — 32 hexadecimal characters.Load
embed.jsfrom the payment domain and callSbpWidget.mount()with that token. When you embed the widget, do not openAuthorizeUrl: it is a separate payment flow and conflicts with the widget on the same token.The page with the widget must be served over
https, or the browser blocks the embed.
<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
| Option | Required | Description |
|---|---|---|
token | Yes | Token from AuthorizeUrl of the CreateSubscription response |
apiBase | No | Payment domain address; defaults to the origin embed.js was loaded from |
methods | No | Method 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 |
webview | No | true 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 |
brand | No | Look: name, logo, primary, background, textColor |
poll | No | false turns status auto-check off; on by default |
onSuccess | No | The initial step succeeded: the first payment, or a binding without a charge when payment is deferred. Does not replace server notifications |
onFail | No | The initial step failed |
onExpired | No | The QR code lifetime expired |
onError | No | Widget 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
| Code | Method |
|---|---|
sbp | SBP |
alfapay | Alfa Pay |
sberpay | SberPay |
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 terms | Available methods | Initial step |
|---|---|---|
| First period paid at sign-up | Enabled SBP, Alfa Pay, SberPay | First payment saving a binding for later charges |
| First payment deferred | SBP only | Binding 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.
<a href="https://subs.digitalspb.com/Cards/Sbp/pay?token=TOKEN&method=sbp">Pay with SBP</a><a href="https://subs.digitalspb.com/Cards/Sbp/pay?token=TOKEN&method=alfapay">Pay with Alfa Pay</a><a href="https://subs.digitalspb.com/Cards/Sbp/pay?token=TOKEN&method=sberpay">Pay with SberPay</a>| Parameter | Required | Description |
|---|---|---|
token | Yes | 32 hexadecimal characters from AuthorizeUrl, without dashes |
method | Yes | sbp, 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
| Method | Path | Purpose |
|---|---|---|
| GET | /Cards/Sbp/embed.js | Embed SDK |
| GET | /Cards/Sbp/widget.html | Iframe content |
| POST | /Cards/Sbp/create | Initial step: QR or link |
| GET | /Cards/Sbp/status | Poll status |
| GET | /Cards/Sbp/methods | Available methods, creates no payment |
| GET | /Cards/Sbp/pay | Redirect route for own buttons |