react-native-iap 8.5.2 → 8.5.3

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.
package/src/iap.js DELETED
@@ -1,625 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- import * as Apple from './types/apple';
38
- import { Linking, NativeEventEmitter, NativeModules, Platform, } from 'react-native';
39
- import { IAPErrorCode, InstallSourceAndroid, PurchaseStateAndroid, } from './types';
40
- var RNIapIos = NativeModules.RNIapIos, RNIapModule = NativeModules.RNIapModule, RNIapAmazonModule = NativeModules.RNIapAmazonModule;
41
- var ANDROID_ITEM_TYPE_SUBSCRIPTION = 'subs';
42
- var ANDROID_ITEM_TYPE_IAP = 'inapp';
43
- export var getInstallSourceAndroid = function () {
44
- return RNIapModule
45
- ? InstallSourceAndroid.GOOGLE_PLAY
46
- : InstallSourceAndroid.AMAZON;
47
- };
48
- var checkNativeAndroidAvailable = function () {
49
- if (!RNIapModule && !RNIapAmazonModule) {
50
- throw new Error(IAPErrorCode.E_IAP_NOT_AVAILABLE);
51
- }
52
- };
53
- var getAndroidModule = function () {
54
- checkNativeAndroidAvailable();
55
- return RNIapModule ? RNIapModule : RNIapAmazonModule;
56
- };
57
- var checkNativeiOSAvailable = function () {
58
- if (!RNIapIos) {
59
- throw new Error(IAPErrorCode.E_IAP_NOT_AVAILABLE);
60
- }
61
- };
62
- var getIosModule = function () {
63
- checkNativeiOSAvailable();
64
- return RNIapIos;
65
- };
66
- var getNativeModule = function () {
67
- return RNIapModule
68
- ? RNIapModule
69
- : RNIapAmazonModule
70
- ? RNIapAmazonModule
71
- : RNIapIos;
72
- };
73
- /**
74
- * Init module for purchase flow. Required on Android. In ios it will check whether user canMakePayment.
75
- * @returns {Promise<boolean>}
76
- */
77
- export var initConnection = function () {
78
- return getNativeModule().initConnection();
79
- };
80
- /**
81
- * End module for purchase flow.
82
- * @returns {Promise<void>}
83
- */
84
- export var endConnection = function () {
85
- return getNativeModule().endConnection();
86
- };
87
- /**
88
- * Consume all 'ghost' purchases (that is, pending payment that already failed but is still marked as pending in Play Store cache). Android only.
89
- * @returns {Promise<boolean>}
90
- */
91
- export var flushFailedPurchasesCachedAsPendingAndroid = function () { return getAndroidModule().flushFailedPurchasesCachedAsPending(); };
92
- /**
93
- * Fill products with additional data
94
- * @param {Array<ProductCommon>} products Products
95
- */
96
- var fillProductsAdditionalData = function (products) { return __awaiter(void 0, void 0, void 0, function () {
97
- var user, currencies, currency_1;
98
- return __generator(this, function (_a) {
99
- switch (_a.label) {
100
- case 0:
101
- if (!RNIapAmazonModule) return [3 /*break*/, 2];
102
- return [4 /*yield*/, RNIapAmazonModule.getUser()];
103
- case 1:
104
- user = _a.sent();
105
- currencies = {
106
- CA: 'CAD',
107
- ES: 'EUR',
108
- AU: 'AUD',
109
- DE: 'EUR',
110
- IN: 'INR',
111
- US: 'USD',
112
- JP: 'JPY',
113
- GB: 'GBP',
114
- IT: 'EUR',
115
- BR: 'BRL',
116
- FR: 'EUR',
117
- };
118
- currency_1 = currencies[user.userMarketplaceAmazon];
119
- // Add currency to products
120
- products.forEach(function (product) {
121
- if (currency_1) {
122
- product.currency = currency_1;
123
- }
124
- });
125
- _a.label = 2;
126
- case 2: return [2 /*return*/, products];
127
- }
128
- });
129
- }); };
130
- /**
131
- * Get a list of products (consumable and non-consumable items, but not subscriptions)
132
- * @param {string[]} skus The item skus
133
- * @returns {Promise<Product[]>}
134
- */
135
- export var getProducts = function (skus) {
136
- return (Platform.select({
137
- ios: function () { return __awaiter(void 0, void 0, void 0, function () {
138
- var products;
139
- return __generator(this, function (_a) {
140
- switch (_a.label) {
141
- case 0: return [4 /*yield*/, getIosModule().getItems(skus)];
142
- case 1:
143
- products = _a.sent();
144
- return [2 /*return*/, products.filter(function (item) {
145
- return skus.includes(item.productId) && item.type === 'iap';
146
- })];
147
- }
148
- });
149
- }); },
150
- android: function () { return __awaiter(void 0, void 0, void 0, function () {
151
- var products;
152
- return __generator(this, function (_a) {
153
- switch (_a.label) {
154
- case 0: return [4 /*yield*/, getAndroidModule().getItemsByType(ANDROID_ITEM_TYPE_IAP, skus)];
155
- case 1:
156
- products = _a.sent();
157
- return [2 /*return*/, fillProductsAdditionalData(products)];
158
- }
159
- });
160
- }); },
161
- }) || Promise.resolve)();
162
- };
163
- /**
164
- * Get a list of subscriptions
165
- * @param {string[]} skus The item skus
166
- * @returns {Promise<Subscription[]>}
167
- */
168
- export var getSubscriptions = function (skus) {
169
- return (Platform.select({
170
- ios: function () { return __awaiter(void 0, void 0, void 0, function () {
171
- var subscriptions;
172
- return __generator(this, function (_a) {
173
- switch (_a.label) {
174
- case 0: return [4 /*yield*/, getIosModule().getItems(skus)];
175
- case 1:
176
- subscriptions = _a.sent();
177
- return [2 /*return*/, subscriptions.filter(function (item) {
178
- return skus.includes(item.productId) && item.type === 'subs';
179
- })];
180
- }
181
- });
182
- }); },
183
- android: function () { return __awaiter(void 0, void 0, void 0, function () {
184
- var subscriptions;
185
- return __generator(this, function (_a) {
186
- switch (_a.label) {
187
- case 0: return [4 /*yield*/, getAndroidModule().getItemsByType(ANDROID_ITEM_TYPE_SUBSCRIPTION, skus)];
188
- case 1:
189
- subscriptions = _a.sent();
190
- return [2 /*return*/, fillProductsAdditionalData(subscriptions)];
191
- }
192
- });
193
- }); },
194
- }) || Promise.resolve)();
195
- };
196
- /**
197
- * Gets an inventory of purchases made by the user regardless of consumption status
198
- * @returns {Promise<(InAppPurchase | SubscriptionPurchase)[]>}
199
- */
200
- export var getPurchaseHistory = function () {
201
- return (Platform.select({
202
- ios: function () { return __awaiter(void 0, void 0, void 0, function () {
203
- return __generator(this, function (_a) {
204
- return [2 /*return*/, getIosModule().getAvailableItems()];
205
- });
206
- }); },
207
- android: function () { return __awaiter(void 0, void 0, void 0, function () {
208
- var products, subscriptions;
209
- return __generator(this, function (_a) {
210
- switch (_a.label) {
211
- case 0:
212
- if (!RNIapAmazonModule) return [3 /*break*/, 2];
213
- return [4 /*yield*/, RNIapAmazonModule.getAvailableItems()];
214
- case 1: return [2 /*return*/, _a.sent()];
215
- case 2: return [4 /*yield*/, getAndroidModule().getPurchaseHistoryByType(ANDROID_ITEM_TYPE_IAP)];
216
- case 3:
217
- products = _a.sent();
218
- return [4 /*yield*/, getAndroidModule().getPurchaseHistoryByType(ANDROID_ITEM_TYPE_SUBSCRIPTION)];
219
- case 4:
220
- subscriptions = _a.sent();
221
- return [2 /*return*/, products.concat(subscriptions)];
222
- }
223
- });
224
- }); },
225
- }) || Promise.resolve)();
226
- };
227
- /**
228
- * Get all purchases made by the user (either non-consumable, or haven't been consumed yet)
229
- * @returns {Promise<(InAppPurchase | SubscriptionPurchase)[]>}
230
- */
231
- export var getAvailablePurchases = function () {
232
- return (Platform.select({
233
- ios: function () { return __awaiter(void 0, void 0, void 0, function () {
234
- return __generator(this, function (_a) {
235
- return [2 /*return*/, getIosModule().getAvailableItems()];
236
- });
237
- }); },
238
- android: function () { return __awaiter(void 0, void 0, void 0, function () {
239
- var products, subscriptions;
240
- return __generator(this, function (_a) {
241
- switch (_a.label) {
242
- case 0:
243
- if (!RNIapAmazonModule) return [3 /*break*/, 2];
244
- return [4 /*yield*/, RNIapAmazonModule.getAvailableItems()];
245
- case 1: return [2 /*return*/, _a.sent()];
246
- case 2: return [4 /*yield*/, getAndroidModule().getAvailableItemsByType(ANDROID_ITEM_TYPE_IAP)];
247
- case 3:
248
- products = _a.sent();
249
- return [4 /*yield*/, getAndroidModule().getAvailableItemsByType(ANDROID_ITEM_TYPE_SUBSCRIPTION)];
250
- case 4:
251
- subscriptions = _a.sent();
252
- return [2 /*return*/, products.concat(subscriptions)];
253
- }
254
- });
255
- }); },
256
- }) || Promise.resolve)();
257
- };
258
- /**
259
- * Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
260
- * @param {string} sku The product's sku/ID
261
- * @param {string} [applicationUsername] The purchaser's user ID
262
- * @param {boolean} [andDangerouslyFinishTransactionAutomaticallyIOS] You should set this to false and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.
263
- * @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
264
- * @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
265
- * @returns {Promise<InAppPurchase>}
266
- */
267
- export var requestPurchase = function (_a) {
268
- var sku = _a.sku, _b = _a.andDangerouslyFinishTransactionAutomaticallyIOS, andDangerouslyFinishTransactionAutomaticallyIOS = _b === void 0 ? false : _b, _c = _a.obfuscatedAccountIdAndroid, obfuscatedAccountIdAndroid = _c === void 0 ? undefined : _c, _d = _a.obfuscatedProfileIdAndroid, obfuscatedProfileIdAndroid = _d === void 0 ? undefined : _d, _e = _a.applicationUsername, applicationUsername = _e === void 0 ? undefined : _e;
269
- return (Platform.select({
270
- ios: function () { return __awaiter(void 0, void 0, void 0, function () {
271
- return __generator(this, function (_a) {
272
- if (andDangerouslyFinishTransactionAutomaticallyIOS) {
273
- // eslint-disable-next-line no-console
274
- console.warn(
275
- // eslint-disable-next-line max-len
276
- 'You are dangerously allowing react-native-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.');
277
- }
278
- return [2 /*return*/, getIosModule().buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, applicationUsername)];
279
- });
280
- }); },
281
- android: function () { return __awaiter(void 0, void 0, void 0, function () {
282
- return __generator(this, function (_a) {
283
- return [2 /*return*/, getAndroidModule().buyItemByType(ANDROID_ITEM_TYPE_IAP, sku, null, 0, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid)];
284
- });
285
- }); },
286
- }) || Promise.resolve)();
287
- };
288
- /**
289
- * Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
290
- * @param {string} [sku] The product's sku/ID
291
- * @param {string} [applicationUsername] The purchaser's user ID
292
- * @param {boolean} [andDangerouslyFinishTransactionAutomaticallyIOS] You should set this to false and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.
293
- * @param {string} [purchaseTokenAndroid] purchaseToken that the user is upgrading or downgrading from (Android).
294
- * @param {ProrationModesAndroid} [prorationModeAndroid] UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY, IMMEDIATE_WITH_TIME_PRORATION, IMMEDIATE_AND_CHARGE_PRORATED_PRICE, IMMEDIATE_WITHOUT_PRORATION, DEFERRED
295
- * @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
296
- * @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
297
- * @returns {Promise<SubscriptionPurchase | null>} Promise resolves to null when using proratioModesAndroid=DEFERRED, and to a SubscriptionPurchase otherwise
298
- */
299
- export var requestSubscription = function (_a) {
300
- var sku = _a.sku, _b = _a.andDangerouslyFinishTransactionAutomaticallyIOS, andDangerouslyFinishTransactionAutomaticallyIOS = _b === void 0 ? false : _b, _c = _a.purchaseTokenAndroid, purchaseTokenAndroid = _c === void 0 ? undefined : _c, _d = _a.prorationModeAndroid, prorationModeAndroid = _d === void 0 ? -1 : _d, _e = _a.obfuscatedAccountIdAndroid, obfuscatedAccountIdAndroid = _e === void 0 ? undefined : _e, _f = _a.obfuscatedProfileIdAndroid, obfuscatedProfileIdAndroid = _f === void 0 ? undefined : _f, _g = _a.applicationUsername, applicationUsername = _g === void 0 ? undefined : _g;
301
- return (Platform.select({
302
- ios: function () { return __awaiter(void 0, void 0, void 0, function () {
303
- return __generator(this, function (_a) {
304
- if (andDangerouslyFinishTransactionAutomaticallyIOS) {
305
- // eslint-disable-next-line no-console
306
- console.warn(
307
- // eslint-disable-next-line max-len
308
- 'You are dangerously allowing react-native-iap to finish your transaction automatically. You should set andDangerouslyFinishTransactionAutomatically to false when calling requestPurchase and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.');
309
- }
310
- return [2 /*return*/, getIosModule().buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, applicationUsername)];
311
- });
312
- }); },
313
- android: function () { return __awaiter(void 0, void 0, void 0, function () {
314
- return __generator(this, function (_a) {
315
- return [2 /*return*/, getAndroidModule().buyItemByType(ANDROID_ITEM_TYPE_SUBSCRIPTION, sku, purchaseTokenAndroid, prorationModeAndroid, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid)];
316
- });
317
- }); },
318
- }) || Promise.resolve)();
319
- };
320
- /**
321
- * Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
322
- * @param {string} sku The product's sku/ID
323
- * @returns {Promise<void>}
324
- */
325
- export var requestPurchaseWithQuantityIOS = function (sku, quantity) {
326
- return getIosModule().buyProductWithQuantityIOS(sku, quantity);
327
- };
328
- /**
329
- * Finish Transaction (both platforms)
330
- * Abstracts Finish Transaction
331
- * iOS: Tells StoreKit that you have delivered the purchase to the user and StoreKit can now let go of the transaction.
332
- * Call this after you have persisted the purchased state to your server or local data in your app.
333
- * `react-native-iap` will continue to deliver the purchase updated events with the successful purchase until you finish the transaction. **Even after the app has relaunched.**
334
- * Android: it will consume purchase for consumables and acknowledge purchase for non-consumables.
335
- * @param {object} purchase The purchase that you would like to finish.
336
- * @param {boolean} isConsumable Checks if purchase is consumable. Has effect on `android`.
337
- * @param {string} developerPayloadAndroid Android developerPayload.
338
- * @returns {Promise<string | void> }
339
- */
340
- export var finishTransaction = function (purchase, isConsumable, developerPayloadAndroid) {
341
- return (Platform.select({
342
- ios: function () { return __awaiter(void 0, void 0, void 0, function () {
343
- return __generator(this, function (_a) {
344
- return [2 /*return*/, getIosModule().finishTransaction(purchase.transactionId)];
345
- });
346
- }); },
347
- android: function () { return __awaiter(void 0, void 0, void 0, function () {
348
- return __generator(this, function (_a) {
349
- if (purchase) {
350
- if (isConsumable) {
351
- return [2 /*return*/, getAndroidModule().consumeProduct(purchase.purchaseToken, developerPayloadAndroid)];
352
- }
353
- else if (purchase.userIdAmazon ||
354
- (!purchase.isAcknowledgedAndroid &&
355
- purchase.purchaseStateAndroid === PurchaseStateAndroid.PURCHASED)) {
356
- return [2 /*return*/, getAndroidModule().acknowledgePurchase(purchase.purchaseToken, developerPayloadAndroid)];
357
- }
358
- else {
359
- throw new Error('purchase is not suitable to be purchased');
360
- }
361
- }
362
- else {
363
- throw new Error('purchase is not assigned');
364
- }
365
- return [2 /*return*/];
366
- });
367
- }); },
368
- }) || Promise.resolve)();
369
- };
370
- /**
371
- * Clear Transaction (iOS only)
372
- * Finish remaining transactions. Related to issue #257 and #801
373
- * link : https://github.com/dooboolab/react-native-iap/issues/257
374
- * https://github.com/dooboolab/react-native-iap/issues/801
375
- * @returns {Promise<void>}
376
- */
377
- export var clearTransactionIOS = function () {
378
- return getIosModule().clearTransaction();
379
- };
380
- /**
381
- * Clear valid Products (iOS only)
382
- * Remove all products which are validated by Apple server.
383
- * @returns {void}
384
- */
385
- export var clearProductsIOS = function () {
386
- return getIosModule().clearProducts();
387
- };
388
- /**
389
- * Acknowledge a product (on Android.) No-op on iOS.
390
- * @param {string} token The product's token (on Android)
391
- * @returns {Promise<PurchaseResult | void>}
392
- */
393
- export var acknowledgePurchaseAndroid = function (token, developerPayload) {
394
- return getAndroidModule().acknowledgePurchase(token, developerPayload);
395
- };
396
- /**
397
- * Deep link to subscriptions screen on Android. No-op on iOS.
398
- * @param {string} sku The product's SKU (on Android)
399
- * @returns {Promise<void>}
400
- */
401
- export var deepLinkToSubscriptionsAndroid = function (sku) { return __awaiter(void 0, void 0, void 0, function () {
402
- var _a, _b, _c;
403
- return __generator(this, function (_d) {
404
- switch (_d.label) {
405
- case 0:
406
- checkNativeAndroidAvailable();
407
- _b = (_a = Linking).openURL;
408
- _c = "https://play.google.com/store/account/subscriptions?package=".concat;
409
- return [4 /*yield*/, RNIapModule.getPackageName()];
410
- case 1: return [2 /*return*/, _b.apply(_a, [_c.apply("https://play.google.com/store/account/subscriptions?package=", [_d.sent(), "&sku="]).concat(sku)])];
411
- }
412
- });
413
- }); };
414
- /**
415
- * Should Add Store Payment (iOS only)
416
- * Indicates the the App Store purchase should continue from the app instead of the App Store.
417
- * @returns {Promise<Product | null>} promoted product
418
- */
419
- export var getPromotedProductIOS = function () {
420
- return getIosModule().promotedProduct();
421
- };
422
- /**
423
- * Buy the currently selected promoted product (iOS only)
424
- * Initiates the payment process for a promoted product. Should only be called in response to the `iap-promoted-product` event.
425
- * @returns {Promise<void>}
426
- */
427
- export var buyPromotedProductIOS = function () {
428
- return getIosModule().buyPromotedProduct();
429
- };
430
- var fetchJsonOrThrow = function (url, receiptBody) { return __awaiter(void 0, void 0, void 0, function () {
431
- var response;
432
- return __generator(this, function (_a) {
433
- switch (_a.label) {
434
- case 0: return [4 /*yield*/, fetch(url, {
435
- method: 'POST',
436
- headers: {
437
- Accept: 'application/json',
438
- 'Content-Type': 'application/json',
439
- },
440
- body: JSON.stringify(receiptBody),
441
- })];
442
- case 1:
443
- response = _a.sent();
444
- if (!response.ok) {
445
- throw Object.assign(new Error(response.statusText), {
446
- statusCode: response.status,
447
- });
448
- }
449
- return [2 /*return*/, response.json()];
450
- }
451
- });
452
- }); };
453
- var requestAgnosticReceiptValidationIos = function (receiptBody) { return __awaiter(void 0, void 0, void 0, function () {
454
- var response, testResponse;
455
- return __generator(this, function (_a) {
456
- switch (_a.label) {
457
- case 0: return [4 /*yield*/, fetchJsonOrThrow('https://buy.itunes.apple.com/verifyReceipt', receiptBody)];
458
- case 1:
459
- response = _a.sent();
460
- if (!(response &&
461
- response.status === Apple.ReceiptValidationStatus.TEST_RECEIPT)) return [3 /*break*/, 3];
462
- return [4 /*yield*/, fetchJsonOrThrow('https://sandbox.itunes.apple.com/verifyReceipt', receiptBody)];
463
- case 2:
464
- testResponse = _a.sent();
465
- return [2 /*return*/, testResponse];
466
- case 3: return [2 /*return*/, response];
467
- }
468
- });
469
- }); };
470
- /**
471
- * Buy products or subscriptions with offers (iOS only)
472
- *
473
- * Runs the payment process with some info you must fetch
474
- * from your server.
475
- * @param {string} sku The product identifier
476
- * @param {string} forUser An user identifier on you system
477
- * @param {Apple.PaymentDiscount} withOffer The offer information
478
- * @param {string} withOffer.identifier The offer identifier
479
- * @param {string} withOffer.keyIdentifier Key identifier that it uses to generate the signature
480
- * @param {string} withOffer.nonce An UUID returned from the server
481
- * @param {string} withOffer.signature The actual signature returned from the server
482
- * @param {number} withOffer.timestamp The timestamp of the signature
483
- * @returns {Promise<void>}
484
- */
485
- export var requestPurchaseWithOfferIOS = function (sku, forUser, withOffer) { return getIosModule().buyProductWithOffer(sku, forUser, withOffer); };
486
- /**
487
- * Validate receipt for iOS.
488
- * @param {object} receiptBody the receipt body to send to apple server.
489
- * @param {boolean} isTest whether this is in test environment which is sandbox.
490
- * @returns {Promise<Apple.ReceiptValidationResponse | false>}
491
- */
492
- export var validateReceiptIos = function (receiptBody, isTest) { return __awaiter(void 0, void 0, void 0, function () {
493
- var url, response;
494
- return __generator(this, function (_a) {
495
- switch (_a.label) {
496
- case 0:
497
- if (!(isTest == null)) return [3 /*break*/, 2];
498
- return [4 /*yield*/, requestAgnosticReceiptValidationIos(receiptBody)];
499
- case 1: return [2 /*return*/, _a.sent()];
500
- case 2:
501
- url = isTest
502
- ? 'https://sandbox.itunes.apple.com/verifyReceipt'
503
- : 'https://buy.itunes.apple.com/verifyReceipt';
504
- return [4 /*yield*/, fetchJsonOrThrow(url, receiptBody)];
505
- case 3:
506
- response = _a.sent();
507
- return [2 /*return*/, response];
508
- }
509
- });
510
- }); };
511
- /**
512
- * Validate receipt for Android. NOTE: This method is here for debugging purposes only. Including
513
- * your access token in the binary you ship to users is potentially dangerous.
514
- * Use server side validation instead for your production builds
515
- * @param {string} packageName package name of your app.
516
- * @param {string} productId product id for your in app product.
517
- * @param {string} productToken token for your purchase.
518
- * @param {string} accessToken accessToken from googleApis.
519
- * @param {boolean} isSub whether this is subscription or inapp. `true` for subscription.
520
- * @returns {Promise<object>}
521
- */
522
- export var validateReceiptAndroid = function (packageName, productId, productToken, accessToken, isSub) { return __awaiter(void 0, void 0, void 0, function () {
523
- var type, url, response;
524
- return __generator(this, function (_a) {
525
- switch (_a.label) {
526
- case 0:
527
- type = isSub ? 'subscriptions' : 'products';
528
- url = 'https://androidpublisher.googleapis.com/androidpublisher/v3/applications' +
529
- "/".concat(packageName, "/purchases/").concat(type, "/").concat(productId) +
530
- "/tokens/".concat(productToken, "?access_token=").concat(accessToken);
531
- return [4 /*yield*/, fetch(url, {
532
- method: 'GET',
533
- headers: {
534
- 'Content-Type': 'application/json',
535
- },
536
- })];
537
- case 1:
538
- response = _a.sent();
539
- if (!response.ok) {
540
- throw Object.assign(new Error(response.statusText), {
541
- statusCode: response.status,
542
- });
543
- }
544
- return [2 /*return*/, response.json()];
545
- }
546
- });
547
- }); };
548
- /**
549
- * Validate receipt for Amazon. NOTE: This method is here for debugging purposes only. Including
550
- * your developer secret in the binary you ship to users is potentially dangerous.
551
- * Use server side validation instead for your production builds
552
- * @param {string} developerSecret: from the Amazon developer console.
553
- * @param {string} userId who purchased the item.
554
- * @param {string} receiptId long obfuscated string returned when purchasing the item
555
- * @param {boolean} useSandbox Defaults to true, use sandbox environment or production.
556
- * @returns {Promise<object>}
557
- */
558
- export var validateReceiptAmazon = function (developerSecret, userId, receiptId, useSandbox) {
559
- if (useSandbox === void 0) { useSandbox = true; }
560
- return __awaiter(void 0, void 0, void 0, function () {
561
- var sandBoxUrl, url, response;
562
- return __generator(this, function (_a) {
563
- switch (_a.label) {
564
- case 0:
565
- sandBoxUrl = useSandbox ? 'sandbox/' : '';
566
- url = "https://appstore-sdk.amazon.com/".concat(sandBoxUrl, "version/1.0/verifyReceiptId/developer/").concat(developerSecret, "/user/").concat(userId, "/receiptId/").concat(receiptId);
567
- return [4 /*yield*/, fetch(url, {
568
- method: 'GET',
569
- headers: {
570
- 'Content-Type': 'application/json',
571
- },
572
- })];
573
- case 1:
574
- response = _a.sent();
575
- if (!response.ok) {
576
- throw Object.assign(new Error(response.statusText), {
577
- statusCode: response.status,
578
- });
579
- }
580
- return [2 /*return*/, response.json()];
581
- }
582
- });
583
- });
584
- };
585
- /**
586
- * Add IAP purchase event
587
- * @returns {callback(e: InAppPurchase | ProductPurchase)}
588
- */
589
- export var purchaseUpdatedListener = function (listener) {
590
- var myModuleEvt = new NativeEventEmitter(getNativeModule());
591
- var emitterSubscription = myModuleEvt.addListener('purchase-updated', listener);
592
- if (Platform.OS === 'android') {
593
- getAndroidModule().startListening();
594
- }
595
- return emitterSubscription;
596
- };
597
- /**
598
- * Add IAP purchase error event
599
- * @returns {callback(e: PurchaseError)}
600
- */
601
- export var purchaseErrorListener = function (listener) {
602
- return new NativeEventEmitter(getNativeModule()).addListener('purchase-error', listener);
603
- };
604
- /**
605
- * Get the current receipt base64 encoded in IOS.
606
- * @param {forceRefresh?:boolean}
607
- * @returns {Promise<string>}
608
- */
609
- export var getReceiptIOS = function (forceRefresh) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
610
- return [2 /*return*/, getIosModule().requestReceipt(forceRefresh !== null && forceRefresh !== void 0 ? forceRefresh : false)];
611
- }); }); };
612
- /**
613
- * Get the pending purchases in IOS.
614
- * @returns {Promise<ProductPurchase[]>}
615
- */
616
- export var getPendingPurchasesIOS = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
617
- return [2 /*return*/, getIosModule().getPendingTransactions()];
618
- }); }); };
619
- /**
620
- * Launches a modal to register the redeem offer code in IOS.
621
- * @returns {Promise<null>}
622
- */
623
- export var presentCodeRedemptionSheetIOS = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
624
- return [2 /*return*/, getIosModule().presentCodeRedemptionSheet()];
625
- }); }); };
package/src/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './types';
2
- export * from './hooks/useIAP';
3
- export * from './hooks/withIAPContext';
4
- export * from './iap';
package/src/index.js DELETED
@@ -1,4 +0,0 @@
1
- export * from './types';
2
- export * from './hooks/useIAP';
3
- export * from './hooks/withIAPContext';
4
- export * from './iap';
@@ -1,23 +0,0 @@
1
- /**
2
- * From: https://developer.amazon.com/es/docs/in-app-purchasing/iap-rvs-examples.html
3
- */
4
- export declare type ReceiptType = {
5
- autoRenewing: boolean;
6
- betaProduct: boolean;
7
- cancelDate: number | null;
8
- cancelReason: string;
9
- deferredDate: number | null;
10
- deferredSku: number | null;
11
- freeTrialEndDate: number;
12
- gracePeriodEndDate: number;
13
- parentProductId: string;
14
- productId: string;
15
- productType: string;
16
- purchaseDate: number;
17
- quantity: number;
18
- receiptId: string;
19
- renewalDate: number;
20
- term: string;
21
- termSku: string;
22
- testTransaction: boolean;
23
- } & Record<string, unknown>;
@@ -1 +0,0 @@
1
- export {};