A Tauri plugin for In-App Purchases (IAP) with support for subscriptions on both iOS (StoreKit 2) and Android (Google Play Billing).
- Initialize billing/store connection
- Query products and subscriptions with detailed pricing
- Purchase subscriptions with platform-specific features
- Restore previous purchases
- Get purchase history
- Check product ownership and subscription status
- Real-time purchase state updates via events
- Automatic transaction verification (iOS)
- Support for introductory offers and free trials
- Fraud prevention with obfuscated account/profile IDs (Android)
- App account token support for tracking (iOS)
- Automatic offer token selection (Android)
- iOS: StoreKit 2 (requires iOS 15.0+)
- Android: Google Play Billing Library v8.0.0
Install the JavaScript package:
npm install @choochmeque/tauri-plugin-iap-api
# or
yarn add @choochmeque/tauri-plugin-iap-api
# or
pnpm add @choochmeque/tauri-plugin-iap-api
Add the plugin to your Tauri project's Cargo.toml
:
[dependencies]
tauri-plugin-iap = "0.3"
Configure the plugin permissions in your capabilities/default.json
:
{
"permissions": [
"iap:default"
]
}
Register the plugin in your Tauri app:
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_iap::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
import {
initialize,
getProducts,
purchase,
restorePurchases,
acknowledgePurchase,
getProductStatus,
onPurchaseUpdated,
PurchaseState
} 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');
// Check if user owns a specific product
const status = await getProductStatus('subscription_id_1', 'subs');
if (status.isOwned && status.purchaseState === PurchaseState.PURCHASED) {
console.log('User has active subscription');
if (status.isAutoRenewing) {
console.log('Subscription will auto-renew');
}
}
// Purchase a subscription or in-app product
// Simple purchase (will use first available offer on Android if not specified)
const purchaseResult = await purchase('subscription_id_1', 'subs');
// With specific offer token (Android)
const purchaseResult = await purchase('subscription_id_1', 'subs', {
offerToken: product.subscriptionOfferDetails[0].offerToken
});
// With fraud prevention (Android)
const purchaseResult = await purchase('subscription_id_1', 'subs', {
obfuscatedAccountId: 'hashed_account_id',
obfuscatedProfileId: 'hashed_profile_id'
});
// With app account token (iOS - must be valid UUID)
const purchaseResult = await purchase('subscription_id_1', 'subs', {
appAccountToken: '550e8400-e29b-41d4-a716-446655440000'
});
// 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();
- 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
- 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
Initializes the billing client connection (required on Android, no-op on iOS).
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
Initiates a purchase flow with enhanced options for fraud prevention and account management.
Parameters:
productId
: The product to purchaseproductType
: Type of product ('subs' for subscriptions, 'inapp' for one-time purchases), defaults to 'subs'options
: Optional purchase parameters:offerToken
: (Android) Specific offer to purchase. If not provided, uses first available offerobfuscatedAccountId
: (Android) Hashed account ID for fraud preventionobfuscatedProfileId
: (Android) Hashed profile ID for fraud preventionappAccountToken
: (iOS) UUID string for account tracking and fraud prevention
Returns: Purchase object with transaction details
Queries and returns all active purchases.
Parameters:
productType
: Type of products to restore ('subs' or 'inapp'), defaults to 'subs'
Returns the complete purchase history.
Acknowledges a purchase (required on Android within 3 days, no-op on iOS).
Checks the ownership and subscription status of a specific product.
Parameters:
productId
: The product identifier to checkproductType
: Type of product ('subs' or 'inapp'), defaults to 'subs'
Returns: ProductStatus object with:
productId
: Product identifierisOwned
: Whether the user currently owns the productpurchaseState
: Current state (PURCHASED=0, CANCELED=1, PENDING=2)purchaseTime
: When the product was purchased (timestamp)expirationTime
: (subscriptions only) When the subscription expiresisAutoRenewing
: (subscriptions only) Whether auto-renewal is enabledisAcknowledged
: Whether the purchase has been acknowledgedpurchaseToken
: Token for the purchase transaction
Listens for purchase state changes.
- Automatic transaction verification
- No manual acknowledgment needed
- Supports introductory offers and promotional offers
- Transaction updates are automatically observed
- Requires iOS 15.0+
- Manual acknowledgment required within 3 days
- Supports multiple subscription offers per product
- Offer tokens required for subscription purchases
- More detailed pricing phase information
- Use sandbox test accounts
- Test on physical devices (subscriptions don't work well on simulators)
- Clear purchase history in Settings > App Store > Sandbox Account
- Upload your app to internal testing track
- Add test accounts in Google Play Console
- Test with test payment methods