react-native-iap 12.1.0 → 12.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,8 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.validateReceiptIos = exports.presentCodeRedemptionSheetIOS = exports.getReceiptIOS = exports.getPromotedProductIOS = exports.getPendingPurchasesIOS = exports.clearTransactionIOS = exports.clearProductsIOS = exports.buyPromotedProductIOS = void 0;
7
7
 
8
+ var _reactNative = require("react-native");
9
+
8
10
  var _internal = require("../internal");
9
11
 
12
+ const {
13
+ RNIapIos
14
+ } = _reactNative.NativeModules;
15
+
10
16
  /**
11
17
  * Get the current receipt base64 encoded in IOS.
12
18
  * @param {forceRefresh?:boolean}
@@ -26,7 +32,12 @@ const getReceiptIOS = async _ref => {
26
32
  let {
27
33
  forceRefresh
28
34
  } = _ref;
29
- return (0, _internal.getIosModule)().requestReceipt(forceRefresh ?? false);
35
+
36
+ if (!(0, _internal.isIosStorekit2)()) {
37
+ return RNIapIos.requestReceipt(forceRefresh ?? false);
38
+ } else {
39
+ return Promise.reject('Only available on Sk1');
40
+ }
30
41
  };
31
42
  /**
32
43
  * Launches a modal to register the redeem offer code in IOS.
@@ -48,7 +59,7 @@ exports.presentCodeRedemptionSheetIOS = presentCodeRedemptionSheetIOS;
48
59
 
49
60
  const getPromotedProductIOS = () => {
50
61
  if (!(0, _internal.isIosStorekit2)()) {
51
- return (0, _internal.getIosModule)().promotedProduct();
62
+ return RNIapIos.promotedProduct();
52
63
  } else {
53
64
  return Promise.reject('Only available on Sk1');
54
65
  }
@@ -1 +1 @@
1
- {"version":3,"names":["getPendingPurchasesIOS","getIosModule","getPendingTransactions","getReceiptIOS","forceRefresh","requestReceipt","presentCodeRedemptionSheetIOS","presentCodeRedemptionSheet","getPromotedProductIOS","isIosStorekit2","promotedProduct","Promise","reject","buyPromotedProductIOS","buyPromotedProduct","fetchJsonOrThrow","url","receiptBody","response","fetch","method","headers","Accept","body","JSON","stringify","ok","Object","assign","Error","statusText","statusCode","status","json","TEST_RECEIPT","requestAgnosticReceiptValidationIos","testResponse","validateReceiptIos","isTest","clearTransactionIOS","clearTransaction","clearProductsIOS","clearProducts"],"sources":["ios.ts"],"sourcesContent":["import type {ResponseBody as ReceiptValidationResponse} from '@jeremybarbet/apple-api-types';\n\nimport {getIosModule, isIosStorekit2} from '../internal';\nimport type {\n ProductIOS,\n ProductPurchase,\n Purchase,\n Sku,\n SubscriptionIOS,\n} from '../types';\nimport type {PaymentDiscount} from '../types/apple';\n\nimport type {NativeModuleProps} from './common';\n\ntype getItems = (skus: Sku[]) => Promise<ProductIOS[] | SubscriptionIOS[]>;\n\ntype getAvailableItems = (\n automaticallyFinishRestoredTransactions: boolean,\n) => Promise<Purchase[]>;\n\nexport type BuyProduct = (\n sku: Sku,\n andDangerouslyFinishTransactionAutomaticallyIOS: boolean,\n applicationUsername: string | undefined,\n quantity: number,\n withOffer: Record<keyof PaymentDiscount, string> | undefined,\n) => Promise<Purchase>;\n\ntype clearTransaction = () => Promise<void>;\ntype clearProducts = () => Promise<void>;\ntype promotedProduct = () => Promise<ProductIOS | null>;\ntype buyPromotedProduct = () => Promise<void>;\ntype requestReceipt = (refresh: boolean) => Promise<string>;\n\ntype finishTransaction = (transactionIdentifier: string) => Promise<boolean>;\n\ntype getPendingTransactions = () => Promise<ProductPurchase[]>;\ntype presentCodeRedemptionSheet = () => Promise<null>;\n\nexport interface IosModuleProps extends NativeModuleProps {\n getItems: getItems;\n getAvailableItems: getAvailableItems;\n buyProduct: BuyProduct;\n clearTransaction: clearTransaction;\n clearProducts: clearProducts;\n promotedProduct: promotedProduct;\n buyPromotedProduct: buyPromotedProduct;\n requestReceipt: requestReceipt;\n finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n disable: () => Promise<null>;\n}\n\n/**\n * Get the current receipt base64 encoded in IOS.\n * @param {forceRefresh?:boolean}\n * @returns {Promise<ProductPurchase[]>}\n */\nexport const getPendingPurchasesIOS = async (): Promise<ProductPurchase[]> =>\n getIosModule().getPendingTransactions();\n\n/**\n * Get the current receipt base64 encoded in IOS.\n * @param {forceRefresh?:boolean}\n * @returns {Promise<string>}\n */\nexport const getReceiptIOS = async ({\n forceRefresh,\n}: {\n forceRefresh?: boolean;\n}): Promise<string> => getIosModule().requestReceipt(forceRefresh ?? false);\n\n/**\n * Launches a modal to register the redeem offer code in IOS.\n * @returns {Promise<null>}\n */\nexport const presentCodeRedemptionSheetIOS = async (): Promise<null> =>\n getIosModule().presentCodeRedemptionSheet();\n\n/**\n * Should Add Store Payment (iOS only)\n * Indicates the the App Store purchase should continue from the app instead of the App Store.\n * @returns {Promise<Product | null>} promoted product\n */\nexport const getPromotedProductIOS = (): Promise<ProductIOS | null> => {\n if (!isIosStorekit2()) {\n return getIosModule().promotedProduct();\n } else {\n return Promise.reject('Only available on Sk1');\n }\n};\n\n/**\n * Buy the currently selected promoted product (iOS only)\n * Initiates the payment process for a promoted product. Should only be called in response to the `iap-promoted-product` event.\n * @returns {Promise<void>}\n */\nexport const buyPromotedProductIOS = (): Promise<void> =>\n getIosModule().buyPromotedProduct();\n\nconst fetchJsonOrThrow = async (\n url: string,\n receiptBody: Record<string, unknown>,\n): Promise<ReceiptValidationResponse | false> => {\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(receiptBody),\n });\n\n if (!response.ok) {\n throw Object.assign(new Error(response.statusText), {\n statusCode: response.status,\n });\n }\n\n return response.json();\n};\n\nconst TEST_RECEIPT = 21007;\nconst requestAgnosticReceiptValidationIos = async (\n receiptBody: Record<string, unknown>,\n): Promise<ReceiptValidationResponse | false> => {\n const response = await fetchJsonOrThrow(\n 'https://buy.itunes.apple.com/verifyReceipt',\n receiptBody,\n );\n\n // Best practice is to check for test receipt and check sandbox instead\n // https://developer.apple.com/documentation/appstorereceipts/verifyreceipt\n if (response && response.status === TEST_RECEIPT) {\n const testResponse = await fetchJsonOrThrow(\n 'https://sandbox.itunes.apple.com/verifyReceipt',\n receiptBody,\n );\n\n return testResponse;\n }\n\n return response;\n};\n\n/**\n * Validate receipt for iOS.\n * @param {object} receiptBody the receipt body to send to apple server.\n * @param {boolean} isTest whether this is in test environment which is sandbox.\n * @returns {Promise<Apple.ReceiptValidationResponse | false>}\n */\nexport const validateReceiptIos = async ({\n receiptBody,\n isTest,\n}: {\n receiptBody: Record<string, unknown>;\n isTest?: boolean;\n}): Promise<ReceiptValidationResponse | false> => {\n if (isTest == null) {\n return await requestAgnosticReceiptValidationIos(receiptBody);\n }\n\n const url = isTest\n ? 'https://sandbox.itunes.apple.com/verifyReceipt'\n : 'https://buy.itunes.apple.com/verifyReceipt';\n\n const response = await fetchJsonOrThrow(url, receiptBody);\n\n return response;\n};\n\n/**\n * Clear Transaction (iOS only)\n * Finish remaining transactions. Related to issue #257 and #801\n * link : https://github.com/dooboolab/react-native-iap/issues/257\n * https://github.com/dooboolab/react-native-iap/issues/801\n * @returns {Promise<void>}\n */\nexport const clearTransactionIOS = (): Promise<void> =>\n getIosModule().clearTransaction();\n\n/**\n * Clear valid Products (iOS only)\n * Remove all products which are validated by Apple server.\n * @returns {void}\n */\nexport const clearProductsIOS = (): Promise<void> =>\n getIosModule().clearProducts();\n"],"mappings":";;;;;;;AAEA;;AAoDA;AACA;AACA;AACA;AACA;AACO,MAAMA,sBAAsB,GAAG,YACpC,IAAAC,sBAAA,IAAeC,sBAAf,EADK;AAGP;AACA;AACA;AACA;AACA;;;;;AACO,MAAMC,aAAa,GAAG;EAAA,IAAO;IAClCC;EADkC,CAAP;EAAA,OAIN,IAAAH,sBAAA,IAAeI,cAAf,CAA8BD,YAAY,IAAI,KAA9C,CAJM;AAAA,CAAtB;AAMP;AACA;AACA;AACA;;;;;AACO,MAAME,6BAA6B,GAAG,YAC3C,IAAAL,sBAAA,IAAeM,0BAAf,E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;;EAED,OAAOlB,QAAP;AACD,CApBD;AAsBA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMmB,kBAAkB,GAAG,eAMgB;EAAA,IANT;IACvCpB,WADuC;IAEvCqB;EAFuC,CAMS;;EAChD,IAAIA,MAAM,IAAI,IAAd,EAAoB;IAClB,OAAO,MAAMH,mCAAmC,CAAClB,WAAD,CAAhD;EACD;;EAED,MAAMD,GAAG,GAAGsB,MAAM,GACd,gDADc,GAEd,4CAFJ;EAIA,MAAMpB,QAAQ,GAAG,MAAMH,gBAAgB,CAACC,GAAD,EAAMC,WAAN,CAAvC;EAEA,OAAOC,QAAP;AACD,CAlBM;AAoBP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMqB,mBAAmB,GAAG,MACjC,IAAAtC,sBAAA,IAAeuC,gBAAf,EADK;AAGP;AACA;AACA;AACA;AACA;;;;;AACO,MAAMC,gBAAgB,GAAG,MAC9B,IAAAxC,sBAAA,IAAeyC,aAAf,EADK"}
1
+ {"version":3,"names":["RNIapIos","NativeModules","getPendingPurchasesIOS","getIosModule","getPendingTransactions","getReceiptIOS","forceRefresh","isIosStorekit2","requestReceipt","Promise","reject","presentCodeRedemptionSheetIOS","presentCodeRedemptionSheet","getPromotedProductIOS","promotedProduct","buyPromotedProductIOS","buyPromotedProduct","fetchJsonOrThrow","url","receiptBody","response","fetch","method","headers","Accept","body","JSON","stringify","ok","Object","assign","Error","statusText","statusCode","status","json","TEST_RECEIPT","requestAgnosticReceiptValidationIos","testResponse","validateReceiptIos","isTest","clearTransactionIOS","clearTransaction","clearProductsIOS","clearProducts"],"sources":["ios.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\nimport type {ResponseBody as ReceiptValidationResponse} from '@jeremybarbet/apple-api-types';\n\nimport {getIosModule, isIosStorekit2} from '../internal';\nconst {RNIapIos} = NativeModules;\nimport type {\n ProductIOS,\n ProductPurchase,\n Purchase,\n Sku,\n SubscriptionIOS,\n} from '../types';\nimport type {PaymentDiscount} from '../types/apple';\n\nimport type {NativeModuleProps} from './common';\n\ntype getItems = (skus: Sku[]) => Promise<ProductIOS[] | SubscriptionIOS[]>;\n\ntype getAvailableItems = (\n automaticallyFinishRestoredTransactions: boolean,\n) => Promise<Purchase[]>;\n\nexport type BuyProduct = (\n sku: Sku,\n andDangerouslyFinishTransactionAutomaticallyIOS: boolean,\n applicationUsername: string | undefined,\n quantity: number,\n withOffer: Record<keyof PaymentDiscount, string> | undefined,\n) => Promise<Purchase>;\n\ntype clearTransaction = () => Promise<void>;\ntype clearProducts = () => Promise<void>;\ntype promotedProduct = () => Promise<ProductIOS | null>;\ntype buyPromotedProduct = () => Promise<void>;\ntype requestReceipt = (refresh: boolean) => Promise<string>;\n\ntype finishTransaction = (transactionIdentifier: string) => Promise<boolean>;\n\ntype getPendingTransactions = () => Promise<ProductPurchase[]>;\ntype presentCodeRedemptionSheet = () => Promise<null>;\n\nexport interface IosModuleProps extends NativeModuleProps {\n getItems: getItems;\n getAvailableItems: getAvailableItems;\n buyProduct: BuyProduct;\n clearTransaction: clearTransaction;\n clearProducts: clearProducts;\n promotedProduct: promotedProduct;\n buyPromotedProduct: buyPromotedProduct;\n requestReceipt: requestReceipt;\n finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n disable: () => Promise<null>;\n}\n\n/**\n * Get the current receipt base64 encoded in IOS.\n * @param {forceRefresh?:boolean}\n * @returns {Promise<ProductPurchase[]>}\n */\nexport const getPendingPurchasesIOS = async (): Promise<ProductPurchase[]> =>\n getIosModule().getPendingTransactions();\n\n/**\n * Get the current receipt base64 encoded in IOS.\n * @param {forceRefresh?:boolean}\n * @returns {Promise<string>}\n */\nexport const getReceiptIOS = async ({\n forceRefresh,\n}: {\n forceRefresh?: boolean;\n}): Promise<string> => {\n if (!isIosStorekit2()) {\n return RNIapIos.requestReceipt(forceRefresh ?? false);\n } else {\n return Promise.reject('Only available on Sk1');\n }\n};\n/**\n * Launches a modal to register the redeem offer code in IOS.\n * @returns {Promise<null>}\n */\nexport const presentCodeRedemptionSheetIOS = async (): Promise<null> =>\n getIosModule().presentCodeRedemptionSheet();\n\n/**\n * Should Add Store Payment (iOS only)\n * Indicates the the App Store purchase should continue from the app instead of the App Store.\n * @returns {Promise<Product | null>} promoted product\n */\nexport const getPromotedProductIOS = (): Promise<ProductIOS | null> => {\n if (!isIosStorekit2()) {\n return RNIapIos.promotedProduct();\n } else {\n return Promise.reject('Only available on Sk1');\n }\n};\n\n/**\n * Buy the currently selected promoted product (iOS only)\n * Initiates the payment process for a promoted product. Should only be called in response to the `iap-promoted-product` event.\n * @returns {Promise<void>}\n */\nexport const buyPromotedProductIOS = (): Promise<void> =>\n getIosModule().buyPromotedProduct();\n\nconst fetchJsonOrThrow = async (\n url: string,\n receiptBody: Record<string, unknown>,\n): Promise<ReceiptValidationResponse | false> => {\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(receiptBody),\n });\n\n if (!response.ok) {\n throw Object.assign(new Error(response.statusText), {\n statusCode: response.status,\n });\n }\n\n return response.json();\n};\n\nconst TEST_RECEIPT = 21007;\nconst requestAgnosticReceiptValidationIos = async (\n receiptBody: Record<string, unknown>,\n): Promise<ReceiptValidationResponse | false> => {\n const response = await fetchJsonOrThrow(\n 'https://buy.itunes.apple.com/verifyReceipt',\n receiptBody,\n );\n\n // Best practice is to check for test receipt and check sandbox instead\n // https://developer.apple.com/documentation/appstorereceipts/verifyreceipt\n if (response && response.status === TEST_RECEIPT) {\n const testResponse = await fetchJsonOrThrow(\n 'https://sandbox.itunes.apple.com/verifyReceipt',\n receiptBody,\n );\n\n return testResponse;\n }\n\n return response;\n};\n\n/**\n * Validate receipt for iOS.\n * @param {object} receiptBody the receipt body to send to apple server.\n * @param {boolean} isTest whether this is in test environment which is sandbox.\n * @returns {Promise<Apple.ReceiptValidationResponse | false>}\n */\nexport const validateReceiptIos = async ({\n receiptBody,\n isTest,\n}: {\n receiptBody: Record<string, unknown>;\n isTest?: boolean;\n}): Promise<ReceiptValidationResponse | false> => {\n if (isTest == null) {\n return await requestAgnosticReceiptValidationIos(receiptBody);\n }\n\n const url = isTest\n ? 'https://sandbox.itunes.apple.com/verifyReceipt'\n : 'https://buy.itunes.apple.com/verifyReceipt';\n\n const response = await fetchJsonOrThrow(url, receiptBody);\n\n return response;\n};\n\n/**\n * Clear Transaction (iOS only)\n * Finish remaining transactions. Related to issue #257 and #801\n * link : https://github.com/dooboolab/react-native-iap/issues/257\n * https://github.com/dooboolab/react-native-iap/issues/801\n * @returns {Promise<void>}\n */\nexport const clearTransactionIOS = (): Promise<void> =>\n getIosModule().clearTransaction();\n\n/**\n * Clear valid Products (iOS only)\n * Remove all products which are validated by Apple server.\n * @returns {void}\n */\nexport const clearProductsIOS = (): Promise<void> =>\n getIosModule().clearProducts();\n"],"mappings":";;;;;;;AAAA;;AAGA;;AACA,MAAM;EAACA;AAAD,IAAaC,0BAAnB;;AAoDA;AACA;AACA;AACA;AACA;AACO,MAAMC,sBAAsB,GAAG,YACpC,IAAAC,sBAAA,IAAeC,sBAAf,EADK;AAGP;AACA;AACA;AACA;AACA;;;;;AACO,MAAMC,aAAa,GAAG,cAIN;EAAA,IAJa;IAClCC;EADkC,CAIb;;EACrB,IAAI,CAAC,IAAAC,wBAAA,GAAL,EAAuB;IACrB,OAAOP,QAAQ,CAACQ,cAAT,CAAwBF,YAAY,IAAI,KAAxC,CAAP;EACD,CAFD,MAEO;IACL,OAAOG,OAAO,CAACC,MAAR,CAAe,uBAAf,CAAP;EACD;AACF,CAVM;AAWP;AACA;AACA;AACA;;;;;AACO,MAAMC,6BAA6B,GAAG,YAC3C,IAAAR,sBAAA,IAAeS,0BAAf,EADK;AAGP;AACA;AACA;AACA;AACA;;;;;AACO,MAAMC,qBAAqB,GAAG,MAAkC;EACrE,IAAI,CAAC,IAAAN,wBAAA,GAAL,EAAuB;IACrB,O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AEvCqB;EAFuC,CAMS;;EAChD,IAAIA,MAAM,IAAI,IAAd,EAAoB;IAClB,OAAO,MAAMH,mCAAmC,CAAClB,WAAD,CAAhD;EACD;;EAED,MAAMD,GAAG,GAAGsB,MAAM,GACd,gDADc,GAEd,4CAFJ;EAIA,MAAMpB,QAAQ,GAAG,MAAMH,gBAAgB,CAACC,GAAD,EAAMC,WAAN,CAAvC;EAEA,OAAOC,QAAP;AACD,CAlBM;AAoBP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMqB,mBAAmB,GAAG,MACjC,IAAAtC,sBAAA,IAAeuC,gBAAf,EADK;AAGP;AACA;AACA;AACA;AACA;;;;;AACO,MAAMC,gBAAgB,GAAG,MAC9B,IAAAxC,sBAAA,IAAeyC,aAAf,EADK"}
@@ -1 +1 @@
1
- {"version":3,"names":["RNIapIosSk2","NativeModules","sync","isEligibleForIntroOffer","groupID","subscriptionStatus","sku","currentEntitlement","latestTransaction"],"sources":["iosSk2.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport type {Product, ProductPurchase, Purchase, Sku} from '../types';\nimport type {\n PaymentDiscountSk2,\n ProductSk2,\n ProductStatus,\n TransactionSk2,\n} from '../types/appleSk2';\n\nimport type {NativeModuleProps} from './common';\nconst {RNIapIosSk2} = NativeModules;\n\ntype getItems = (skus: Sku[]) => Promise<ProductSk2[]>;\n\ntype getAvailableItems = (\n alsoPublishToEventListener?: boolean,\n) => Promise<TransactionSk2[]>;\n\nexport type BuyProduct = (\n sku: Sku,\n andDangerouslyFinishTransactionAutomaticallyIOS: boolean,\n applicationUsername: string | undefined,\n quantity: number,\n withOffer: Record<keyof PaymentDiscountSk2, string> | undefined,\n) => Promise<Purchase>;\n\ntype clearTransaction = () => Promise<void>;\ntype clearProducts = () => Promise<void>;\ntype promotedProduct = () => Promise<Product | null>;\ntype buyPromotedProduct = () => Promise<void>;\ntype requestReceipt = (refresh: boolean) => Promise<string>;\n\ntype finishTransaction = (transactionIdentifier: string) => Promise<boolean>;\n\ntype getPendingTransactions = () => Promise<ProductPurchase[]>;\ntype presentCodeRedemptionSheet = () => Promise<null>;\n\nexport interface IosModulePropsSk2 extends NativeModuleProps {\n isAvailable(): number;\n latestTransaction(sku: string): Promise<TransactionSk2>;\n currentEntitlement(sku: string): Promise<TransactionSk2>;\n subscriptionStatus(sku: string): Promise<ProductStatus[]>;\n isEligibleForIntroOffer(groupID: string): Promise<Boolean>;\n sync(): Promise<null>;\n getItems: getItems;\n getAvailableItems: getAvailableItems;\n buyProduct: BuyProduct;\n clearTransaction: clearTransaction;\n clearProducts: clearProducts;\n promotedProduct: promotedProduct;\n buyPromotedProduct: buyPromotedProduct;\n requestReceipt: requestReceipt;\n finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n disable: () => Promise<null>;\n}\n\n/**\n * Sync state with Appstore (iOS only)\n * https://developer.apple.com/documentation/storekit/appstore/3791906-sync\n */\nexport const sync = (): Promise<null> => RNIapIosSk2.sync();\n\n/**\n *\n */\nexport const isEligibleForIntroOffer = (groupID: string): Promise<Boolean> =>\n RNIapIosSk2.isEligibleForIntroOffer(groupID);\n\n/**\n *\n */\n\nexport const subscriptionStatus = (sku: string): Promise<ProductStatus[]> =>\n RNIapIosSk2.subscriptionStatus(sku);\n\n/**\n *\n */\nexport const currentEntitlement = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.currentEntitlement(sku);\n\n/**\n *\n */\nexport const latestTransaction = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.latestTransaction(sku);\n"],"mappings":";;;;;;;AAAA;;AAWA,MAAM;EAACA;AAAD,IAAgBC,0BAAtB;;AAgDA;AACA;AACA;AACA;AACO,MAAMC,IAAI,GAAG,MAAqBF,WAAW,CAACE,IAAZ,EAAlC;AAEP;AACA;AACA;;;;;AACO,MAAMC,uBAAuB,GAAIC,OAAD,IACrCJ,WAAW,CAACG,uBAAZ,CAAoCC,OAApC,CADK;AAGP;AACA;AACA;;;;;AAEO,MAAMC,kBAAkB,GAAIC,GAAD,IAChCN,WAAW,CAACK,kBAAZ,CAA+BC,GAA/B,CADK;AAGP;AACA;AACA;;;;;AACO,MAAMC,kBAAkB,GAAID,GAAD,IAChCN,WAAW,CAACO,kBAAZ,CAA+BD,GAA/B,CADK;AAGP;AACA;AACA;;;;;AACO,MAAME,iBAAiB,GAAIF,GAAD,IAC/BN,WAAW,CAACQ,iBAAZ,CAA8BF,GAA9B,CADK"}
1
+ {"version":3,"names":["RNIapIosSk2","NativeModules","sync","isEligibleForIntroOffer","groupID","subscriptionStatus","sku","currentEntitlement","latestTransaction"],"sources":["iosSk2.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport type {Product, ProductPurchase, Purchase, Sku} from '../types';\nimport type {\n PaymentDiscountSk2,\n ProductSk2,\n ProductStatus,\n TransactionSk2,\n} from '../types/appleSk2';\n\nimport type {NativeModuleProps} from './common';\nconst {RNIapIosSk2} = NativeModules;\n\ntype getItems = (skus: Sku[]) => Promise<ProductSk2[]>;\n\ntype getAvailableItems = (\n alsoPublishToEventListener?: boolean,\n) => Promise<TransactionSk2[]>;\n\nexport type BuyProduct = (\n sku: Sku,\n andDangerouslyFinishTransactionAutomaticallyIOS: boolean,\n applicationUsername: string | undefined,\n quantity: number,\n withOffer: Record<keyof PaymentDiscountSk2, string> | undefined,\n) => Promise<Purchase>;\n\ntype clearTransaction = () => Promise<void>;\ntype clearProducts = () => Promise<void>;\ntype promotedProduct = () => Promise<Product | null>;\ntype buyPromotedProduct = () => Promise<void>;\n\ntype finishTransaction = (transactionIdentifier: string) => Promise<boolean>;\n\ntype getPendingTransactions = () => Promise<ProductPurchase[]>;\ntype presentCodeRedemptionSheet = () => Promise<null>;\n\nexport interface IosModulePropsSk2 extends NativeModuleProps {\n isAvailable(): number;\n latestTransaction(sku: string): Promise<TransactionSk2>;\n currentEntitlement(sku: string): Promise<TransactionSk2>;\n subscriptionStatus(sku: string): Promise<ProductStatus[]>;\n isEligibleForIntroOffer(groupID: string): Promise<Boolean>;\n sync(): Promise<null>;\n getItems: getItems;\n getAvailableItems: getAvailableItems;\n buyProduct: BuyProduct;\n clearTransaction: clearTransaction;\n clearProducts: clearProducts;\n promotedProduct: promotedProduct;\n buyPromotedProduct: buyPromotedProduct;\n finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n disable: () => Promise<null>;\n}\n\n/**\n * Sync state with Appstore (iOS only)\n * https://developer.apple.com/documentation/storekit/appstore/3791906-sync\n */\nexport const sync = (): Promise<null> => RNIapIosSk2.sync();\n\n/**\n *\n */\nexport const isEligibleForIntroOffer = (groupID: string): Promise<Boolean> =>\n RNIapIosSk2.isEligibleForIntroOffer(groupID);\n\n/**\n *\n */\n\nexport const subscriptionStatus = (sku: string): Promise<ProductStatus[]> =>\n RNIapIosSk2.subscriptionStatus(sku);\n\n/**\n *\n */\nexport const currentEntitlement = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.currentEntitlement(sku);\n\n/**\n *\n */\nexport const latestTransaction = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.latestTransaction(sku);\n"],"mappings":";;;;;;;AAAA;;AAWA,MAAM;EAACA;AAAD,IAAgBC,0BAAtB;;AA8CA;AACA;AACA;AACA;AACO,MAAMC,IAAI,GAAG,MAAqBF,WAAW,CAACE,IAAZ,EAAlC;AAEP;AACA;AACA;;;;;AACO,MAAMC,uBAAuB,GAAIC,OAAD,IACrCJ,WAAW,CAACG,uBAAZ,CAAoCC,OAApC,CADK;AAGP;AACA;AACA;;;;;AAEO,MAAMC,kBAAkB,GAAIC,GAAD,IAChCN,WAAW,CAACK,kBAAZ,CAA+BC,GAA/B,CADK;AAGP;AACA;AACA;;;;;AACO,MAAMC,kBAAkB,GAAID,GAAD,IAChCN,WAAW,CAACO,kBAAZ,CAA+BD,GAA/B,CADK;AAGP;AACA;AACA;;;;;AACO,MAAME,iBAAiB,GAAIF,GAAD,IAC/BN,WAAW,CAACQ,iBAAZ,CAA8BF,GAA9B,CADK"}
@@ -1,4 +1,8 @@
1
+ import { NativeModules } from 'react-native';
1
2
  import { getIosModule, isIosStorekit2 } from '../internal';
3
+ const {
4
+ RNIapIos
5
+ } = NativeModules;
2
6
 
3
7
  /**
4
8
  * Get the current receipt base64 encoded in IOS.
@@ -16,7 +20,12 @@ export const getReceiptIOS = async _ref => {
16
20
  let {
17
21
  forceRefresh
18
22
  } = _ref;
19
- return getIosModule().requestReceipt(forceRefresh ?? false);
23
+
24
+ if (!isIosStorekit2()) {
25
+ return RNIapIos.requestReceipt(forceRefresh ?? false);
26
+ } else {
27
+ return Promise.reject('Only available on Sk1');
28
+ }
20
29
  };
21
30
  /**
22
31
  * Launches a modal to register the redeem offer code in IOS.
@@ -32,7 +41,7 @@ export const presentCodeRedemptionSheetIOS = async () => getIosModule().presentC
32
41
 
33
42
  export const getPromotedProductIOS = () => {
34
43
  if (!isIosStorekit2()) {
35
- return getIosModule().promotedProduct();
44
+ return RNIapIos.promotedProduct();
36
45
  } else {
37
46
  return Promise.reject('Only available on Sk1');
38
47
  }
@@ -1 +1 @@
1
- {"version":3,"names":["getIosModule","isIosStorekit2","getPendingPurchasesIOS","getPendingTransactions","getReceiptIOS","forceRefresh","requestReceipt","presentCodeRedemptionSheetIOS","presentCodeRedemptionSheet","getPromotedProductIOS","promotedProduct","Promise","reject","buyPromotedProductIOS","buyPromotedProduct","fetchJsonOrThrow","url","receiptBody","response","fetch","method","headers","Accept","body","JSON","stringify","ok","Object","assign","Error","statusText","statusCode","status","json","TEST_RECEIPT","requestAgnosticReceiptValidationIos","testResponse","validateReceiptIos","isTest","clearTransactionIOS","clearTransaction","clearProductsIOS","clearProducts"],"sources":["ios.ts"],"sourcesContent":["import type {ResponseBody as ReceiptValidationResponse} from '@jeremybarbet/apple-api-types';\n\nimport {getIosModule, isIosStorekit2} from '../internal';\nimport type {\n ProductIOS,\n ProductPurchase,\n Purchase,\n Sku,\n SubscriptionIOS,\n} from '../types';\nimport type {PaymentDiscount} from '../types/apple';\n\nimport type {NativeModuleProps} from './common';\n\ntype getItems = (skus: Sku[]) => Promise<ProductIOS[] | SubscriptionIOS[]>;\n\ntype getAvailableItems = (\n automaticallyFinishRestoredTransactions: boolean,\n) => Promise<Purchase[]>;\n\nexport type BuyProduct = (\n sku: Sku,\n andDangerouslyFinishTransactionAutomaticallyIOS: boolean,\n applicationUsername: string | undefined,\n quantity: number,\n withOffer: Record<keyof PaymentDiscount, string> | undefined,\n) => Promise<Purchase>;\n\ntype clearTransaction = () => Promise<void>;\ntype clearProducts = () => Promise<void>;\ntype promotedProduct = () => Promise<ProductIOS | null>;\ntype buyPromotedProduct = () => Promise<void>;\ntype requestReceipt = (refresh: boolean) => Promise<string>;\n\ntype finishTransaction = (transactionIdentifier: string) => Promise<boolean>;\n\ntype getPendingTransactions = () => Promise<ProductPurchase[]>;\ntype presentCodeRedemptionSheet = () => Promise<null>;\n\nexport interface IosModuleProps extends NativeModuleProps {\n getItems: getItems;\n getAvailableItems: getAvailableItems;\n buyProduct: BuyProduct;\n clearTransaction: clearTransaction;\n clearProducts: clearProducts;\n promotedProduct: promotedProduct;\n buyPromotedProduct: buyPromotedProduct;\n requestReceipt: requestReceipt;\n finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n disable: () => Promise<null>;\n}\n\n/**\n * Get the current receipt base64 encoded in IOS.\n * @param {forceRefresh?:boolean}\n * @returns {Promise<ProductPurchase[]>}\n */\nexport const getPendingPurchasesIOS = async (): Promise<ProductPurchase[]> =>\n getIosModule().getPendingTransactions();\n\n/**\n * Get the current receipt base64 encoded in IOS.\n * @param {forceRefresh?:boolean}\n * @returns {Promise<string>}\n */\nexport const getReceiptIOS = async ({\n forceRefresh,\n}: {\n forceRefresh?: boolean;\n}): Promise<string> => getIosModule().requestReceipt(forceRefresh ?? false);\n\n/**\n * Launches a modal to register the redeem offer code in IOS.\n * @returns {Promise<null>}\n */\nexport const presentCodeRedemptionSheetIOS = async (): Promise<null> =>\n getIosModule().presentCodeRedemptionSheet();\n\n/**\n * Should Add Store Payment (iOS only)\n * Indicates the the App Store purchase should continue from the app instead of the App Store.\n * @returns {Promise<Product | null>} promoted product\n */\nexport const getPromotedProductIOS = (): Promise<ProductIOS | null> => {\n if (!isIosStorekit2()) {\n return getIosModule().promotedProduct();\n } else {\n return Promise.reject('Only available on Sk1');\n }\n};\n\n/**\n * Buy the currently selected promoted product (iOS only)\n * Initiates the payment process for a promoted product. Should only be called in response to the `iap-promoted-product` event.\n * @returns {Promise<void>}\n */\nexport const buyPromotedProductIOS = (): Promise<void> =>\n getIosModule().buyPromotedProduct();\n\nconst fetchJsonOrThrow = async (\n url: string,\n receiptBody: Record<string, unknown>,\n): Promise<ReceiptValidationResponse | false> => {\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(receiptBody),\n });\n\n if (!response.ok) {\n throw Object.assign(new Error(response.statusText), {\n statusCode: response.status,\n });\n }\n\n return response.json();\n};\n\nconst TEST_RECEIPT = 21007;\nconst requestAgnosticReceiptValidationIos = async (\n receiptBody: Record<string, unknown>,\n): Promise<ReceiptValidationResponse | false> => {\n const response = await fetchJsonOrThrow(\n 'https://buy.itunes.apple.com/verifyReceipt',\n receiptBody,\n );\n\n // Best practice is to check for test receipt and check sandbox instead\n // https://developer.apple.com/documentation/appstorereceipts/verifyreceipt\n if (response && response.status === TEST_RECEIPT) {\n const testResponse = await fetchJsonOrThrow(\n 'https://sandbox.itunes.apple.com/verifyReceipt',\n receiptBody,\n );\n\n return testResponse;\n }\n\n return response;\n};\n\n/**\n * Validate receipt for iOS.\n * @param {object} receiptBody the receipt body to send to apple server.\n * @param {boolean} isTest whether this is in test environment which is sandbox.\n * @returns {Promise<Apple.ReceiptValidationResponse | false>}\n */\nexport const validateReceiptIos = async ({\n receiptBody,\n isTest,\n}: {\n receiptBody: Record<string, unknown>;\n isTest?: boolean;\n}): Promise<ReceiptValidationResponse | false> => {\n if (isTest == null) {\n return await requestAgnosticReceiptValidationIos(receiptBody);\n }\n\n const url = isTest\n ? 'https://sandbox.itunes.apple.com/verifyReceipt'\n : 'https://buy.itunes.apple.com/verifyReceipt';\n\n const response = await fetchJsonOrThrow(url, receiptBody);\n\n return response;\n};\n\n/**\n * Clear Transaction (iOS only)\n * Finish remaining transactions. Related to issue #257 and #801\n * link : https://github.com/dooboolab/react-native-iap/issues/257\n * https://github.com/dooboolab/react-native-iap/issues/801\n * @returns {Promise<void>}\n */\nexport const clearTransactionIOS = (): Promise<void> =>\n getIosModule().clearTransaction();\n\n/**\n * Clear valid Products (iOS only)\n * Remove all products which are validated by Apple server.\n * @returns {void}\n */\nexport const clearProductsIOS = (): Promise<void> =>\n getIosModule().clearProducts();\n"],"mappings":"AAEA,SAAQA,YAAR,EAAsBC,cAAtB,QAA2C,aAA3C;;AAoDA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,sBAAsB,GAAG,YACpCF,YAAY,GAAGG,sBAAf,EADK;AAGP;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,aAAa,GAAG;EAAA,IAAO;IAClCC;EADkC,CAAP;EAAA,OAINL,YAAY,GAAGM,cAAf,CAA8BD,YAAY,IAAI,KAA9C,CAJM;AAAA,CAAtB;AAMP;AACA;AACA;AACA;;AACA,OAAO,MAAME,6BAA6B,GAAG,YAC3CP,YAAY,GAAGQ,0BAAf,EADK;AAGP;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,qBAAqB,GAAG,MAAkC;EACrE,IAAI,CAACR,cAAc,EAAnB,EAAuB;IACrB,OAAOD,YAAY,GAAGU,eAAf,EAAP;EACD,CAFD,MAEO;IACL,OAAOC,OAAO,CAACC,MAAR,CAAe,uBAAf,CAAP;EACD;AACF,CANM;AAQP;AACA;AACA;AACA;AACA;;AAC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MAAM,GACd,gDADc,GAEd,4CAFJ;EAIA,MAAMpB,QAAQ,GAAG,MAAMH,gBAAgB,CAACC,GAAD,EAAMC,WAAN,CAAvC;EAEA,OAAOC,QAAP;AACD,CAlBM;AAoBP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMqB,mBAAmB,GAAG,MACjCvC,YAAY,GAAGwC,gBAAf,EADK;AAGP;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,gBAAgB,GAAG,MAC9BzC,YAAY,GAAG0C,aAAf,EADK"}
1
+ {"version":3,"names":["NativeModules","getIosModule","isIosStorekit2","RNIapIos","getPendingPurchasesIOS","getPendingTransactions","getReceiptIOS","forceRefresh","requestReceipt","Promise","reject","presentCodeRedemptionSheetIOS","presentCodeRedemptionSheet","getPromotedProductIOS","promotedProduct","buyPromotedProductIOS","buyPromotedProduct","fetchJsonOrThrow","url","receiptBody","response","fetch","method","headers","Accept","body","JSON","stringify","ok","Object","assign","Error","statusText","statusCode","status","json","TEST_RECEIPT","requestAgnosticReceiptValidationIos","testResponse","validateReceiptIos","isTest","clearTransactionIOS","clearTransaction","clearProductsIOS","clearProducts"],"sources":["ios.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\nimport type {ResponseBody as ReceiptValidationResponse} from '@jeremybarbet/apple-api-types';\n\nimport {getIosModule, isIosStorekit2} from '../internal';\nconst {RNIapIos} = NativeModules;\nimport type {\n ProductIOS,\n ProductPurchase,\n Purchase,\n Sku,\n SubscriptionIOS,\n} from '../types';\nimport type {PaymentDiscount} from '../types/apple';\n\nimport type {NativeModuleProps} from './common';\n\ntype getItems = (skus: Sku[]) => Promise<ProductIOS[] | SubscriptionIOS[]>;\n\ntype getAvailableItems = (\n automaticallyFinishRestoredTransactions: boolean,\n) => Promise<Purchase[]>;\n\nexport type BuyProduct = (\n sku: Sku,\n andDangerouslyFinishTransactionAutomaticallyIOS: boolean,\n applicationUsername: string | undefined,\n quantity: number,\n withOffer: Record<keyof PaymentDiscount, string> | undefined,\n) => Promise<Purchase>;\n\ntype clearTransaction = () => Promise<void>;\ntype clearProducts = () => Promise<void>;\ntype promotedProduct = () => Promise<ProductIOS | null>;\ntype buyPromotedProduct = () => Promise<void>;\ntype requestReceipt = (refresh: boolean) => Promise<string>;\n\ntype finishTransaction = (transactionIdentifier: string) => Promise<boolean>;\n\ntype getPendingTransactions = () => Promise<ProductPurchase[]>;\ntype presentCodeRedemptionSheet = () => Promise<null>;\n\nexport interface IosModuleProps extends NativeModuleProps {\n getItems: getItems;\n getAvailableItems: getAvailableItems;\n buyProduct: BuyProduct;\n clearTransaction: clearTransaction;\n clearProducts: clearProducts;\n promotedProduct: promotedProduct;\n buyPromotedProduct: buyPromotedProduct;\n requestReceipt: requestReceipt;\n finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n disable: () => Promise<null>;\n}\n\n/**\n * Get the current receipt base64 encoded in IOS.\n * @param {forceRefresh?:boolean}\n * @returns {Promise<ProductPurchase[]>}\n */\nexport const getPendingPurchasesIOS = async (): Promise<ProductPurchase[]> =>\n getIosModule().getPendingTransactions();\n\n/**\n * Get the current receipt base64 encoded in IOS.\n * @param {forceRefresh?:boolean}\n * @returns {Promise<string>}\n */\nexport const getReceiptIOS = async ({\n forceRefresh,\n}: {\n forceRefresh?: boolean;\n}): Promise<string> => {\n if (!isIosStorekit2()) {\n return RNIapIos.requestReceipt(forceRefresh ?? false);\n } else {\n return Promise.reject('Only available on Sk1');\n }\n};\n/**\n * Launches a modal to register the redeem offer code in IOS.\n * @returns {Promise<null>}\n */\nexport const presentCodeRedemptionSheetIOS = async (): Promise<null> =>\n getIosModule().presentCodeRedemptionSheet();\n\n/**\n * Should Add Store Payment (iOS only)\n * Indicates the the App Store purchase should continue from the app instead of the App Store.\n * @returns {Promise<Product | null>} promoted product\n */\nexport const getPromotedProductIOS = (): Promise<ProductIOS | null> => {\n if (!isIosStorekit2()) {\n return RNIapIos.promotedProduct();\n } else {\n return Promise.reject('Only available on Sk1');\n }\n};\n\n/**\n * Buy the currently selected promoted product (iOS only)\n * Initiates the payment process for a promoted product. Should only be called in response to the `iap-promoted-product` event.\n * @returns {Promise<void>}\n */\nexport const buyPromotedProductIOS = (): Promise<void> =>\n getIosModule().buyPromotedProduct();\n\nconst fetchJsonOrThrow = async (\n url: string,\n receiptBody: Record<string, unknown>,\n): Promise<ReceiptValidationResponse | false> => {\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(receiptBody),\n });\n\n if (!response.ok) {\n throw Object.assign(new Error(response.statusText), {\n statusCode: response.status,\n });\n }\n\n return response.json();\n};\n\nconst TEST_RECEIPT = 21007;\nconst requestAgnosticReceiptValidationIos = async (\n receiptBody: Record<string, unknown>,\n): Promise<ReceiptValidationResponse | false> => {\n const response = await fetchJsonOrThrow(\n 'https://buy.itunes.apple.com/verifyReceipt',\n receiptBody,\n );\n\n // Best practice is to check for test receipt and check sandbox instead\n // https://developer.apple.com/documentation/appstorereceipts/verifyreceipt\n if (response && response.status === TEST_RECEIPT) {\n const testResponse = await fetchJsonOrThrow(\n 'https://sandbox.itunes.apple.com/verifyReceipt',\n receiptBody,\n );\n\n return testResponse;\n }\n\n return response;\n};\n\n/**\n * Validate receipt for iOS.\n * @param {object} receiptBody the receipt body to send to apple server.\n * @param {boolean} isTest whether this is in test environment which is sandbox.\n * @returns {Promise<Apple.ReceiptValidationResponse | false>}\n */\nexport const validateReceiptIos = async ({\n receiptBody,\n isTest,\n}: {\n receiptBody: Record<string, unknown>;\n isTest?: boolean;\n}): Promise<ReceiptValidationResponse | false> => {\n if (isTest == null) {\n return await requestAgnosticReceiptValidationIos(receiptBody);\n }\n\n const url = isTest\n ? 'https://sandbox.itunes.apple.com/verifyReceipt'\n : 'https://buy.itunes.apple.com/verifyReceipt';\n\n const response = await fetchJsonOrThrow(url, receiptBody);\n\n return response;\n};\n\n/**\n * Clear Transaction (iOS only)\n * Finish remaining transactions. Related to issue #257 and #801\n * link : https://github.com/dooboolab/react-native-iap/issues/257\n * https://github.com/dooboolab/react-native-iap/issues/801\n * @returns {Promise<void>}\n */\nexport const clearTransactionIOS = (): Promise<void> =>\n getIosModule().clearTransaction();\n\n/**\n * Clear valid Products (iOS only)\n * Remove all products which are validated by Apple server.\n * @returns {void}\n */\nexport const clearProductsIOS = (): Promise<void> =>\n getIosModule().clearProducts();\n"],"mappings":"AAAA,SAAQA,aAAR,QAA4B,cAA5B;AAGA,SAAQC,YAAR,EAAsBC,cAAtB,QAA2C,aAA3C;AACA,MAAM;EAACC;AAAD,IAAaH,aAAnB;;AAoDA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMI,sBAAsB,GAAG,YACpCH,YAAY,GAAGI,sBAAf,EADK;AAGP;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,aAAa,GAAG,cAIN;EAAA,IAJa;IAClCC;EADkC,CAIb;;EACrB,IAAI,CAACL,cAAc,EAAnB,EAAuB;IACrB,OAAOC,QAAQ,CAACK,cAAT,CAAwBD,YAAY,IAAI,KAAxC,CAAP;EACD,CAFD,MAEO;IACL,OAAOE,OAAO,CAACC,MAAR,CAAe,uBAAf,CAAP;EACD;AACF,CAVM;AAWP;AACA;AACA;AACA;;AACA,OAAO,MAAMC,6BAA6B,GAAG,YAC3CV,YAAY,GAAGW,0BAAf,EADK;AAGP;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,qBAAqB,GAAG,MAAkC;EACrE,IAAI,CAACX,cAAc,EAAnB,EAAuB;IACrB,OAAOC,QAAQ,CAACW,eAAT,EAAP;EACD,CAFD,MAEO;IACL,OAAOL,OAAO,CAACC,MAAR,CAAe,uBAAf,CAAP;EACD;AACF,CANM;AAQP;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMK,qBAAqB,GAAG,MACnCd,YAAY,GAAGe,kBAAf,EADK;;AAGP,MAAMC,gBAAgB,GAAG,OACv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AAN,CAAvC;EAEA,OAAOC,QAAP;AACD,CAlBM;AAoBP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMqB,mBAAmB,GAAG,MACjCxC,YAAY,GAAGyC,gBAAf,EADK;AAGP;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,gBAAgB,GAAG,MAC9B1C,YAAY,GAAG2C,aAAf,EADK"}
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","RNIapIosSk2","sync","isEligibleForIntroOffer","groupID","subscriptionStatus","sku","currentEntitlement","latestTransaction"],"sources":["iosSk2.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport type {Product, ProductPurchase, Purchase, Sku} from '../types';\nimport type {\n PaymentDiscountSk2,\n ProductSk2,\n ProductStatus,\n TransactionSk2,\n} from '../types/appleSk2';\n\nimport type {NativeModuleProps} from './common';\nconst {RNIapIosSk2} = NativeModules;\n\ntype getItems = (skus: Sku[]) => Promise<ProductSk2[]>;\n\ntype getAvailableItems = (\n alsoPublishToEventListener?: boolean,\n) => Promise<TransactionSk2[]>;\n\nexport type BuyProduct = (\n sku: Sku,\n andDangerouslyFinishTransactionAutomaticallyIOS: boolean,\n applicationUsername: string | undefined,\n quantity: number,\n withOffer: Record<keyof PaymentDiscountSk2, string> | undefined,\n) => Promise<Purchase>;\n\ntype clearTransaction = () => Promise<void>;\ntype clearProducts = () => Promise<void>;\ntype promotedProduct = () => Promise<Product | null>;\ntype buyPromotedProduct = () => Promise<void>;\ntype requestReceipt = (refresh: boolean) => Promise<string>;\n\ntype finishTransaction = (transactionIdentifier: string) => Promise<boolean>;\n\ntype getPendingTransactions = () => Promise<ProductPurchase[]>;\ntype presentCodeRedemptionSheet = () => Promise<null>;\n\nexport interface IosModulePropsSk2 extends NativeModuleProps {\n isAvailable(): number;\n latestTransaction(sku: string): Promise<TransactionSk2>;\n currentEntitlement(sku: string): Promise<TransactionSk2>;\n subscriptionStatus(sku: string): Promise<ProductStatus[]>;\n isEligibleForIntroOffer(groupID: string): Promise<Boolean>;\n sync(): Promise<null>;\n getItems: getItems;\n getAvailableItems: getAvailableItems;\n buyProduct: BuyProduct;\n clearTransaction: clearTransaction;\n clearProducts: clearProducts;\n promotedProduct: promotedProduct;\n buyPromotedProduct: buyPromotedProduct;\n requestReceipt: requestReceipt;\n finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n disable: () => Promise<null>;\n}\n\n/**\n * Sync state with Appstore (iOS only)\n * https://developer.apple.com/documentation/storekit/appstore/3791906-sync\n */\nexport const sync = (): Promise<null> => RNIapIosSk2.sync();\n\n/**\n *\n */\nexport const isEligibleForIntroOffer = (groupID: string): Promise<Boolean> =>\n RNIapIosSk2.isEligibleForIntroOffer(groupID);\n\n/**\n *\n */\n\nexport const subscriptionStatus = (sku: string): Promise<ProductStatus[]> =>\n RNIapIosSk2.subscriptionStatus(sku);\n\n/**\n *\n */\nexport const currentEntitlement = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.currentEntitlement(sku);\n\n/**\n *\n */\nexport const latestTransaction = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.latestTransaction(sku);\n"],"mappings":"AAAA,SAAQA,aAAR,QAA4B,cAA5B;AAWA,MAAM;EAACC;AAAD,IAAgBD,aAAtB;;AAgDA;AACA;AACA;AACA;AACA,OAAO,MAAME,IAAI,GAAG,MAAqBD,WAAW,CAACC,IAAZ,EAAlC;AAEP;AACA;AACA;;AACA,OAAO,MAAMC,uBAAuB,GAAIC,OAAD,IACrCH,WAAW,CAACE,uBAAZ,CAAoCC,OAApC,CADK;AAGP;AACA;AACA;;AAEA,OAAO,MAAMC,kBAAkB,GAAIC,GAAD,IAChCL,WAAW,CAACI,kBAAZ,CAA+BC,GAA/B,CADK;AAGP;AACA;AACA;;AACA,OAAO,MAAMC,kBAAkB,GAAID,GAAD,IAChCL,WAAW,CAACM,kBAAZ,CAA+BD,GAA/B,CADK;AAGP;AACA;AACA;;AACA,OAAO,MAAME,iBAAiB,GAAIF,GAAD,IAC/BL,WAAW,CAACO,iBAAZ,CAA8BF,GAA9B,CADK"}
1
+ {"version":3,"names":["NativeModules","RNIapIosSk2","sync","isEligibleForIntroOffer","groupID","subscriptionStatus","sku","currentEntitlement","latestTransaction"],"sources":["iosSk2.ts"],"sourcesContent":["import {NativeModules} from 'react-native';\n\nimport type {Product, ProductPurchase, Purchase, Sku} from '../types';\nimport type {\n PaymentDiscountSk2,\n ProductSk2,\n ProductStatus,\n TransactionSk2,\n} from '../types/appleSk2';\n\nimport type {NativeModuleProps} from './common';\nconst {RNIapIosSk2} = NativeModules;\n\ntype getItems = (skus: Sku[]) => Promise<ProductSk2[]>;\n\ntype getAvailableItems = (\n alsoPublishToEventListener?: boolean,\n) => Promise<TransactionSk2[]>;\n\nexport type BuyProduct = (\n sku: Sku,\n andDangerouslyFinishTransactionAutomaticallyIOS: boolean,\n applicationUsername: string | undefined,\n quantity: number,\n withOffer: Record<keyof PaymentDiscountSk2, string> | undefined,\n) => Promise<Purchase>;\n\ntype clearTransaction = () => Promise<void>;\ntype clearProducts = () => Promise<void>;\ntype promotedProduct = () => Promise<Product | null>;\ntype buyPromotedProduct = () => Promise<void>;\n\ntype finishTransaction = (transactionIdentifier: string) => Promise<boolean>;\n\ntype getPendingTransactions = () => Promise<ProductPurchase[]>;\ntype presentCodeRedemptionSheet = () => Promise<null>;\n\nexport interface IosModulePropsSk2 extends NativeModuleProps {\n isAvailable(): number;\n latestTransaction(sku: string): Promise<TransactionSk2>;\n currentEntitlement(sku: string): Promise<TransactionSk2>;\n subscriptionStatus(sku: string): Promise<ProductStatus[]>;\n isEligibleForIntroOffer(groupID: string): Promise<Boolean>;\n sync(): Promise<null>;\n getItems: getItems;\n getAvailableItems: getAvailableItems;\n buyProduct: BuyProduct;\n clearTransaction: clearTransaction;\n clearProducts: clearProducts;\n promotedProduct: promotedProduct;\n buyPromotedProduct: buyPromotedProduct;\n finishTransaction: finishTransaction;\n getPendingTransactions: getPendingTransactions;\n presentCodeRedemptionSheet: presentCodeRedemptionSheet;\n disable: () => Promise<null>;\n}\n\n/**\n * Sync state with Appstore (iOS only)\n * https://developer.apple.com/documentation/storekit/appstore/3791906-sync\n */\nexport const sync = (): Promise<null> => RNIapIosSk2.sync();\n\n/**\n *\n */\nexport const isEligibleForIntroOffer = (groupID: string): Promise<Boolean> =>\n RNIapIosSk2.isEligibleForIntroOffer(groupID);\n\n/**\n *\n */\n\nexport const subscriptionStatus = (sku: string): Promise<ProductStatus[]> =>\n RNIapIosSk2.subscriptionStatus(sku);\n\n/**\n *\n */\nexport const currentEntitlement = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.currentEntitlement(sku);\n\n/**\n *\n */\nexport const latestTransaction = (sku: string): Promise<TransactionSk2> =>\n RNIapIosSk2.latestTransaction(sku);\n"],"mappings":"AAAA,SAAQA,aAAR,QAA4B,cAA5B;AAWA,MAAM;EAACC;AAAD,IAAgBD,aAAtB;;AA8CA;AACA;AACA;AACA;AACA,OAAO,MAAME,IAAI,GAAG,MAAqBD,WAAW,CAACC,IAAZ,EAAlC;AAEP;AACA;AACA;;AACA,OAAO,MAAMC,uBAAuB,GAAIC,OAAD,IACrCH,WAAW,CAACE,uBAAZ,CAAoCC,OAApC,CADK;AAGP;AACA;AACA;;AAEA,OAAO,MAAMC,kBAAkB,GAAIC,GAAD,IAChCL,WAAW,CAACI,kBAAZ,CAA+BC,GAA/B,CADK;AAGP;AACA;AACA;;AACA,OAAO,MAAMC,kBAAkB,GAAID,GAAD,IAChCL,WAAW,CAACM,kBAAZ,CAA+BD,GAA/B,CADK;AAGP;AACA;AACA;;AACA,OAAO,MAAME,iBAAiB,GAAIF,GAAD,IAC/BL,WAAW,CAACO,iBAAZ,CAA8BF,GAA9B,CADK"}
@@ -8,7 +8,6 @@ declare type clearTransaction = () => Promise<void>;
8
8
  declare type clearProducts = () => Promise<void>;
9
9
  declare type promotedProduct = () => Promise<Product | null>;
10
10
  declare type buyPromotedProduct = () => Promise<void>;
11
- declare type requestReceipt = (refresh: boolean) => Promise<string>;
12
11
  declare type finishTransaction = (transactionIdentifier: string) => Promise<boolean>;
13
12
  declare type getPendingTransactions = () => Promise<ProductPurchase[]>;
14
13
  declare type presentCodeRedemptionSheet = () => Promise<null>;
@@ -26,7 +25,6 @@ export interface IosModulePropsSk2 extends NativeModuleProps {
26
25
  clearProducts: clearProducts;
27
26
  promotedProduct: promotedProduct;
28
27
  buyPromotedProduct: buyPromotedProduct;
29
- requestReceipt: requestReceipt;
30
28
  finishTransaction: finishTransaction;
31
29
  getPendingTransactions: getPendingTransactions;
32
30
  presentCodeRedemptionSheet: presentCodeRedemptionSheet;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-iap",
3
- "version": "12.1.0",
3
+ "version": "12.1.1",
4
4
  "description": "React Native In App Purchase Module.",
5
5
  "repository": "https://github.com/dooboolab/react-native-iap",
6
6
  "author": "dooboolab <support@dooboolab.com> (https://github.com/dooboolab)",
@@ -1,6 +1,8 @@
1
+ import {NativeModules} from 'react-native';
1
2
  import type {ResponseBody as ReceiptValidationResponse} from '@jeremybarbet/apple-api-types';
2
3
 
3
4
  import {getIosModule, isIosStorekit2} from '../internal';
5
+ const {RNIapIos} = NativeModules;
4
6
  import type {
5
7
  ProductIOS,
6
8
  ProductPurchase,
@@ -69,8 +71,13 @@ export const getReceiptIOS = async ({
69
71
  forceRefresh,
70
72
  }: {
71
73
  forceRefresh?: boolean;
72
- }): Promise<string> => getIosModule().requestReceipt(forceRefresh ?? false);
73
-
74
+ }): Promise<string> => {
75
+ if (!isIosStorekit2()) {
76
+ return RNIapIos.requestReceipt(forceRefresh ?? false);
77
+ } else {
78
+ return Promise.reject('Only available on Sk1');
79
+ }
80
+ };
74
81
  /**
75
82
  * Launches a modal to register the redeem offer code in IOS.
76
83
  * @returns {Promise<null>}
@@ -85,7 +92,7 @@ export const presentCodeRedemptionSheetIOS = async (): Promise<null> =>
85
92
  */
86
93
  export const getPromotedProductIOS = (): Promise<ProductIOS | null> => {
87
94
  if (!isIosStorekit2()) {
88
- return getIosModule().promotedProduct();
95
+ return RNIapIos.promotedProduct();
89
96
  } else {
90
97
  return Promise.reject('Only available on Sk1');
91
98
  }
@@ -29,7 +29,6 @@ type clearTransaction = () => Promise<void>;
29
29
  type clearProducts = () => Promise<void>;
30
30
  type promotedProduct = () => Promise<Product | null>;
31
31
  type buyPromotedProduct = () => Promise<void>;
32
- type requestReceipt = (refresh: boolean) => Promise<string>;
33
32
 
34
33
  type finishTransaction = (transactionIdentifier: string) => Promise<boolean>;
35
34
 
@@ -50,7 +49,6 @@ export interface IosModulePropsSk2 extends NativeModuleProps {
50
49
  clearProducts: clearProducts;
51
50
  promotedProduct: promotedProduct;
52
51
  buyPromotedProduct: buyPromotedProduct;
53
- requestReceipt: requestReceipt;
54
52
  finishTransaction: finishTransaction;
55
53
  getPendingTransactions: getPendingTransactions;
56
54
  presentCodeRedemptionSheet: presentCodeRedemptionSheet;