Managing user subscriptions
To implement subscription management in your application, follow this logic:
- Retrieve the list of the user’s subscriptions and display them in the application.
- Implement subscription management — open the subscriber account or manage specific subscriptions directly from your application.
For simplified implementation, refer to the sample.
Purchasing and managing subscriptions are only available to authenticated users. For information on using the SDK for user authentication, refer to the Authentication section.
The code samples use password authentication via user name and password (the XsollaAuth.SignIn method) with hardcoded credentials to simplify the subscription workflow demonstration. In a real application, you need to implement full authentication logic and current session validation using the XsollaAuth.AuthBySavedToken method.
Retrieve user subscriptions
To retrieve all active subscriptions for the current user, use the XsollaSubscriptions.GetSubscriptions method. The method will return subscriptions with the statuses active, non_renewing, and freeze linked to the current user’s account.
You can also request detailed information about each subscription using the XsollaSubscriptions.GetSubscriptionDetails method.
Use the returned data (the SubscriptionItem object) to display the subscription management UI in your application.
Key fields for configuring UI widgets:
plan_name— subscription name.status— current subscription state (new,active,canceled,non_renewing,freeze).date_next_charge— date and time of the next automatic charge.charge— recurring payment information. The object contains the price (amount) and currency (currency).
Subscription management
Open subscriber account
Xsolla provides a ready-made UI — the subscriber account — through which users can view information about their subscriptions and manage them. This is the simplest and recommended way to implement subscription management.
Key features:
- the subscription details view
- the subscription management — immediate cancellation, disabling of auto-renewal, or reactivation (depending on the project settings)
- the subscription plan change
- the payment method update
To display the subscriber account to the user, call the XsollaSubscriptions.GetUserAccountUrl method. Upon a successful request, a UserAccountLink object containing a link to the account UI will be passed to the callback function. To open the link in an external browser or built-in WebView, use the XsollaWebBrowser.Open method.
Specific subscription management
To open the management UI for a specific subscription from your application, use the XsollaSubscriptions.GetSubscriptionManagementUrl method. Upon a successful request, a PaymentLink object containing a link to the subscription management UI will be passed to the callback function. To open the link in an external browser or built-in WebView, use the XsollaWebBrowser.Open method.
Subscription cancelation
To implement subscription cancellation from your application’s UI, use the XsollaSubscriptions.CancelSubscription method. The method disables auto-renewal, and the subscription transitions to non_renewing status. This means no automatic charge will occur in the next billing period; the subscription remains active until the end of the paid period.
Subscription renewal
To implement navigation to the subscription renewal UI from your application, use the XsollaSubscriptions.GetSubscriptionRenewalUrl method. Upon a successful request, a PaymentLink object containing a link to the subscription renewal UI will be passed to the callback function. To open the link in an external browser or built-in WebView, use the XsollaWebBrowser.Open method.
Found a typo or other text error? Select the text and press Ctrl+Enter.