Portal Architecture

Learn about the Servicebot Subscription Management Portal architecture

Overview

We will prepare your app to be able to handle the following prerequisites:

Store data needed on user. This will depend on your needs whether you need to store anything, or data like subscription ID, tier name, or subscription status.

Create Stripe customer & subscription. If you do not wish to use the Subscription Management Portal for the creation of these, you can create them with Stripe APIs.

Create Post signup process. We will determine what needs to happen after a user signs up using the Subscription Management Portal for things like user data storage and redirects.

Architecture

Servicebot Subscription Management Portal Architecture

Store data needed on user

We recommend you store the Stripe subscription ID, the tier name, and the subscription status in your database for each user. Optionally, you can also store the Stripe customer ID or the entire subscription object as returned from Stripe. You can use this information to restrict access to features or the app all together. You can restrict initial access by checking if the subscription ID or status is set, then use status to determine if they are active, trialing, cancelled, and more. Tier can be used to restrict access to features or limit usage based on the tier the user is on.

If you are doing metric based billing, you will also want to store the subscription item ID for each metric you have available on your service & tier. The subscription item ID is used for updating the metric later.

Create Stripe customer & subscription

If you have a use-case not covered by the signup process of the subscription management portal, or have a process already in place, you can create the customer object and assign a subscription using Stripe libraries and API.

Learn more here

Create Post signup process

Populating the data you need in the first step is done by using the handleResponse function in the subscription portal front-end code. In order for the changes to be immediate, we use handleResponse as opposed to webhooks for subscription creation and resubscribe. If you process cancellations immediately instead of at the end of a billing period you will want to update your user with handleResponse as well.

Simply run the code for your user update or make an API call based on the event in handleResponse. The response for that event is the subscription object and from that you will be able to determine the subscription id, customer id, service & tier name from the metadata (Servicebot automatically adds the product metadata to subscriptions), and the subscription status.

handleResponse: async function({event, response}){
if(event === "create_subscription" || event === "resubscribe"){
console.log("Activating account!", response);
let activationResponse = await fetch("/activate", {
method: "POST",
credentials: "include",
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
subscription_id: response.id
})
}).then(response => response.json());
console.log("response from server - ", activationResponse);
}
}
}