A robust in-app purchase library for React Native that simplifies receipt validation and subscription management through the Iaptic service.
- 🛒 Unified Purchasing API - Single interface for iOS and Android
- 🔄 Subscription Management - Easy status tracking and renewal handling
- 🔒 Secure Receipt Validation - Server-side validation via Iaptic
- 🛡 Error Handling - Comprehensive error codes and localization
- 📦 Product Catalog - Structured product definitions with pricing phases
- 📊 Entitlement Tracking - Real-time purchase state management
npm install react-native-iaptic
# or
yarn add react-native-iaptic
Here's a complete example to get you started:
import { IapticRN } from 'react-native-iaptic';
// 1. Initialize with your configuration
const iaptic = new IapticRN({
appName: 'app.example.com',
publicKey: 'YOUR_PUBLIC_KEY',
iosBundleId: 'com.yourcompany.app',
});
// 2. Define your products
iaptic.setProductDefinitions([
{
id: 'premium_monthly',
type: 'paid subscription',
entitlements: ['premium']
},
{
id: 'coins_100',
type: 'consumable',
tokenType: 'coins',
tokenValue: 100
}
]);
// 3. Initialize connection and load products/purchases
await iaptic.initialize();
// 4. Handle purchases
const offer = iaptic.products.get('premium_monthly')?.offers[0];
if (offer) {
await iaptic.order(offer);
}
// 5. Check access
if (iaptic.checkEntitlement('premium')) {
// Unlock premium features
}
Products can be subscriptions, consumables, or non-consumables. Each product can grant one or more entitlements:
iaptic.setProductDefinitions([
// Subscription that unlocks premium features
{
id: 'premium_monthly',
type: 'paid subscription',
entitlements: ['premium']
},
// Non-consumable that unlocks a specific feature
{
id: 'dark_theme',
type: 'non consumable',
entitlements: ['cool_feature']
},
// Consumable tokens/currency
{
id: 'coins_100',
type: 'consumable',
tokenType: 'coins',
tokenValue: 100
}
]);
Handle purchases with proper error management:
try {
await iaptic.order(productOffer);
} catch (error) {
showError(error);
}
Allow users to restore their previous purchases:
try {
iaptic.restorePurchases((processed, total) => {
console.log(`Processed ${processed} of ${total} purchases`);
});
}
catch (error) {
showError(error);
}
Listen for purchase and subscription updates:
// Listen for subscription updates
iaptic.addEventListener('subscription.updated', (reason, purchase) => {
console.log(`Subscription ${purchase.id} ${reason}`);
});
// Listen for pending purchase updates
iaptic.addEventListener('pendingPurchase.updated', (pendingPurchase) => {
console.log(`Purchase ${pendingPurchase.productId} is now ${pendingPurchase.status}`);
});
// Listen for purchase updates
iaptic.addEventListener('purchase.updated', (purchase) => {
console.log(`Purchase ${purchase.id} ${purchase.status}`);
});
Check if users have access to specific features:
// Check premium access
if (iaptic.checkEntitlement('premium')) {
showPremiumContent();
} else {
showUpgradePrompt();
}
// List all active entitlements
const unlockedFeatures = iaptic.listEntitlements();
// ['basic', 'premium', 'cool_feature']
function showError(error: Error | IapticError) {
if (error instanceof IapticError) {
trackAnalyticsEvent(error.code);
if (error.severity === IapticErrorSeverity.INFO) {
console.log('Info:', error.localizedMessage);
return;
}
Alert.alert(error.localizedTitle, error.localizedMessage);
} else {
Alert.alert('Unknown error', error.message);
}
}
For complete API documentation, visit our API Reference.
- 📘 Documentation
- 🐛 Issue Tracker
- 📱 Demo app
- 📧 Support
MIT © Iaptic