⚠️ WARNING: WORK IS STILL IN PROGRESS. NOT READY FOR PRODUCTION YET
Tauri Plugin IAP
A Tauri plugin for In-App Purchases (IAP) with support for subscriptions on both iOS (StoreKit 2) and Android (Google Play Billing).
Features
- Initialize billing/store connection
- Query products and subscriptions with detailed pricing
- Purchase subscriptions with platform-specific features
- Restore previous purchases
- Get purchase history
- Real-time purchase state updates via events
- Automatic transaction verification (iOS)
- Support for introductory offers and free trials
Platform Support
- iOS: StoreKit 2 (requires iOS 15.0+)
- Android: Google Play Billing Library v8.0.0
Installation
Add the plugin to your Tauri project:
[]
= "0.1"
Register the plugin in your Tauri app:
Usage
JavaScript/TypeScript
import {
initialize,
getProducts,
purchase,
restorePurchases,
acknowledgePurchase,
onPurchaseUpdated
} from 'tauri-plugin-iap-api';
// Initialize the billing client
await initialize();
// Get available products
const products = await getProducts(['subscription_id_1', 'subscription_id_2'], 'subs');
// Purchase a subscription or in-app product
// On Android: use the offer token from subscriptionOfferDetails
// On iOS: offer token is not used
const purchaseResult = await purchase('subscription_id_1', 'subs', offerToken);
// Restore purchases (specify product type)
const restored = await restorePurchases('subs');
// Acknowledge a purchase (Android only, iOS auto-acknowledges)
await acknowledgePurchase(purchaseResult.purchaseToken);
// Listen for purchase updates
const unlisten = onPurchaseUpdated((purchase) => {
console.log('Purchase updated:', purchase);
});
// Stop listening
unlisten();
Platform Setup
iOS Setup
- Configure your app in App Store Connect
- Create subscription products with appropriate pricing
- Add In-App Purchase capability to your app in Xcode:
- Open your project in Xcode
- Select your target
- Go to "Signing & Capabilities"
- Click "+" and add "In-App Purchase"
- Test with sandbox accounts
Android Setup
- Add your app to Google Play Console
- Create subscription products in Google Play Console
- Configure your app's billing permissions (already included in the plugin)
- Test with test accounts or sandbox environment
API Reference
initialize()
Initializes the billing client connection (required on Android, no-op on iOS).
getProducts(productIds: string[], productType: 'subs' | 'inapp')
Fetches product details from the store.
Returns:
products: Array of product objects with:productId: Product identifiertitle: Display namedescription: Product descriptionproductType: Type of productformattedPrice: Localized price stringsubscriptionOfferDetails: (subscriptions only) Array of offers
purchase(productId: string, productType: 'subs' | 'inapp' = 'subs', offerToken?: string)
Initiates a purchase flow.
Parameters:
productId: The product to purchaseproductType: Type of product ('subs' for subscriptions, 'inapp' for one-time purchases), defaults to 'subs'offerToken: (Android only) The offer token for subscriptions
Returns: Purchase object with transaction details
restorePurchases(productType: 'subs' | 'inapp' = 'subs')
Queries and returns all active purchases.
Parameters:
productType: Type of products to restore ('subs' or 'inapp'), defaults to 'subs'
getPurchaseHistory()
Returns the complete purchase history.
acknowledgePurchase(purchaseToken: string)
Acknowledges a purchase (required on Android within 3 days, no-op on iOS).
onPurchaseUpdated(callback: (purchase: Purchase) => void)
Listens for purchase state changes.
Differences Between Platforms
iOS (StoreKit 2)
- Automatic transaction verification
- No manual acknowledgment needed
- Supports introductory offers and promotional offers
- Transaction updates are automatically observed
- Requires iOS 15.0+
Android (Google Play Billing)
- Manual acknowledgment required within 3 days
- Supports multiple subscription offers per product
- Offer tokens required for subscription purchases
- More detailed pricing phase information
Testing
iOS
- Use sandbox test accounts
- Test on physical devices (subscriptions don't work well on simulators)
- Clear purchase history in Settings > App Store > Sandbox Account
Android
- Upload your app to internal testing track
- Add test accounts in Google Play Console
- Test with test payment methods
License
MIT or Apache-2.0