How to allow a user to change a subscription plan
How it works
- When choosing a new plan, a refund is made to the user’s balance for the unused period of the current subscription.
- Payment for the new subscription plan is made entirely from the user’s balance. If their balance is insufficient, an additional payment is made by any of the payment methods allowed in the project.
- When changing the plan, funds are debited immediately after payment is confirmed, even if the project is configured to change the plan from the next billing period.
If the currency of the new plan is different from the currency of the current plan, the purchase of the new plan will be done with a currency conversion.
- the user already has an active subscription with the plan that the current plan is changing to
- the subscription that the user wants to change is not in the Active status
- the subscription plan that the user wants to change is of the Lifetime plan type: such a subscription can only be canceled within the specified refund period
How to get it
- Open your project in Publisher Account.
- Click Subscriptions in the sidebar and go to the Settings section.
- In the Changing plan section, set the Ability to choose a different plan toggle to On.
- Plan changes are allowed from the next period by default. To allow changing the plan in the current period, select Now. If you select this option, the plan changes immediately after payment is confirmed.
- To allow plan changes more than once a day, set the toggle Ability to choose a different plan several times on the same day to On.
- When opening the payment interface, use:
- server-side Create token API call
- client-side API call for getting a link to open a payment UI if you use Xsolla Login in your project
Opening the payment UI via the server-side Create token API call
- Get a token to open the payment UI by passing the following to the method:
change_plan
value in thepurchase.subscription.operation
parameter.- ID of the new plan in the
purchase.subscription.plan_id
parameter. - Subscription-based product ID in the
purchase.subscription.product_id
parameter if you are using subscription-based products. To get it, contact your Customer Success Manager or email to csm@xsolla.com.
- Open the payment interface in one of the following ways:
Opening the payment UI on the subscription management page using the client-side API call
If Xsolla Login is configured in your project, you can use the client-side API call to get a link to open the payment interface. The link returned in the response allows you to open the payment UI on the subscription management page, where users can select an active subscription and change it.
To do this, on the client side of your application, implement receiving a link to the payment interface using an HTTP POST request: https://subscriptions.xsolla.com/api/user/v1/projects/{project_id}/subscriptions/manage
.
The request must contain an Authorization: Bearer <client_user_jwt>
header, where <client_user_jwt>
is user’s JSON Web Token (JWT) — a unique, Base64-encoded token encoded according to the Base64 standard. To get the token:
- Use the
Register new user andAuth by username and password API calls if your application uses login and password authorization. - Use the
Auth via social network API call if your application uses authorization through social networks.
projectId
path parameter. You can find this parameter in your Publisher Account next to the name of the project.
Specify country
as the query parameter — the two-letter designation of the user’s country according to the ISO 3166-1 alpha-2 standard. Affects the choice of locale and currency. If this parameter is not passed, the country is determined by the user’s IP address.Pass additional parameters for customization if needed.
Request body parameters:
Parameter | Type | Description |
---|---|---|
| string | Required. The external ID of the subscription plan. You can find it in the Publisher Account > Subscriptions > Subscription Plans section. |
| object | Custom project settings (object). |
| object | Interface settings (object). |
| string | Payment UI size. Can be:
|
| string | Payment UI theme. Can be default , default_dark or custom theme ID. |
| string | Device type. Can be desktop (default) or mobile . |
| object | Interface settings for the desktop version (object). |
| object | Header settings (object). |
| boolean | Whether to show a Close button in Pay Station desktop. The button closes Pay Station and redirects the user to the URL specified in the settings.return_url parameter. false by default. |
| boolean | Whether to show the header in the payment UI. |
| string | Header appearance. Can be compact (in which case the game name and user ID will not be shown in the header) or normal . |
| boolean | If true , the header shows your logo (first provide the image to your Customer Success Manager). |
| boolean | Whether to show the project name in the header. |
| string | How to show the header. Can be compact (hides project name and user ID) or normal (default). |
| string | A user can only pay using their saved payment methods. Can be saved_accounts . |
| boolean | Whether to hide the footer in the mobile version of the payment UI. |
| boolean | Whether to show a Close button in Pay Station mobile. The button closes Pay Station and redirects the user to the URL specified in the settings.return_url parameter. false by default. |
| string | Interface mode in Pay Station. Can be user_account only: The header contains only the account navigation menu, and the user cannot select a product or make a payment. This mode is only available on the desktop. |
| string | Preferred payment currency. Three-letter ISO 4217 currency code. |
| string | Transaction ID in the game. Has to be unique for each user payment. |
| integer | Payment method ID. You can get the list of payment method IDs in Publisher Account. |
| string | Page to redirect the user to after payment. Parameters user_id , foreigninvoice , invoice_id and status will be automatically added to the link. |
| object | Redirect policy settings (object). |
| string | A payment status that redirects the user to a return URL after making a payment. Can be none , successful , successful_or_canceled , or any . |
settings.redirect_policy.delay | integer | Delay (in seconds) after which a user is automatically redirected to the return URL. |
| string | A payment status that redirects the user to a return URL after making a payment. Can be none , successful , successful_or_canceled , or any . |
| string | Text on the button for manual redirection. |
- curl
curl -X 'POST' \
'https://subscriptions.xsolla.com/api/user/v1/projects/{project_id}/subscriptions/manage?country=RU ' \
-H 'accept: application/json' \
-H 'Authorization: Bearer client_user_jwt'
{
"settings": {
"ui": {
"size": "large",
"theme": "string",
"version": "desktop",
"desktop": {
"header": {
"is_visible": true,
"visible_logo": true,
"visible_name": true,
"type": "compact",
"close_button": true
}
},
"mobile": {
"mode": "saved_accounts",
"footer": {
"is_visible": true
},
"header": {
"close_button": true
}
},
"license_url": "string",
"mode": "user_account",
"user_account": {
"history": {
"enable": true,
"order": 1
},
"payment_accounts": {
"enable": true,
"order": 1
},
"info": {
"enable": true,
"order": 1
},
"subscriptions": {
"enable": true,
"order": 1
}
}
},
"currency": "str",
"locale": "st",
"external_id": "string",
"payment_method": 1,
"return_url": "string",
"redirect_policy": {
"redirect_conditions": "none",
"delay": 0,
"status_for_manual_redirection": "none",
"redirect_button_caption": "string"
}
}
}
Response example:
- javascript
{
"link_to_ps": "https://secure.xsolla.com/paystation2/?access_token=<access_token>"
}
Found a typo or other text error? Select the text and press Ctrl+Enter.