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.
- Your app reacts via the callback and unlocks premium features.
Web entitlements are separate from in-app purchase entitlements. 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:
final entitlement = AppDNA.billing.webEntitlement;
if (entitlement != null && entitlement.isActive) {
unlockPremium();
print("Plan: ${entitlement.planName}, Status: ${entitlement.status}");
}
Listen for Changes
AppDNA.billing.onWebEntitlementChanged((entitlement) {
if (entitlement?.isActive == true) {
unlockPremium();
} else {
lockPremium();
}
});
WebEntitlement
| Property | Type | Description |
|---|
isActive | bool | Whether the subscription is currently active |
planName | String | Name of the subscription plan |
productId | String | Product identifier |
status | String | Current status |
expiresAt | DateTime? | 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 'package:appdna_sdk/appdna_sdk.dart';
class PremiumManager {
void setup() {
AppDNA.billing.onWebEntitlementChanged((entitlement) {
_updateAccessState(entitlement);
});
}
Future<void> checkAccessOnLaunch() async {
final hasIAP = await AppDNA.billing.hasActiveSubscription();
if (hasIAP) {
unlockPremium();
return;
}
final web = AppDNA.billing.webEntitlement;
if (web != null && web.isActive) {
unlockPremium();
return;
}
lockPremium();
}
void _updateAccessState(WebEntitlement? entitlement) {
if (entitlement?.isActive == true) {
unlockPremium();
} else {
AppDNA.billing.hasActiveSubscription().then((hasIAP) {
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.