Subscription purchase
To implement subscription purchasing in your application, follow this logic:
- Retrieve the list of subscription plans available for purchase and display them to the user.
- Initiate the purchase of the plan selected by the user.
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 list of subscription plans
To retrieve the list of plans configured in Publisher Account, call the XsollaSubscriptions.GetSubscriptionPublicPlans or XsollaSubscriptions.GetSubscriptionPlans method. Use the returned data (the PlanItem object) to display the subscription catalog in your application.
Key fields for configuring UI widgets:
plan_name— subscription name.plan_description— description of the plan’s benefits.charge— object containing the price (amount) and currency (currency).period— billing period.
Initiate subscription purchase
To initiate the purchase of a subscription plan selected by the user, call the XsollaSubscriptions.GetSubscriptionPurchaseUrl method, passing the planExternalId parameter. 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.
To track the order status, you need to configure webhook handling and receive order information on the server side of your application. This will allow you to implement additional validation of completed purchases.
Refer to the Get subscription information section for detailed information on configuring and testing webhooks.
Found a typo or other text error? Select the text and press Ctrl+Enter.