### Install Pods for iOS Example Source: https://github.com/hyochan/react-native-iap/blob/main/docs/blog/2025-09-10-release-14.2.0.md Run this command to install the necessary pods for the iOS example or application after upgrading. ```bash cd example/ios && pod install ``` -------------------------------- ### Start Metro Bundler for Expo Example Source: https://github.com/hyochan/react-native-iap/blob/main/CLAUDE.md Start the Metro bundler for the Expo example app by running 'bun start' within the 'example-expo' directory. ```sh cd example-expo && bun start ``` -------------------------------- ### iOS Setup for Example Apps Source: https://github.com/hyochan/react-native-iap/blob/main/AGENTS.md Instructions for setting up iOS dependencies using Bundler and CocoaPods for both the workspace example and the independent Expo example. ```sh # For example (workspace) cd example/ios bundle install # Install Ruby dependencies bundle exec pod install # Install iOS dependencies ``` ```sh # For example-expo (independent) cd example-expo/ios pod install # iOS dependencies ``` -------------------------------- ### Setup Expo Example App Source: https://github.com/hyochan/react-native-iap/blob/main/CONTRIBUTING.md Set up the independent Expo example application using Bun. ```bash cd example-expo && bun setup ``` -------------------------------- ### Run Example-Expo App (Independent Project) Source: https://github.com/hyochan/react-native-iap/blob/main/AGENTS.md Commands for setting up and running the independent Expo example app using Bun. This includes initial setup, running on iOS and Android, and starting the Metro bundler. ```sh # Initial setup (copies lib files and builds) cd example-expo && bun setup ``` ```sh # iOS cd example-expo && bun ios cd example-expo && bun ios --device # For physical device ``` ```sh # Android cd example-expo && bun android ``` ```sh # Start Metro bundler cd example-expo && bun start ``` -------------------------------- ### Example Prompt: Basic Setup Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/guides/ai-assistants.md Use this prompt to ask an AI assistant for help with the basic setup of react-native-iap, including product fetching and purchase handling. ```text Using react-native-iap documentation, show me how to set up a basic store with product fetching and purchase handling. ``` -------------------------------- ### Start Metro Bundler for React Native Example Source: https://github.com/hyochan/react-native-iap/blob/main/CLAUDE.md Start the Metro bundler for the React Native example app by running 'yarn start' within the 'example' directory. ```sh cd example && yarn start ``` -------------------------------- ### Automated Expo Setup Command Source: https://github.com/hyochan/react-native-iap/blob/main/example-expo/README.md Run this command from the root directory for a complete automated setup of the Expo example app. It installs dependencies, runs the postinstall script, and generates native code. ```bash yarn setup:expo ``` -------------------------------- ### Install iOS Pods Source: https://github.com/hyochan/react-native-iap/blob/main/AGENTS.md Navigate to the example's iOS directory and run `bundle exec pod install` to resolve iOS build errors. ```bash cd example/ios bundle exec pod install ``` -------------------------------- ### Install Ruby Dependencies for Example (Workspace) Source: https://github.com/hyochan/react-native-iap/blob/main/CLAUDE.md For the React Native example app (workspace), install Ruby dependencies by navigating to 'example/ios' and running 'bundle install'. ```sh cd example/ios bundle install ``` -------------------------------- ### Basic Listener Setup and Cleanup Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/api/methods/listeners.md This example demonstrates the fundamental setup and cleanup of purchase update and error listeners using `useEffect`. It's crucial for preventing memory leaks and ensuring proper listener management. ```tsx useEffect(() => { const purchaseUpdateSubscription = purchaseUpdatedListener((purchase) => { // Handle successful/pending purchases }); const purchaseErrorSubscription = purchaseErrorListener((error) => { // Handle purchase errors }); return () => { purchaseUpdateSubscription?.remove(); purchaseErrorSubscription?.remove(); }; }, []); ``` -------------------------------- ### Install iOS Dependencies for Expo Example (Independent) Source: https://github.com/hyochan/react-native-iap/blob/main/CLAUDE.md For the independent Expo example app, install iOS dependencies by navigating to 'example-expo/ios' and running 'pod install'. ```sh cd example-expo/ios pod install ``` -------------------------------- ### setup() removal Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/guides/migration-v13-to-v14.md Illustrates the removal of the setup() function as StoreKit 2 is used by default in v14. ```tsx // v13 import {setup} from 'react-native-iap'; setup({storekitMode: 'STOREKIT2_MODE'}); // v14 // Not needed - StoreKit 2 is used by default ``` -------------------------------- ### Install iOS Dependencies for Example (Workspace) Source: https://github.com/hyochan/react-native-iap/blob/main/CLAUDE.md After installing Ruby dependencies, install the iOS project dependencies using CocoaPods by running 'bundle exec pod install' in the 'example/ios' directory. ```sh bundle exec pod install ``` -------------------------------- ### Manual Installation Script Source: https://github.com/hyochan/react-native-iap/blob/main/example-expo/README.md If manual installation is needed, use these commands. The `bun install` command will automatically run the postinstall script. ```bash bun install ./scripts/postinstall.sh ``` -------------------------------- ### Run Example App Source: https://github.com/hyochan/react-native-iap/blob/main/docs/blog/2025-10-05-release-14.4.12-alternative-billing.md Instructions to run the example application for testing alternative billing features. ```bash cd example yarn ios # or yarn android # Navigate to "Alternative Billing" from home screen ``` -------------------------------- ### iOS Setup - Pod Install Source: https://github.com/hyochan/react-native-iap/blob/main/docs/static/llms-full.txt Navigate to the ios directory and run pod install to set up the iOS environment. ```bash cd ios && pod install ``` -------------------------------- ### Quick Start with useIAP Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/examples/subscription-flow.md Demonstrates the basic usage of the `useIAP` hook for managing subscriptions, including fetching products, requesting purchases, and handling purchase success and errors. ```tsx const {subscriptions, fetchProducts, requestPurchase, finishTransaction} = useIAP({ onPurchaseSuccess: async (purchase) => { // Validate on your server, then finish await finishTransaction({purchase}); }, onPurchaseError: (error) => { if (error.code !== ErrorCode.UserCancelled) { Alert.alert('Error', error.message); } }, }); // Load subscriptions await fetchProducts({skus: ['premium_monthly'], type: 'subs'}); // Purchase (platform-specific) const subscription = subscriptions[0]; await requestPurchase({ request: { apple: {sku: 'premium_monthly'}, google: { skus: ['premium_monthly'], subscriptionOffers: subscription.subscriptionOfferDetailsAndroid?.map((offer) => ({ sku: subscription.id, offerToken: offer.offerToken, })) || [], }, }, type: 'subs', }); ``` -------------------------------- ### Run Tests with Coverage (Example App) Source: https://github.com/hyochan/react-native-iap/blob/main/docs/CODECOV.md Navigate to the example directory and run tests with coverage enabled. ```bash cd example bun test --coverage ``` -------------------------------- ### Run Example App (React Native - Workspace) Source: https://github.com/hyochan/react-native-iap/blob/main/AGENTS.md Commands to build and run the React Native example app, including iOS and Android platforms, and starting the Metro bundler. These commands can be run from the project root. ```sh # iOS cd example && yarn ios cd example && yarn ios --device # For physical device ``` ```sh # Android cd example && yarn android ``` ```sh # Start Metro bundler cd example && yarn start ``` ```sh # Or from root: yarn workspace rn-iap-example ios yarn workspace rn-iap-example android yarn workspace rn-iap-example start ``` -------------------------------- ### Install Bun Source: https://github.com/hyochan/react-native-iap/blob/main/docs/README.md Installs Bun, the package manager used for this project. Ensure Bun is installed before proceeding with project setup. ```bash curl -fsSL https://bun.sh/install | bash ``` -------------------------------- ### Install iOS Pods Source: https://github.com/hyochan/react-native-iap/blob/main/README.md Navigate to the ios directory and run 'pod install' to install necessary dependencies for iOS. ```bash cd ios && pod install ``` -------------------------------- ### Install Dependencies with Yarn 3 Workspaces Source: https://github.com/hyochan/react-native-iap/blob/main/AGENTS.md Use 'yarn install' to install dependencies for the library and the main example app. Other commands are provided for adding packages to specific workspaces or independent projects. ```sh yarn install ``` ```sh yarn add [package] ``` ```sh yarn workspace rn-iap-example add [package] ``` ```sh cd example-expo && bun add [package] ``` ```sh yarn [script] ``` ```sh yarn dlx [package] ``` ```sh npx [package] ``` -------------------------------- ### Example Prompt: Subscription Implementation Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/guides/ai-assistants.md This prompt is designed to get assistance with implementing subscription purchases using react-native-iap, specifically including Android offer tokens handling. ```text How do I implement subscription purchases with react-native-iap? Include Android offer tokens handling. ``` -------------------------------- ### Complete Migration Example - Before (v13) Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/guides/migration-v13-to-v14.md This code block shows a complete example of initializing and using the `react-native-iap` library in v13, including fetching products and handling purchases. ```typescript import { initConnection, endConnection, getProducts, getSubscriptions, requestPurchase, requestSubscription, finishTransaction, purchaseUpdatedListener, purchaseErrorListener, clearProductsIOS, flushFailedPurchasesCachedAsPendingAndroid, } from 'react-native-iap'; const productSkus = ['com.app.product1']; const subscriptionSkus = ['com.app.subscription1']; export const useInitIAP = () => { useEffect(() => { const init = async () => { await initConnection(); if (Platform.OS === 'android') { await flushFailedPurchasesCachedAsPendingAndroid(); } else { await clearProductsIOS(); } // Fetch products const products = await getProducts({skus: productSkus}); const subscriptions = await getSubscriptions({skus: subscriptionSkus}); }; init(); return () => endConnection(); }, []); }; // Purchase const buyProduct = async (sku: string) => { await requestPurchase({sku}); }; const buySubscription = async (sku: string, offerToken?: string) => { await requestSubscription({ sku, subscriptionOffers: offerToken ? [{sku, offerToken}] : undefined, }); }; ``` -------------------------------- ### Run React Native Example App on iOS Source: https://github.com/hyochan/react-native-iap/blob/main/CLAUDE.md To run the React Native example app on iOS, navigate to the 'example' directory and run 'yarn ios'. Dependencies are managed via workspaces, so no separate installation is needed. ```sh cd example && yarn ios ``` -------------------------------- ### getProducts() to fetchProducts() Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/guides/migration-v13-to-v14.md Example of migrating from getProducts to fetchProducts for in-app products. ```tsx // v13 import {getProducts} from 'react-native-iap'; const products = await getProducts({skus: ['product.id']}); // v14 import {fetchProducts} from 'react-native-iap'; const products = await fetchProducts({skus: ['product.id'], type: 'in-app'}); ``` -------------------------------- ### Run React Native Example App Source: https://github.com/hyochan/react-native-iap/blob/main/CONTRIBUTING.md Navigate to the example directory and run the iOS or Android application using Yarn. ```bash cd example && yarn ios ``` ```bash cd example && yarn android ``` -------------------------------- ### Run Example App on iOS Source: https://github.com/hyochan/react-native-iap/blob/main/example/README.md Executes the example application on an iOS simulator or device. ```sh yarn example:ios ``` -------------------------------- ### Build Release APK for Android Example Source: https://github.com/hyochan/react-native-iap/blob/main/CONTRIBUTING.md Assemble a release build of the Android example application. ```bash cd example/android && ./gradlew :app:assembleRelease ``` -------------------------------- ### Run Example App on Android Source: https://github.com/hyochan/react-native-iap/blob/main/example/README.md Executes the example application on an Android emulator or device. ```sh yarn example:android ``` -------------------------------- ### getSubscriptions() to fetchProducts() Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/guides/migration-v13-to-v14.md Example of migrating from getSubscriptions to fetchProducts for subscription products. ```tsx // v13 import {getSubscriptions} from 'react-native-iap'; const subscriptions = await getSubscriptions({skus: ['subscription.id']}); // v14 import {fetchProducts} from 'react-native-iap'; const subscriptions = await fetchProducts({skus: ['subscription.id'], type: 'subs'}); ``` -------------------------------- ### Running Expo App on iOS Source: https://github.com/hyochan/react-native-iap/blob/main/example-expo/README.md Commands to run the Expo example app on an iOS simulator or a physical device after setup. ```bash bun ios --device bun ios ``` -------------------------------- ### Running Expo App on Android Source: https://github.com/hyochan/react-native-iap/blob/main/example-expo/README.md Command to run the Expo example app on an Android emulator or physical device after setup. ```bash bun android ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/hyochan/react-native-iap/blob/main/docs/README.md Installs all project dependencies using Bun. This command should be run after cloning the repository or pulling changes. ```bash bun install ``` -------------------------------- ### Run Expo Example Tests Source: https://github.com/hyochan/react-native-iap/blob/main/CONTRIBUTING.md Execute tests for the Expo example application using Bun. ```bash cd example-expo && bun test ``` -------------------------------- ### Run React Native Example Tests Source: https://github.com/hyochan/react-native-iap/blob/main/CONTRIBUTING.md Execute tests specifically for the React Native example application. ```bash cd example && yarn test ``` -------------------------------- ### Install Dependencies Source: https://github.com/hyochan/react-native-iap/blob/main/AGENTS.md Installs project dependencies using Yarn. This command should be run before other checks or development tasks. ```bash yarn install ``` -------------------------------- ### Run Expo Example App Source: https://github.com/hyochan/react-native-iap/blob/main/CONTRIBUTING.md Navigate to the example-expo directory and run the iOS or Android application using Bun. ```bash cd example-expo && bun ios ``` ```bash cd example-expo && bun android ``` -------------------------------- ### Start Local Development Server Source: https://github.com/hyochan/react-native-iap/blob/main/docs/README.md Starts a local development server for live previewing changes. Most modifications are reflected without needing a server restart. ```bash bun run start ``` -------------------------------- ### Complete Flow Example (Legacy) Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/api/methods/android-specific.md An example demonstrating the complete flow for purchasing with alternative billing on Android, including checking availability, showing dialogs, processing payments, and creating reporting tokens. ```APIDOC ## Complete Flow Example (Legacy) ### Description This example demonstrates the complete flow for purchasing with alternative billing on Android. It includes checking availability, showing the required dialog to the user, processing the payment in your system, creating a reporting token, and reporting to Google Play backend. ### Method `checkAlternativeBillingAvailabilityAndroid`, `showAlternativeBillingDialogAndroid`, `createAlternativeBillingTokenAndroid`, `processPaymentInYourSystem` (custom), `reportToGooglePlayBackend` (custom) ### Endpoint N/A (Function calls) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```ts import { checkAlternativeBillingAvailabilityAndroid, showAlternativeBillingDialogAndroid, createAlternativeBillingTokenAndroid, } from 'react-native-iap'; async function purchaseWithAlternativeBilling(productId: string) { // Step 1: Check availability const isAvailable = await checkAlternativeBillingAvailabilityAndroid(); if (!isAvailable) { throw new Error('Alternative billing not available'); } // Step 2: Show required dialog const userAccepted = await showAlternativeBillingDialogAndroid(); if (!userAccepted) { throw new Error('User declined alternative billing'); } // Step 3: Process payment in your system const paymentResult = await processPaymentInYourSystem(productId); // Assume this function exists if (!paymentResult.success) { throw new Error('Payment failed'); } // Step 4: Create reporting token const token = await createAlternativeBillingTokenAndroid(productId); if (!token) { throw new Error('Failed to create token'); } // Step 5: Report to Google (must be done within 24 hours) await reportToGooglePlayBackend(token, productId, paymentResult); // Assume this function exists return {success: true, token}; } ``` ### Response N/A (Example function) ``` -------------------------------- ### Run Coverage Tests for Both Main Library and Example App Source: https://github.com/hyochan/react-native-iap/blob/main/docs/CODECOV.md Execute a script from the project root to run coverage tests for both the main library and the example app. ```bash # From project root ./scripts/test-coverage.sh ``` -------------------------------- ### getPurchaseHistory() to getAvailablePurchases() Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/guides/migration-v13-to-v14.md Example of migrating from getPurchaseHistory to getAvailablePurchases. ```tsx // v13 import {getPurchaseHistory} from 'react-native-iap'; const history = await getPurchaseHistory(); // v14 import {getAvailablePurchases} from 'react-native-iap'; const purchases = await getAvailablePurchases(); ``` -------------------------------- ### v13 Error Handling Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/guides/migration-v13-to-v14.md Example of error handling in v13 using the purchaseErrorListener. ```tsx // v13 purchaseErrorListener((error) => { console.error('Error code:', error.code); console.error('Error message:', error.message); }); ``` -------------------------------- ### Complete Alternative Billing Flow Example (Android) Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/api/methods/android-specific.md A comprehensive example demonstrating the steps for handling purchases with alternative billing on Android, including checking availability, showing the dialog, processing payment, creating a token, and reporting to Google Play. ```typescript import { checkAlternativeBillingAvailabilityAndroid, showAlternativeBillingDialogAndroid, createAlternativeBillingTokenAndroid, } from 'react-native-iap'; async function purchaseWithAlternativeBilling(productId: string) { // Step 1: Check availability const isAvailable = await checkAlternativeBillingAvailabilityAndroid(); if (!isAvailable) { throw new Error('Alternative billing not available'); } // Step 2: Show required dialog const userAccepted = await showAlternativeBillingDialogAndroid(); if (!userAccepted) { throw new Error('User declined alternative billing'); } // Step 3: Process payment in your system const paymentResult = await processPaymentInYourSystem(productId); if (!paymentResult.success) { throw new Error('Payment failed'); } // Step 4: Create reporting token const token = await createAlternativeBillingTokenAndroid(productId); if (!token) { throw new Error('Failed to create token'); } // Step 5: Report to Google (must be done within 24 hours) await reportToGooglePlayBackend(token, productId, paymentResult); return {success: true, token}; } ``` -------------------------------- ### Get Active Subscriptions Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/guides/subscription-validation.md Example of using getActiveSubscriptions to check for active subscriptions for a given product ID. ```typescript import {getActiveSubscriptions} from 'react-native-iap'; const active = await getActiveSubscriptions(['your.yearly.subscription']); if (active.length === 0) { // user has no valid subscription } ``` -------------------------------- ### requestSubscription() to requestPurchase() with type: 'subs' Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/guides/migration-v13-to-v14.md Example of migrating from requestSubscription to requestPurchase with the 'subs' type for subscriptions. ```tsx // v13 import {requestSubscription} from 'react-native-iap'; await requestSubscription({ sku: 'subscription.id', subscriptionOffers: [{sku: 'subscription.id', offerToken: 'token'}], }); // v14 import {requestPurchase} from 'react-native-native-iap'; await requestPurchase({ request: { apple: {sku: 'subscription.id'}, google: { skus: ['subscription.id'], subscriptionOffers: [{sku: 'subscription.id', offerToken: 'token'}], }, }, type: 'subs', }); ``` -------------------------------- ### buyPromotedProductIOS() to requestPurchase() with listener Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/guides/migration-v13-to-v14.md Example of migrating from buyPromotedProductIOS to using requestPurchase with a listener for promoted products. ```tsx // v13 import {buyPromotedProductIOS} from 'react-native-iap'; await buyPromotedProductIOS(); // v14 import {promotedProductListenerIOS, requestPurchase} from 'react-native-iap'; // Set up listener for promoted products const subscription = promotedProductListenerIOS((product) => { // Purchase the promoted product directly requestPurchase({ request: {apple: {sku: product.id}}, type: 'in-app', }); }); // Clean up when done subscription.remove(); ``` -------------------------------- ### Get Subscription Status for iOS Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/guides/subscription-validation.md Example of using subscriptionStatusIOS to retrieve the StoreKit 2 subscription status for a given product ID. ```typescript import {subscriptionStatusIOS} from 'react-native-iap'; const statuses = await subscriptionStatusIOS('your.yearly.subscription'); const latestState = statuses[0]?.state ?? 'unknown'; ``` -------------------------------- ### v14 Android Subscription Offers Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/guides/migration-v13-to-v14.md Example of requesting a purchase for an Android subscription using subscription offers in v14. ```tsx // v14 - Android subscriptions const subscription = subscriptions.find((s) => s.id === 'sub.id'); const offers = subscription?.subscriptionOfferDetailsAndroid ?? []; await requestPurchase({ request: { google: { skus: ['sub.id'], subscriptionOffers: offers.map((offer) => ({ sku: 'sub.id', offerToken: offer.offerToken, })), }, }, type: 'subs', }); ``` -------------------------------- ### Import Order Example Source: https://github.com/hyochan/react-native-iap/blob/main/docs/CONVENTIONS.md Demonstrates the recommended order for imports: external dependencies, internal modules, types, and styles/assets. ```typescript // External import React from 'react'; import {Platform} from 'react-native'; // Internal modules import {ExpoIapModule} from '../ExpoIapModule'; import {validateReceipt} from '../utils'; // Types import type {Product, Purchase} from '../types'; ``` -------------------------------- ### v14 Error Handling Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/guides/migration-v13-to-v14.md Example of error handling in v14 using the unified ErrorCode enum and isUserCancelledError helper. ```tsx // v14 - Using unified ErrorCode enum import {purchaseErrorListener, ErrorCode, isUserCancelledError} from 'react-native-iap'; purchaseErrorListener((error) => { // Helper function if (isUserCancelledError(error)) { return; // User cancelled, no action needed } // Or use ErrorCode enum directly switch (error.code) { case ErrorCode.UserCancelled: // User cancelled break; case ErrorCode.ItemUnavailable: Alert.alert('Product not available'); break; case ErrorCode.NetworkError: Alert.alert('Network error, please try again'); break; default: Alert.alert('Purchase failed', error.message); } }); ``` -------------------------------- ### v14 Unified API Usage Source: https://github.com/hyochan/react-native-iap/blob/main/docs/docs/guides/migration-v13-to-v14.md Example of using the unified API in v14 for fetching products and subscriptions, and handling purchases. ```tsx import { useIAP, fetchProducts, requestPurchase, finishTransaction, ErrorCode, } from 'react-native-iap'; const productSkus = ['com.app.product1']; const subscriptionSkus = ['com.app.subscription1']; export const MyStoreComponent = () => { const { connected, products, subscriptions, fetchProducts, requestPurchase, finishTransaction, } = useIAP({ onPurchaseSuccess: async (purchase) => { console.log('Purchase successful:', purchase.productId); // Validate on your server, then finish await finishTransaction({purchase, isConsumable: false}); }, onPurchaseError: (error) => { if (error.code !== ErrorCode.UserCancelled) { console.error('Purchase failed:', error.message); } }, }); useEffect(() => { if (!connected) return; // Fetch products (unified API) fetchProducts({skus: productSkus, type: 'in-app'}); fetchProducts({skus: subscriptionSkus, type: 'subs'}); }, [connected, fetchProducts]); // Purchase product const buyProduct = async (productId: string) => { await requestPurchase({ request: { apple: {sku: productId}, google: {skus: [productId]}, }, type: 'in-app', }); }; // Purchase subscription const buySubscription = async (subscriptionId: string) => { const subscription = subscriptions.find((s) => s.id === subscriptionId); const offers = subscription?.subscriptionOfferDetailsAndroid ?? []; await requestPurchase({ request: { apple: {sku: subscriptionId}, google: { skus: [subscriptionId], ...(offers.length > 0 && { subscriptionOffers: offers.map((o) => ({ sku: subscriptionId, offerToken: o.offerToken, })), }), }, }, type: 'subs', }); }; return ( {products.map((product) => (