import { NativeModules, Platform } from 'react-native'; const LINKING_ERROR = `The package '@jeremybarbet/react-native-purchase-kit' doesn't seem to be linked. Make sure: \n\n` + Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; if (!NativeModules.PurchaseKit) { throw new Error(LINKING_ERROR); } export enum ErrorCode { INPUT_VALIDATION = 'INPUT_VALIDATION', PENDING = 'PENDING', FAILED = 'FAILED', UNVERIFIED = 'UNVERIFIED', CANCELLED = 'CANCELLED', EMPTY = 'EMPTY', NOT_FOUND = 'NOT_FOUND', UNKNOWN = 'UNKNOWN', } export type ProductType = 'subscription' | 'consumable'; export interface ProductsInput { ids: string[]; type: ProductType; } interface Price { value: number; currency: string | null; localized: string | null; } interface Period { value: string; unit: string; localized: string; } interface Subscription { period: Period | null; } export interface Product { id: string; name: string; price: Price; subscription: Subscription | null; } export interface PurchaseInput { id: string; userId: string; type: ProductType; } export interface Transaction { id: string; originalId: string; productId: string; environment: 'production' | 'sandbox' | 'xcode' | 'android'; expirationDate: number; purchaseDate: number; originalPurchaseDate: number; token?: string; quantity: number; price: Price; } export interface FinishTransactionInput { id: string; type: ProductType; } export interface PurchaseKitError extends Error { code: ErrorCode; } interface NativePurchaseKit { products(input: ProductsInput): Promise; entitlements(): Promise; purchase(input: PurchaseInput): Promise; finishTransaction(input: FinishTransactionInput): Promise; syncPurchases(): Promise; } declare module 'react-native' { interface NativeModulesStatic { PurchaseKit: NativePurchaseKit; } } const { products, entitlements, purchase, finishTransaction, syncPurchases } = NativeModules.PurchaseKit; export const purchaseKit = { products, entitlements, purchase, finishTransaction, syncPurchases, };