The subscription widget is a javascript widget that can be embedded in a merchant's website to allow customers to subscribe to the merchant's plans.
To insert the widget in a page, the following code should be added to the page:
<div id="sbpay-widget"></div> <script src="https://app.sbpay.me//widgets/subscriptions-widget-plans.js"></script> <script> let widget = new SbPayWidget('sbpay-widget', { merchant: '{merchant_id}', project: '{project_id}', customerJwtToken: '{jwt_token}' }); </script>
The widget will be rendered in the div with id 'sbpay-widget'.
The merchant, project and customerJwtToken parameters are mandatory.
The widget will be rendered in the language of the browser, if the language is supported. Otherwise, the widget will be rendered in default language selected for project.
You can specify the language of the widget by passing the 'language' parameter to the widget constructor.
The widget will be rendered in the currency detected by SBPay. You can specify the currency of the widget by passing the 'currency' parameter to the widget constructor.
The customerJwtToken
parameter is a JWT token that identifies the customer.
The token is generated by the merchant's server and should contain the following claims:
sub
: the customer's idexp
: the expiration date of the tokenallow_change_subscription
: allow customer to change subscriptionallow_cancel_recurring_profile
: allow customer to cancel recurring profile
The token should be signed with the merchant's private key.
For more information about JWT, see https://jwt.io/.
The following parameters can be passed to the widget constructor:
merchant
- Merchant ID
The merchant ID. Parameter is mandatory.
project
- Project ID
The project ID. Parameter is mandatory. You can find it in the SBPay project settings.
customerJwtToken
- Customer JWT Token
The customer JWT token. Parameter is mandatory. Please see the customer authentication section for more information.
language
- Language
The language of the widget. Parameter is optional. If not specified, the widget will be rendered in the language of the browser, if the language is supported. Otherwise, the widget will be rendered in default language selected for project.
currency
- Currency
The currency of the widget. Parameter is optional. If not specified, the widget will be rendered in the currency detected by SBPay.
onContactButtonClick
- On Contact Button Click event
On Contact Button Click event handler. Parameter is optional. The handler is called when the customer clicks the contact button.
onValidatePlan
- On Validate Plan event
On Validate Plan event handler. Parameter is optional. Can be used to validate the plan before the customer select it. Throw an exception to prevent the customer from selecting the plan.
SBPay provides an API to interact with customer's subscriptions.
Please see the API documentation for more information.