react-native-iap 9.0.4 → 10.0.2

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.
Files changed (70) hide show
  1. package/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonModule.kt +2 -1
  2. package/android/src/play/java/com/dooboolab/RNIap/RNIapModule.kt +2 -1
  3. package/ios/RNIapIos.swift +848 -848
  4. package/lib/commonjs/eventEmitter.js +54 -0
  5. package/lib/commonjs/eventEmitter.js.map +1 -0
  6. package/lib/commonjs/hooks/useIAP.js +33 -15
  7. package/lib/commonjs/hooks/useIAP.js.map +1 -1
  8. package/lib/commonjs/hooks/withIAPContext.js +9 -7
  9. package/lib/commonjs/hooks/withIAPContext.js.map +1 -1
  10. package/lib/commonjs/iap.js +127 -197
  11. package/lib/commonjs/iap.js.map +1 -1
  12. package/lib/commonjs/index.js +28 -15
  13. package/lib/commonjs/index.js.map +1 -1
  14. package/lib/commonjs/internal/enhancedFetch.js +30 -0
  15. package/lib/commonjs/internal/enhancedFetch.js.map +1 -0
  16. package/lib/commonjs/internal/fillProductsWithAdditionalData.js +47 -0
  17. package/lib/commonjs/internal/fillProductsWithAdditionalData.js.map +1 -0
  18. package/lib/commonjs/internal/index.js +45 -0
  19. package/lib/commonjs/internal/index.js.map +1 -0
  20. package/lib/commonjs/internal/platform.js +19 -0
  21. package/lib/commonjs/internal/platform.js.map +1 -0
  22. package/lib/commonjs/purchaseError.js +47 -0
  23. package/lib/commonjs/purchaseError.js.map +1 -0
  24. package/lib/commonjs/types/index.js +1 -23
  25. package/lib/commonjs/types/index.js.map +1 -1
  26. package/lib/module/eventEmitter.js +36 -0
  27. package/lib/module/eventEmitter.js.map +1 -0
  28. package/lib/module/hooks/useIAP.js +34 -16
  29. package/lib/module/hooks/useIAP.js.map +1 -1
  30. package/lib/module/hooks/withIAPContext.js +6 -5
  31. package/lib/module/hooks/withIAPContext.js.map +1 -1
  32. package/lib/module/iap.js +118 -185
  33. package/lib/module/iap.js.map +1 -1
  34. package/lib/module/index.js +2 -2
  35. package/lib/module/index.js.map +1 -1
  36. package/lib/module/internal/enhancedFetch.js +21 -0
  37. package/lib/module/internal/enhancedFetch.js.map +1 -0
  38. package/lib/module/internal/fillProductsWithAdditionalData.js +37 -0
  39. package/lib/module/internal/fillProductsWithAdditionalData.js.map +1 -0
  40. package/lib/module/internal/index.js +4 -0
  41. package/lib/module/internal/index.js.map +1 -0
  42. package/lib/module/internal/platform.js +8 -0
  43. package/lib/module/internal/platform.js.map +1 -0
  44. package/lib/module/purchaseError.js +38 -0
  45. package/lib/module/purchaseError.js.map +1 -0
  46. package/lib/module/types/index.js +0 -21
  47. package/lib/module/types/index.js.map +1 -1
  48. package/lib/typescript/eventEmitter.d.ts +17 -0
  49. package/lib/typescript/hooks/useIAP.d.ts +15 -9
  50. package/lib/typescript/hooks/withIAPContext.d.ts +4 -3
  51. package/lib/typescript/iap.d.ts +80 -41
  52. package/lib/typescript/index.d.ts +2 -2
  53. package/lib/typescript/internal/enhancedFetch.d.ts +6 -0
  54. package/lib/typescript/internal/fillProductsWithAdditionalData.d.ts +5 -0
  55. package/lib/typescript/internal/index.d.ts +3 -0
  56. package/lib/typescript/internal/platform.d.ts +3 -0
  57. package/lib/typescript/purchaseError.d.ts +26 -0
  58. package/lib/typescript/types/index.d.ts +1 -48
  59. package/package.json +1 -1
  60. package/src/eventEmitter.ts +49 -0
  61. package/src/hooks/useIAP.ts +38 -35
  62. package/src/hooks/withIAPContext.tsx +12 -13
  63. package/src/iap.ts +151 -232
  64. package/src/index.ts +2 -4
  65. package/src/internal/enhancedFetch.ts +25 -0
  66. package/src/internal/fillProductsWithAdditionalData.ts +43 -0
  67. package/src/internal/index.ts +3 -0
  68. package/src/internal/platform.ts +7 -0
  69. package/src/purchaseError.ts +35 -0
  70. package/src/types/index.ts +1 -59
@@ -3,12 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.validateReceiptIos = exports.validateReceiptAndroid = exports.validateReceiptAmazon = exports.setAndroidNativeModule = exports.requestSubscription = exports.requestPurchaseWithQuantityIOS = exports.requestPurchaseWithOfferIOS = exports.requestPurchase = exports.purchaseUpdatedListener = exports.purchaseErrorListener = exports.promotedProductListener = exports.presentCodeRedemptionSheetIOS = exports.initConnection = exports.getSubscriptions = exports.getReceiptIOS = exports.getPurchaseHistory = exports.getPromotedProductIOS = exports.getProducts = exports.getPendingPurchasesIOS = exports.getInstallSourceAndroid = exports.getAvailablePurchases = exports.flushFailedPurchasesCachedAsPendingAndroid = exports.finishTransaction = exports.endConnection = exports.deepLinkToSubscriptionsAndroid = exports.clearTransactionIOS = exports.clearProductsIOS = exports.buyPromotedProductIOS = exports.acknowledgePurchaseAndroid = exports.IapError = void 0;
6
+ exports.validateReceiptIos = exports.validateReceiptAndroid = exports.validateReceiptAmazon = exports.setAndroidNativeModule = exports.requestSubscription = exports.requestPurchaseWithQuantityIOS = exports.requestPurchaseWithOfferIOS = exports.requestPurchase = exports.presentCodeRedemptionSheetIOS = exports.initConnection = exports.getSubscriptions = exports.getReceiptIOS = exports.getPurchaseHistory = exports.getPromotedProductIOS = exports.getProducts = exports.getPendingPurchasesIOS = exports.getNativeModule = exports.getIosModule = exports.getInstallSourceAndroid = exports.getAvailablePurchases = exports.getAndroidModule = exports.flushFailedPurchasesCachedAsPendingAndroid = exports.finishTransaction = exports.endConnection = exports.deepLinkToSubscriptionsAndroid = exports.clearTransactionIOS = exports.clearProductsIOS = exports.buyPromotedProductIOS = exports.acknowledgePurchaseAndroid = void 0;
7
7
 
8
8
  var _reactNative = require("react-native");
9
9
 
10
10
  var _apple = require("./types/apple");
11
11
 
12
+ var _internal = require("./internal");
13
+
12
14
  var _types = require("./types");
13
15
 
14
16
  const {
@@ -16,24 +18,9 @@ const {
16
18
  RNIapModule,
17
19
  RNIapAmazonModule
18
20
  } = _reactNative.NativeModules;
19
- const isAndroid = _reactNative.Platform.OS === 'android';
20
- const isAmazon = isAndroid && !!RNIapAmazonModule;
21
- const isIos = _reactNative.Platform.OS === 'ios';
22
21
  const ANDROID_ITEM_TYPE_SUBSCRIPTION = 'subs';
23
22
  const ANDROID_ITEM_TYPE_IAP = 'inapp';
24
23
 
25
- class IapError {
26
- constructor(code, message) {
27
- this.code = code;
28
- this.message = message;
29
- this.code = code;
30
- this.message = message;
31
- }
32
-
33
- }
34
-
35
- exports.IapError = IapError;
36
-
37
24
  const getInstallSourceAndroid = () => {
38
25
  return RNIapModule ? _types.InstallSourceAndroid.GOOGLE_PLAY : _types.InstallSourceAndroid.AMAZON;
39
26
  };
@@ -49,7 +36,7 @@ exports.setAndroidNativeModule = setAndroidNativeModule;
49
36
 
50
37
  const checkNativeAndroidAvailable = () => {
51
38
  if (!RNIapModule && !RNIapAmazonModule) {
52
- throw new Error(_types.IAPErrorCode.E_IAP_NOT_AVAILABLE);
39
+ throw new Error('IAP_NOT_AVAILABLE');
53
40
  }
54
41
  };
55
42
 
@@ -58,9 +45,11 @@ const getAndroidModule = () => {
58
45
  return androidNativeModule ? androidNativeModule : RNIapModule ? RNIapModule : RNIapAmazonModule;
59
46
  };
60
47
 
48
+ exports.getAndroidModule = getAndroidModule;
49
+
61
50
  const checkNativeIOSAvailable = () => {
62
51
  if (!RNIapIos) {
63
- throw new Error(_types.IAPErrorCode.E_IAP_NOT_AVAILABLE);
52
+ throw new Error('IAP_NOT_AVAILABLE');
64
53
  }
65
54
  };
66
55
 
@@ -69,8 +58,10 @@ const getIosModule = () => {
69
58
  return RNIapIos;
70
59
  };
71
60
 
61
+ exports.getIosModule = getIosModule;
62
+
72
63
  const getNativeModule = () => {
73
- return isAndroid ? getAndroidModule() : getIosModule();
64
+ return _internal.isAndroid ? getAndroidModule() : getIosModule();
74
65
  };
75
66
  /**
76
67
  * Init module for purchase flow. Required on Android. In ios it will check whether user canMakePayment.
@@ -78,6 +69,8 @@ const getNativeModule = () => {
78
69
  */
79
70
 
80
71
 
72
+ exports.getNativeModule = getNativeModule;
73
+
81
74
  const initConnection = () => getNativeModule().initConnection();
82
75
  /**
83
76
  * End module for purchase flow.
@@ -97,43 +90,6 @@ const endConnection = () => getNativeModule().endConnection();
97
90
  exports.endConnection = endConnection;
98
91
 
99
92
  const flushFailedPurchasesCachedAsPendingAndroid = () => getAndroidModule().flushFailedPurchasesCachedAsPending();
100
- /**
101
- * Fill products with additional data
102
- * @param {Array<ProductCommon>} products Products
103
- */
104
-
105
-
106
- exports.flushFailedPurchasesCachedAsPendingAndroid = flushFailedPurchasesCachedAsPendingAndroid;
107
-
108
- const fillProductsAdditionalData = async products => {
109
- // Amazon
110
- if (RNIapAmazonModule) {
111
- // On amazon we must get the user marketplace to detect the currency
112
- const user = await RNIapAmazonModule.getUser();
113
- const currencies = {
114
- CA: 'CAD',
115
- ES: 'EUR',
116
- AU: 'AUD',
117
- DE: 'EUR',
118
- IN: 'INR',
119
- US: 'USD',
120
- JP: 'JPY',
121
- GB: 'GBP',
122
- IT: 'EUR',
123
- BR: 'BRL',
124
- FR: 'EUR'
125
- };
126
- const currency = currencies[user.userMarketplaceAmazon]; // Add currency to products
127
-
128
- products.forEach(product => {
129
- if (currency) {
130
- product.currency = currency;
131
- }
132
- });
133
- }
134
-
135
- return products;
136
- };
137
93
  /**
138
94
  * Get a list of products (consumable and non-consumable items, but not subscriptions)
139
95
  * @param {string[]} skus The item skus
@@ -141,16 +97,23 @@ const fillProductsAdditionalData = async products => {
141
97
  */
142
98
 
143
99
 
144
- const getProducts = skus => (_reactNative.Platform.select({
145
- ios: async () => {
146
- const items = await getIosModule().getItems(skus);
147
- return items.filter(item => skus.includes(item.productId) && item.type === 'iap');
148
- },
149
- android: async () => {
150
- const products = await getAndroidModule().getItemsByType(ANDROID_ITEM_TYPE_IAP, skus);
151
- return fillProductsAdditionalData(products);
152
- }
153
- }) || Promise.resolve)();
100
+ exports.flushFailedPurchasesCachedAsPendingAndroid = flushFailedPurchasesCachedAsPendingAndroid;
101
+
102
+ const getProducts = _ref => {
103
+ let {
104
+ skus
105
+ } = _ref;
106
+ return (_reactNative.Platform.select({
107
+ ios: async () => {
108
+ const items = await getIosModule().getItems(skus);
109
+ return items.filter(item => skus.includes(item.productId) && item.type === 'iap');
110
+ },
111
+ android: async () => {
112
+ const products = await getAndroidModule().getItemsByType(ANDROID_ITEM_TYPE_IAP, skus);
113
+ return (0, _internal.fillProductsWithAdditionalData)(products);
114
+ }
115
+ }) || Promise.resolve)();
116
+ };
154
117
  /**
155
118
  * Get a list of subscriptions
156
119
  * @param {string[]} skus The item skus
@@ -160,19 +123,24 @@ const getProducts = skus => (_reactNative.Platform.select({
160
123
 
161
124
  exports.getProducts = getProducts;
162
125
 
163
- const getSubscriptions = skus => (_reactNative.Platform.select({
164
- ios: async () => {
165
- const items = await getIosModule().getItems(skus);
166
- return items.filter(item => skus.includes(item.productId) && item.type === 'subs');
167
- },
168
- android: async () => {
169
- const subscriptions = await getAndroidModule().getItemsByType(ANDROID_ITEM_TYPE_SUBSCRIPTION, skus);
170
- return fillProductsAdditionalData(subscriptions);
171
- }
172
- }) || Promise.resolve)();
126
+ const getSubscriptions = _ref2 => {
127
+ let {
128
+ skus
129
+ } = _ref2;
130
+ return (_reactNative.Platform.select({
131
+ ios: async () => {
132
+ const items = await getIosModule().getItems(skus);
133
+ return items.filter(item => skus.includes(item.productId) && item.type === 'subs');
134
+ },
135
+ android: async () => {
136
+ const subscriptions = await getAndroidModule().getItemsByType(ANDROID_ITEM_TYPE_SUBSCRIPTION, skus);
137
+ return (0, _internal.fillProductsWithAdditionalData)(subscriptions);
138
+ }
139
+ }) || Promise.resolve)();
140
+ };
173
141
  /**
174
142
  * Gets an inventory of purchases made by the user regardless of consumption status
175
- * @returns {Promise<(InAppPurchase | SubscriptionPurchase)[]>}
143
+ * @returns {Promise<(ProductPurchase | SubscriptionPurchase)[]>}
176
144
  */
177
145
 
178
146
 
@@ -194,7 +162,7 @@ const getPurchaseHistory = () => (_reactNative.Platform.select({
194
162
  }) || Promise.resolve)();
195
163
  /**
196
164
  * Get all purchases made by the user (either non-consumable, or haven't been consumed yet)
197
- * @returns {Promise<(InAppPurchase | SubscriptionPurchase)[]>}
165
+ * @returns {Promise<(ProductPurchase | SubscriptionPurchase)[]>}
198
166
  */
199
167
 
200
168
 
@@ -223,24 +191,22 @@ const getAvailablePurchases = () => (_reactNative.Platform.select({
223
191
  * @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
224
192
  * @param {string[]} [skus] Product Ids to purchase. Note that this is only for Android. iOS only uses a single SKU. If not provided, it'll default to using [sku] for backward-compatibility
225
193
  * @param {boolean} [isOfferPersonalized] Defaults to false, Only for Android V5
226
- * @returns {Promise<InAppPurchase>}
194
+ * @returns {Promise<ProductPurchase>}
227
195
  */
228
196
 
229
197
 
230
198
  exports.getAvailablePurchases = getAvailablePurchases;
231
199
 
232
- const requestPurchase = _ref => {
200
+ const requestPurchase = _ref3 => {
233
201
  let {
234
202
  sku,
235
203
  andDangerouslyFinishTransactionAutomaticallyIOS = false,
204
+ applicationUsername,
236
205
  obfuscatedAccountIdAndroid,
237
206
  obfuscatedProfileIdAndroid,
238
- applicationUsername,
239
207
  skus,
240
- // Android Billing V5
241
- isOfferPersonalized = undefined // Android Billing V5
242
-
243
- } = _ref;
208
+ isOfferPersonalized
209
+ } = _ref3;
244
210
  return (_reactNative.Platform.select({
245
211
  ios: async () => {
246
212
  if (andDangerouslyFinishTransactionAutomaticallyIOS) {
@@ -250,7 +216,7 @@ const requestPurchase = _ref => {
250
216
  return getIosModule().buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, applicationUsername);
251
217
  },
252
218
  android: async () => {
253
- if (isAmazon) {
219
+ if (_internal.isAmazon) {
254
220
  return RNIapAmazonModule.buyItemByType(sku);
255
221
  } else {
256
222
  return getAndroidModule().buyItemByType(ANDROID_ITEM_TYPE_IAP, skus !== null && skus !== void 0 && skus.length ? skus : [sku], null, -1, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, [], isOfferPersonalized ?? false);
@@ -274,20 +240,18 @@ const requestPurchase = _ref => {
274
240
 
275
241
  exports.requestPurchase = requestPurchase;
276
242
 
277
- const requestSubscription = _ref2 => {
243
+ const requestSubscription = _ref4 => {
278
244
  let {
279
245
  sku,
280
246
  andDangerouslyFinishTransactionAutomaticallyIOS = false,
247
+ applicationUsername,
281
248
  purchaseTokenAndroid,
282
249
  prorationModeAndroid = -1,
250
+ subscriptionOffers,
283
251
  obfuscatedAccountIdAndroid,
284
252
  obfuscatedProfileIdAndroid,
285
- subscriptionOffers = undefined,
286
- // Android Billing V5
287
- isOfferPersonalized = undefined,
288
- // Android Billing V5
289
- applicationUsername
290
- } = _ref2;
253
+ isOfferPersonalized = undefined
254
+ } = _ref4;
291
255
  return (_reactNative.Platform.select({
292
256
  ios: async () => {
293
257
  if (andDangerouslyFinishTransactionAutomaticallyIOS) {
@@ -297,7 +261,7 @@ const requestSubscription = _ref2 => {
297
261
  return getIosModule().buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, applicationUsername);
298
262
  },
299
263
  android: async () => {
300
- if (isAmazon) {
264
+ if (_internal.isAmazon) {
301
265
  return RNIapAmazonModule.buyItemByType(sku);
302
266
  } else {
303
267
  if (!(subscriptionOffers !== null && subscriptionOffers !== void 0 && subscriptionOffers.length)) {
@@ -319,7 +283,13 @@ const requestSubscription = _ref2 => {
319
283
 
320
284
  exports.requestSubscription = requestSubscription;
321
285
 
322
- const requestPurchaseWithQuantityIOS = (sku, quantity) => getIosModule().buyProductWithQuantityIOS(sku, quantity);
286
+ const requestPurchaseWithQuantityIOS = _ref5 => {
287
+ let {
288
+ sku,
289
+ quantity
290
+ } = _ref5;
291
+ return getIosModule().buyProductWithQuantityIOS(sku, quantity);
292
+ };
323
293
  /**
324
294
  * Finish Transaction (both platforms)
325
295
  * Abstracts Finish Transaction
@@ -336,7 +306,12 @@ const requestPurchaseWithQuantityIOS = (sku, quantity) => getIosModule().buyProd
336
306
 
337
307
  exports.requestPurchaseWithQuantityIOS = requestPurchaseWithQuantityIOS;
338
308
 
339
- const finishTransaction = (purchase, isConsumable, developerPayloadAndroid) => {
309
+ const finishTransaction = _ref6 => {
310
+ let {
311
+ purchase,
312
+ isConsumable,
313
+ developerPayloadAndroid
314
+ } = _ref6;
340
315
  return (_reactNative.Platform.select({
341
316
  ios: async () => {
342
317
  return getIosModule().finishTransaction(purchase.transactionId);
@@ -387,7 +362,11 @@ const clearProductsIOS = () => getIosModule().clearProducts();
387
362
 
388
363
  exports.clearProductsIOS = clearProductsIOS;
389
364
 
390
- const acknowledgePurchaseAndroid = (token, developerPayload) => {
365
+ const acknowledgePurchaseAndroid = _ref7 => {
366
+ let {
367
+ token,
368
+ developerPayload
369
+ } = _ref7;
391
370
  return getAndroidModule().acknowledgePurchase(token, developerPayload);
392
371
  };
393
372
  /**
@@ -399,7 +378,10 @@ const acknowledgePurchaseAndroid = (token, developerPayload) => {
399
378
 
400
379
  exports.acknowledgePurchaseAndroid = acknowledgePurchaseAndroid;
401
380
 
402
- const deepLinkToSubscriptionsAndroid = async sku => {
381
+ const deepLinkToSubscriptionsAndroid = async _ref8 => {
382
+ let {
383
+ sku
384
+ } = _ref8;
403
385
  checkNativeAndroidAvailable();
404
386
  return _reactNative.Linking.openURL(`https://play.google.com/store/account/subscriptions?package=${await RNIapModule.getPackageName()}&sku=${sku}`);
405
387
  };
@@ -426,31 +408,18 @@ const buyPromotedProductIOS = () => getIosModule().buyPromotedProduct();
426
408
 
427
409
  exports.buyPromotedProductIOS = buyPromotedProductIOS;
428
410
 
429
- const fetchJsonOrThrow = async (url, receiptBody) => {
430
- const response = await fetch(url, {
431
- method: 'POST',
432
- headers: {
433
- Accept: 'application/json',
434
- 'Content-Type': 'application/json'
435
- },
436
- body: JSON.stringify(receiptBody)
437
- });
438
-
439
- if (!response.ok) {
440
- throw Object.assign(new Error(response.statusText), {
441
- statusCode: response.status
442
- });
443
- }
444
-
445
- return response.json();
446
- };
447
-
448
411
  const requestAgnosticReceiptValidationIos = async receiptBody => {
449
- const response = await fetchJsonOrThrow('https://buy.itunes.apple.com/verifyReceipt', receiptBody); // Best practice is to check for test receipt and check sandbox instead
412
+ const response = await (0, _internal.enhancedFetch)('https://buy.itunes.apple.com/verifyReceipt', {
413
+ method: 'POST',
414
+ body: receiptBody
415
+ }); // Best practice is to check for test receipt and check sandbox instead
450
416
  // https://developer.apple.com/documentation/appstorereceipts/verifyreceipt
451
417
 
452
418
  if (response && response.status === _apple.ReceiptValidationStatus.TEST_RECEIPT) {
453
- const testResponse = await fetchJsonOrThrow('https://sandbox.itunes.apple.com/verifyReceipt', receiptBody);
419
+ const testResponse = await (0, _internal.enhancedFetch)('https://sandbox.itunes.apple.com/verifyReceipt', {
420
+ method: 'POST',
421
+ body: receiptBody
422
+ });
454
423
  return testResponse;
455
424
  }
456
425
 
@@ -473,7 +442,14 @@ const requestAgnosticReceiptValidationIos = async receiptBody => {
473
442
  */
474
443
 
475
444
 
476
- const requestPurchaseWithOfferIOS = (sku, forUser, withOffer) => getIosModule().buyProductWithOffer(sku, forUser, withOffer);
445
+ const requestPurchaseWithOfferIOS = _ref9 => {
446
+ let {
447
+ sku,
448
+ forUser,
449
+ withOffer
450
+ } = _ref9;
451
+ return getIosModule().buyProductWithOffer(sku, forUser, withOffer);
452
+ };
477
453
  /**
478
454
  * Validate receipt for iOS.
479
455
  * @param {object} receiptBody the receipt body to send to apple server.
@@ -484,14 +460,18 @@ const requestPurchaseWithOfferIOS = (sku, forUser, withOffer) => getIosModule().
484
460
 
485
461
  exports.requestPurchaseWithOfferIOS = requestPurchaseWithOfferIOS;
486
462
 
487
- const validateReceiptIos = async (receiptBody, isTest) => {
463
+ const validateReceiptIos = async _ref10 => {
464
+ let {
465
+ receiptBody,
466
+ isTest
467
+ } = _ref10;
468
+
488
469
  if (isTest == null) {
489
470
  return await requestAgnosticReceiptValidationIos(receiptBody);
490
471
  }
491
472
 
492
473
  const url = isTest ? 'https://sandbox.itunes.apple.com/verifyReceipt' : 'https://buy.itunes.apple.com/verifyReceipt';
493
- const response = await fetchJsonOrThrow(url, receiptBody);
494
- return response;
474
+ return await (0, _internal.enhancedFetch)(url);
495
475
  };
496
476
  /**
497
477
  * Validate receipt for Android. NOTE: This method is here for debugging purposes only. Including
@@ -508,23 +488,17 @@ const validateReceiptIos = async (receiptBody, isTest) => {
508
488
 
509
489
  exports.validateReceiptIos = validateReceiptIos;
510
490
 
511
- const validateReceiptAndroid = async (packageName, productId, productToken, accessToken, isSub) => {
491
+ const validateReceiptAndroid = async _ref11 => {
492
+ let {
493
+ packageName,
494
+ productId,
495
+ productToken,
496
+ accessToken,
497
+ isSub
498
+ } = _ref11;
512
499
  const type = isSub ? 'subscriptions' : 'products';
513
500
  const url = 'https://androidpublisher.googleapis.com/androidpublisher/v3/applications' + `/${packageName}/purchases/${type}/${productId}` + `/tokens/${productToken}?access_token=${accessToken}`;
514
- const response = await fetch(url, {
515
- method: 'GET',
516
- headers: {
517
- 'Content-Type': 'application/json'
518
- }
519
- });
520
-
521
- if (!response.ok) {
522
- throw Object.assign(new Error(response.statusText), {
523
- statusCode: response.status
524
- });
525
- }
526
-
527
- return response.json();
501
+ return await (0, _internal.enhancedFetch)(url);
528
502
  };
529
503
  /**
530
504
  * Validate receipt for Amazon. NOTE: This method is here for debugging purposes only. Including
@@ -540,65 +514,16 @@ const validateReceiptAndroid = async (packageName, productId, productToken, acce
540
514
 
541
515
  exports.validateReceiptAndroid = validateReceiptAndroid;
542
516
 
543
- const validateReceiptAmazon = async function (developerSecret, userId, receiptId) {
544
- let useSandbox = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
517
+ const validateReceiptAmazon = async _ref12 => {
518
+ let {
519
+ developerSecret,
520
+ userId,
521
+ receiptId,
522
+ useSandbox = true
523
+ } = _ref12;
545
524
  const sandBoxUrl = useSandbox ? 'sandbox/' : '';
546
525
  const url = `https://appstore-sdk.amazon.com/${sandBoxUrl}version/1.0/verifyReceiptId/developer/${developerSecret}/user/${userId}/receiptId/${receiptId}`;
547
- const response = await fetch(url, {
548
- method: 'GET',
549
- headers: {
550
- 'Content-Type': 'application/json'
551
- }
552
- });
553
-
554
- if (!response.ok) {
555
- throw Object.assign(new Error(response.statusText), {
556
- statusCode: response.status
557
- });
558
- }
559
-
560
- return response.json();
561
- };
562
- /**
563
- * Add IAP purchase event
564
- * @returns {callback(e: InAppPurchase | ProductPurchase)}
565
- */
566
-
567
-
568
- exports.validateReceiptAmazon = validateReceiptAmazon;
569
-
570
- const purchaseUpdatedListener = listener => {
571
- const emitterSubscription = new _reactNative.NativeEventEmitter(getNativeModule()).addListener('purchase-updated', listener);
572
-
573
- if (isAndroid) {
574
- getAndroidModule().startListening();
575
- }
576
-
577
- return emitterSubscription;
578
- };
579
- /**
580
- * Add IAP purchase error event
581
- * @returns {callback(e: PurchaseError)}
582
- */
583
-
584
-
585
- exports.purchaseUpdatedListener = purchaseUpdatedListener;
586
-
587
- const purchaseErrorListener = listener => new _reactNative.NativeEventEmitter(getNativeModule()).addListener('purchase-error', listener);
588
- /**
589
- * Add IAP promoted subscription event
590
- * Only available on iOS
591
- */
592
-
593
-
594
- exports.purchaseErrorListener = purchaseErrorListener;
595
-
596
- const promotedProductListener = listener => {
597
- if (isIos) {
598
- return new _reactNative.NativeEventEmitter(getIosModule()).addListener('iap-promoted-product', listener);
599
- }
600
-
601
- return null;
526
+ return await (0, _internal.enhancedFetch)(url);
602
527
  };
603
528
  /**
604
529
  * Get the current receipt base64 encoded in IOS.
@@ -607,7 +532,7 @@ const promotedProductListener = listener => {
607
532
  */
608
533
 
609
534
 
610
- exports.promotedProductListener = promotedProductListener;
535
+ exports.validateReceiptAmazon = validateReceiptAmazon;
611
536
 
612
537
  const getPendingPurchasesIOS = async () => getIosModule().getPendingTransactions();
613
538
  /**
@@ -619,7 +544,12 @@ const getPendingPurchasesIOS = async () => getIosModule().getPendingTransactions
619
544
 
620
545
  exports.getPendingPurchasesIOS = getPendingPurchasesIOS;
621
546
 
622
- const getReceiptIOS = async forceRefresh => getIosModule().requestReceipt(forceRefresh ?? false);
547
+ const getReceiptIOS = async _ref13 => {
548
+ let {
549
+ forceRefresh
550
+ } = _ref13;
551
+ return getIosModule().requestReceipt(forceRefresh ?? false);
552
+ };
623
553
  /**
624
554
  * Launches a modal to register the redeem offer code in IOS.
625
555
  * @returns {Promise<null>}