expo-iap 1.0.3 → 2.0.0-rc.1

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