import {NativeModules} from 'react-native'; import type {Product, ProductPurchase, Sku} from '../types'; import type { PaymentDiscountSk2, ProductSk2, ProductStatus, RefundRequestStatus, TransactionSk2, } from '../types/appleSk2'; import type {NativeModuleProps} from './common'; const {RNIapIosSk2} = NativeModules; type getItems = (skus: Sku[]) => Promise; type getAvailableItems = ( alsoPublishToEventListener?: boolean, onlyIncludeActiveItems?: boolean, ) => Promise; export type BuyProduct = ( sku: Sku, andDangerouslyFinishTransactionAutomaticallyIOS: boolean, applicationUsername: string | undefined, quantity: number, withOffer: Record | undefined, ) => Promise; type clearTransaction = () => Promise; type clearProducts = () => Promise; type promotedProduct = () => Promise; type buyPromotedProduct = () => Promise; type finishTransaction = (transactionIdentifier: string) => Promise; type getPendingTransactions = () => Promise; type presentCodeRedemptionSheet = () => Promise; type showManageSubscriptions = () => Promise; type getStorefront = () => Promise; export interface IosModulePropsSk2 extends NativeModuleProps { isAvailable(): number; latestTransaction(sku: string): Promise; currentEntitlement(sku: string): Promise; subscriptionStatus(sku: string): Promise; isEligibleForIntroOffer(groupID: string): Promise; sync(): Promise; getItems: getItems; getAvailableItems: getAvailableItems; buyProduct: BuyProduct; clearTransaction: clearTransaction; clearProducts: clearProducts; promotedProduct: promotedProduct; buyPromotedProduct: buyPromotedProduct; finishTransaction: finishTransaction; getPendingTransactions: getPendingTransactions; presentCodeRedemptionSheet: presentCodeRedemptionSheet; showManageSubscriptions: showManageSubscriptions; disable: () => Promise; beginRefundRequest: (sku: string) => Promise; getStorefront: getStorefront; } /** * Sync state with Appstore (iOS only) * https://developer.apple.com/documentation/storekit/appstore/3791906-sync */ export const sync = (): Promise => RNIapIosSk2.sync(); /** * */ export const isEligibleForIntroOffer = (groupID: string): Promise => RNIapIosSk2.isEligibleForIntroOffer(groupID); /** * */ export const subscriptionStatus = (sku: string): Promise => RNIapIosSk2.subscriptionStatus(sku); /** * */ export const currentEntitlement = (sku: string): Promise => RNIapIosSk2.currentEntitlement(sku); /** * */ export const latestTransaction = (sku: string): Promise => RNIapIosSk2.latestTransaction(sku); /** * */ export const beginRefundRequest = (sku: string): Promise => RNIapIosSk2.beginRefundRequest(sku); /** * */ export const showManageSubscriptions = (): Promise => RNIapIosSk2.showManageSubscriptions(); /** * */ export const finishTransaction = ( transactionIdentifier: string, ): Promise => RNIapIosSk2.finishTransaction(transactionIdentifier);