Web entitlements enable apps that sell subscriptions via web checkout (e.g., Stripe) to unlock premium features in the native app in real-time. After calling identify(), the SDK listens for entitlement changes automatically.
How It Works
- User purchases a subscription on your website.
- Your backend writes the entitlement to AppDNA.
- The SDK detects the change in real-time and updates the local cache.
- Your app reacts via the callback and unlocks premium features.
Web entitlements are separate from in-app purchase entitlements (Play Billing). They are designed for apps that also sell subscriptions through a web checkout flow.
Check Current Entitlement
After identify(), the current web entitlement is available synchronously:
val entitlement = AppDNA.billing.webEntitlement
if (entitlement != null && entitlement.isActive) {
unlockPremium()
println("Plan: ${entitlement.planName}, Status: ${entitlement.status}")
}
Listen for Changes
Register a callback to react in real-time when the entitlement status changes:
AppDNA.billing.onWebEntitlementChanged { entitlement ->
if (entitlement?.isActive == true) {
unlockPremium()
} else {
lockPremium()
}
}
WebEntitlement
| Property | Type | Description |
|---|
isActive | Boolean | Whether the subscription is currently active |
planName | String | Name of the subscription plan |
productId | String | Product identifier |
status | String | Current status |
expiresAt | Date? | Expiration date |
Entitlement Statuses
| Status | Description |
|---|
active | Subscription is active and paid |
trialing | User is in a free trial period |
past_due | Payment failed, in grace period |
canceled | Subscription is canceled |
Auto-Tracked Events
| Event | Trigger |
|---|
web_entitlement_activated | Web subscription becomes active |
web_entitlement_expired | Web subscription expires or is canceled |
Full Example
import ai.appdna.sdk.AppDNA
class PremiumManager {
fun setup() {
AppDNA.billing.onWebEntitlementChanged { entitlement ->
updateAccessState(entitlement)
}
}
fun checkAccessOnLaunch() {
// Check in-app purchase entitlements
val hasIAP = AppDNA.billing.hasActiveSubscription()
if (hasIAP) {
unlockPremium()
return
}
// Check web entitlement
val web = AppDNA.billing.webEntitlement
if (web != null && web.isActive) {
unlockPremium()
return
}
lockPremium()
}
private fun updateAccessState(entitlement: WebEntitlement?) {
if (entitlement?.isActive == true) {
unlockPremium()
} else {
val hasIAP = AppDNA.billing.hasActiveSubscription()
if (!hasIAP) lockPremium()
}
}
}
Web entitlements require Stripe integration configured in the Console under Settings > Billing > Web Payments. The real-time listener activates after identify() is called.