react-native-iap 9.0.0-beta → 9.0.0-beta10

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