@amisi/subscriptions
@amisi/subscriptions provides an adapter-based in-app subscription and purchase API for managing subscriptions across iOS, Android, and web platforms.
Adapter model
- Adapters implement a shared
SubscriptionAdaptercontract - The active adapter is selected at runtime via
initializeSubscriptions({ adapter, options }) - Built-in adapters:
revenuecat,mock
Initialize
Initialize once at app startup:SubscriptionsProvider
Wrap your app with theSubscriptionsProvider to provide subscription context throughout your app:
- Initializes the subscription adapter
- Fetches products and subscription status
- Provides subscription state to all child components
- Handles refresh and purchase operations
Hook usage
useSubscriptions
Access subscription state and operations from the provider:useEntitlement
Check if a user has access to a specific product:useHasActiveSubscription
Check if the user has any active subscription:useSubscriptionProduct
Get the current active subscription product ID:Hook alias usage
useSubscription is an alias of useSubscriptions and must be used inside SubscriptionsProvider:
Purchase a product
Restore purchases
Check subscription status
Thestatus object contains:
Available products
Theproducts array contains:
RevenueCat adapter
The RevenueCat adapter supports the following options:Mock adapter
For testing and development:Paywall component
Use the built-inPaywall component:
Custom adapter
Create a custom adapter by implementing theSubscriptionAdapter interface: