### Install Dependencies Source: https://github.com/buildingapplications/iap/blob/main/_autodocs/INTEGRATION_GUIDE.md Install the necessary @biltme/iap package and its peer dependencies. Ensure all versions are consistent, especially in monorepos. ```bash npm install @biltme/iap npm install react react-native expo-iap @react-native-async-storage/async-storage ``` -------------------------------- ### EntitlementMap Example Usage Source: https://github.com/buildingapplications/iap/blob/main/_autodocs/types.md An example demonstrating how to structure an EntitlementMap, showing different entitlement configurations for 'pro' and 'premium' products. ```typescript const entitlements: EntitlementMap = { pro: { active: true, status: 'active', platform: 'IOS', productId: 'com.example.pro.monthly', expirationDate: 1693526400000, isAutoRenewing: true, }, premium: { active: false, status: 'expired', platform: 'IOS', }, }; ``` -------------------------------- ### No-auth Tenant Configuration Source: https://github.com/buildingapplications/iap/blob/main/_autodocs/configuration.md Example configuration for a no-auth tenant, requiring only the tenantAppId and product IDs. ```typescript const config: BiltIapConfig = { tenantAppId: '11111111-1111-1111-1111-111111111111', productIds: [{ id: 'com.example.pro.monthly' }], }; ``` -------------------------------- ### Supabase-auth Tenant Configuration Source: https://github.com/buildingapplications/iap/blob/main/_autodocs/configuration.md Example configuration for a Supabase-auth tenant, including tenantAppId, a getAccessToken function, and product IDs. ```typescript import { supabase } from './supabaseClient'; import type { BiltIapConfig } from '@biltme/iap'; const config: BiltIapConfig = { tenantAppId: '11111111-1111-1111-1111-111111111111', getAccessToken: async () => { const { data } = await supabase.auth.getSession(); return data.session?.access_token ?? null; }, productIds: [ { id: 'com.example.pro.monthly' }, { id: 'com.example.pro.annual' }, ], onError: (err) => console.warn('[BiltIAP]', err), }; ``` -------------------------------- ### Install @biltme/iap Source: https://github.com/buildingapplications/iap/blob/main/README.md Install the @biltme/iap package using npm or bun. Ensure peer dependencies like react, react-native, expo-iap, and @react-native-async-storage/async-storage are installed at the correct versions. ```sh npm install @biltme/iap # or bun add @biltme/iap ``` -------------------------------- ### Build Paywall UI with Hooks Source: https://github.com/buildingapplications/iap/blob/main/_autodocs/INTEGRATION_GUIDE.md Implement a paywall screen using `useBiltIAP` and `useEntitlement` hooks. This example shows how to display products, handle purchases, restore purchases, and manage loading and entitlement states. ```typescript import React from 'react'; import { View, Text, Button, ActivityIndicator } from 'react-native'; import { useBiltIAP, useEntitlement, BiltIapError } from '@biltme/iap'; export function PaywallScreen() { const { initialized, loading, products, purchasing, purchaseProduct, restorePurchases, } = useBiltIAP(); const pro = useEntitlement('pro'); // Show loading state until initialized if (!initialized) { return ( ); } // If user has pro, show different UI if (pro.active) { return ( You have Pro!