Overview
The JavaScript SDK allows you access customer data from Stigg, and leverage it to implement mind-blowing customer experiences.Stigg also offers plug-and-play customizable widgets for React, Vue.js, Webflow, Wordpress, and plain HTML.
Installing the SDK
The first step is to install the Stigg SDK as a dependency in your application using your application’s dependency manager:Retrieving the client API key
In the Stigg app, go to Settings > Account > Environments. Copy the Client API key of the relevant environment.Initializing the SDK
Initializing client instance with client api key. You can either pass the customer id when initializing the client instance or usingsetCustomerId
function as shown below.
waitForInitialization
which return a promise that resolves when the client is ready to use, or rejects when the initialization failed.
Setting the customer context
Set the customer ID of the user that’s accessing your app, usually after the customer signs in or restores a session:Setting the customer resource context
For Multi-instance products, set the customer resource ID of the user that’s accessing your app, usually after the customer enters into a resource context:Getting all of the entitlements of a specific customer
Getting the entitlement of a customer to a specific feature
Checking the entitlement for a boolean feature
Checking the entitlement for a numeric configuration feature
Checking if a customer has access to a metered feature
Proactively checking if a customer will have access to X units of a metered feature
Getting paywall data
Useful for rendering the public pricing page or customer paywall.Getting customer portal data
Useful for rendering the public pricing page or customer paywall.Getting customer data
Useful for rendering a customer portal.Listing customers active subscriptions
ThegetActiveSubscriptionsList
method returns a list of slim subscription data, for extended data for a specific subscription use getSubscription
method.
Getting a subscription
Useful for rendering a customer portal. To retrieve extended subscription:Getting all available coupons
Useful for rendering a paywall or promotions.Estimate subscription cost
You can estimate the subscription cost using theestimateSubscription
method. This can help the customer to understand the costs before paying.
updateSubscription
method, which also returns a breakdown of the proration amounts:
- Passing of promo codes requires an integration with a billing solution, such as: Stripe.
- Promo codes should be generated in the integrated billing solution.
- When providing the optional
promotionCode
parameter, the promo code and associated coupon will validated against the defined restrictions to ensure that they’re applicable for the subscription. If validation fails, a relevant error code would be returned; otherwise, the subscription will include the discounted price.
Handling a successful checkout
When initiating checkout using Stigg, the user is expected to be redirected and land on thesuccessUrl
destination page in the case of a successful payment.
Due to the async nature of webhooks from Stripe, the subscription might not be yet provisioned in your Stigg account. To make sure that the new subscription has been activated in this scenario, you can utilize the waitForCheckoutCompleted
method to have an indication if the checkout is still in progress or not. Once the promise resolves, the subscription has been successfully activated and new entitlements were granted. If there’s a timeout or a network error during that time, the promise is rejected with the error.
For example, you can present a loading animation until the promise returned from the method is resolved.