Static
addAdd an event listener for iaptic events
To remove a listener, call the returned object's remove()
method.
Type of event to listen for
Callback function that will be called when the event occurs
// Listen for subscription updates
IapticRN.addEventListener('subscription.updated', (reason, purchase) => {
console.log(`Subscription ${purchase.id} ${reason}`);
});
// Listen for pending purchase updates
IapticRN.addEventListener('pendingPurchase.updated', (pendingPurchase) => {
console.log(`Purchase ${pendingPurchase.productId} is now ${pendingPurchase.status}`);
});
// Listen for purchase updates
IapticRN.addEventListener('purchase.updated', (purchase) => {
console.log(`Purchase ${purchase.id} ${purchase.status}`);
});
// Listen for non-consumable purchases
IapticRN.addEventListener('nonConsumable.owned', (purchase) => {
console.log(`Non-consumable purchase ${purchase.id} is now owned`);
});
const listener = IapticRN.addEventListener('purchase.updated', (purchase) => {
console.log(`Purchase ${purchase.id} ${purchase.status}`);
});
listener.remove();
IapticEventType for all possible event types
Static
addAdd a locale for Iaptic provided components and error messages.
The language code
The locale messages
Static
checkCheck if the user has active access to a specific feature or content.
Entitlements represent features/content that users unlock through purchases. They are defined in product definitions and automatically tracked when purchases are validated.
The unique identifier for the feature/content (e.g. "premium", "gold_status")
True if the user has active access to the specified feature
Static
consumeConsume a purchase. Only for consumable products.
The purchase to consume
IapticTokensManager for a convenient way to handle your consumable products.
Static
destroyStatic
getGet the active subscription (if any)
For apps that sell multiple subscriptions that can be active at the same time, this returns the first one. To check if there is any active subscription:
The active subscription or undefined if there is no active subscription
IapticVerifiedPurchase for more information on the purchase object
const activeSubscription = IapticRN.getActiveSubscription();
if (activeSubscription) {
console.log(`Active subscription: ${activeSubscription.productId}`);
if (activeSubscription.renewalIntent === 'Renew') {
console.log('Will renew on: ' + new Date(activeSubscription.expiryDate).toLocaleDateString());
}
else {
console.log('Will expire on: ' + new Date(activeSubscription.expiryDate).toLocaleDateString());
}
}
Static
getGet all pending purchases.
List of pending purchases
Static
getGet a product from the product catalog
The product identifier
The product or undefined if not found
IapticProduct for more information on the product object
Static
getGet all products from the product catalog
List of products
IapticProduct for more information on the product object
Static
getGet all verified purchases.
List of purchases, most recent first
IapticVerifiedPurchase for more information on the purchase object
Static
initializeInitialize the IapticRN singleton
The configuration for the IapticRN singleton
IapticRN.initialize({
appName: 'com.example.app',
publicKey: '1234567890',
iosBundleId: 'com.example.app',
products: [
{ id: 'pro_monthly', type: 'paid subscription', entitlements: ['pro'] },
{ id: 'premium_lifetime', type: 'non consumable', entitlements: ['premium'] },
{ id: 'coins_100', type: 'consumable', tokenType: 'coins', tokenValue: 100 },
],
});
Static
isCheck if a product is owned.
The product identifier
True if the product is owned
Static
listGet all currently active entitlements for the user.
This aggregates entitlements from all non-expired purchases, including:
Entitlements are defined in product definitions and automatically tracked when purchases are validated.
Array of entitlement IDs the user currently has access to
Static
loadLoad products from the Store.
Optional
definitions: IapticProductDefinition[]The products to load
await IapticRN.loadProducts([
{ id: 'basic_subscription', type: 'paid subscription', entitlements: [ 'basic' ] },
{ id: 'premium_subscription', type: 'paid subscription', entitlements: [ 'basic', 'premium' ] },
{ id: 'premium_lifetime', type: 'non consumable', entitlements: [ 'basic', 'premium' ] },
{ id: 'coins_100', type: 'consumable', tokenType: 'coins', tokenValue: 100 },
]);
Static
loadLoad and validate active purchases details from the Store and Iaptic using their receipts
Notice that this is done when initialize the Store already.
List of verified purchases.
Static
manageStatic
manageStatic
orderOrder a product with an offer.
The offer to order
Static
presentStatic
removeRemove all event listeners for a specific event type If no event type is specified, removes all listeners for all events
Optional
eventType: IapticEventTypeOptional event type to remove listeners for
Static
restoreRestore purchases from the Store.
Callback function that will be called with the progress of the restore operation - An initial call with -1, 0 when the operation starts. - Subsequent calls are with the current progress (processed, total). - The final call will have processed === total, you know the operation is complete.
The number of purchases restored
Static
setSet the application username for the iaptic service.
This is used to track which user is making the purchase and associate it with the user's account.
Don't forget to update the username in the app service if the user changes (login/logout).
Static
setStatic
setAdd product definitions to the product catalog.
Entitlements define what features/content a product unlocks. They can be shared across multiple products (e.g. a subscription and lifetime purchase both granting "premium" access).
IapticRN.setProductDefinitions([
{
id: 'premium_monthly',
type: 'paid subscription',
entitlements: ['premium'] // Unlocks premium features
},
{
id: 'dark_theme',
type: 'non consumable',
entitlements: ['dark_theme'] // Unlocks visual feature
}
]);
Static
setSet the verbosity level for the iaptic service.
Iaptic React Native SDK.
This is the entry point for the Iaptic SDK, the main methods are:
Example: Simplified example (without Subscription UI)