Chargebee provides the feature
resource to help you define various features offered as part of your product line. This tutorial explains how you can check if a user of your system is entitled to a feature and then provide them access to it. This is achieved by retrieving and checking the subscription_entitlement
object. The subscription_entitlement
object specifies the entitlement a specific subscription has towards a specific feature.
If you'd like to request more of such guides to solve other use cases with the Entitlements API, contact us at [email protected]
Start by ensuring that the following objects have been created in Chargebee:
feature
objects to model the features you offer your users.item_entitlements
towards those features.Tip
It is recommended that you cache the subscription_entitlement
resource in your system to speed up the process of checking entitlements.
Perform the following steps each time the user logs in and a session is created:
Based on your use case, the user in the diagram below could be a human being or even a device such as in IoT .
The following steps explain the sequence shown in the above diagram:
subscription.id
.subscription.id
of the user.subscription_entitlements
.subscription_entitlements
object from its cache.subscription_entitlements
from Chargebee and store it in the cache.curl https://{site}.chargebee.com/api/v2/subscriptions/{subscription_id}/subscription_entitlements \
-G \
-u {site_api_key}:
{
"list": [{
"subscription_entitlement": {
"id": "KyVnHhSBWlm1j2m7",
"subscription_id": "JzDnHhSBWlm1j1n4",
"feature_id": "salesforce-integration",
"feature_name": "Salesforce integration",
"value": "available",
"name": "",
"is_overridden": false
}
},
{
"subscription_entitlement": {
"id": "KyVnHhSBWlm1j2m7",
"subscription_id": "JzDnHhSBWlm1j1n4",
"feature_id": "number_of_users",
"feature_name": "Number of users",
"value": "10",
"name": "",
"is_overridden": false
}
}]
}
feature_id
from the list.subscription_entitlements.value
and allow/deny the user access to the feature:
feature.type
switch
, allow access if subscription_entitlements.value
is true
.feature.type
quantity
or range
, allow access when subscription_entitlements.value
is either unlimited
or more than the consumed entitlements for the feature.feature.type
custom
, allow access based on your specific interpretation of subscription_entitlements.value
.Tip
subscription_entitlement
cache entries so that they may get refreshed periodically.