react-native-purchases 4.6.1 → 5.0.0-beta.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/README.md +11 -19
- package/RNPurchases.podspec +2 -2
- package/android/build.gradle +2 -2
- package/android/build.gradle.bck +126 -0
- package/android/gradle.properties +1 -1
- package/android/src/main/java/com/revenuecat/purchases/react/RNPurchasesModule.java +24 -43
- package/android/src/main/java/com/revenuecat/purchases/react/RNPurchasesModule.java.bck +379 -0
- package/dist/{purchaserInfo.d.ts → customerInfo.d.ts} +4 -5
- package/dist/{purchaserInfo.js → customerInfo.js} +0 -0
- package/dist/errors.d.ts +3 -0
- package/dist/errors.js +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/offerings.d.ts +12 -44
- package/dist/offerings.js +4 -0
- package/dist/purchases.d.ts +67 -114
- package/dist/purchases.js +61 -163
- package/ios/RNPurchases.h +2 -2
- package/ios/RNPurchases.m +42 -74
- package/ios/RNPurchases.m.bck +343 -0
- package/package.json +5 -6
- package/scripts/{build.js → build.js.bck} +0 -0
- package/scripts/docs/index.html +9 -0
- package/scripts/docs/index.html.bck +9 -0
- package/scripts/setupJest.js +253 -243
- package/scripts/download-purchases-common.sh +0 -39
- package/scripts/download-purchases-framework.sh +0 -39
package/dist/purchases.js
CHANGED
|
@@ -36,17 +36,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.BILLING_FEATURE = exports.PURCHASE_TYPE =
|
|
39
|
+
exports.BILLING_FEATURE = exports.PURCHASE_TYPE = void 0;
|
|
40
40
|
var react_native_1 = require("react-native");
|
|
41
41
|
var errors_1 = require("./errors");
|
|
42
42
|
var offerings_1 = require("./offerings");
|
|
43
43
|
var react_native_2 = require("react-native");
|
|
44
44
|
var RNPurchases = react_native_1.NativeModules.RNPurchases;
|
|
45
45
|
var eventEmitter = new react_native_1.NativeEventEmitter(RNPurchases);
|
|
46
|
-
var
|
|
46
|
+
var customerInfoUpdateListeners = [];
|
|
47
47
|
var shouldPurchasePromoProductListeners = [];
|
|
48
|
-
eventEmitter.addListener("Purchases-
|
|
49
|
-
|
|
48
|
+
eventEmitter.addListener("Purchases-CustomerInfoUpdated", function (customerInfo) {
|
|
49
|
+
customerInfoUpdateListeners.forEach(function (listener) { return listener(customerInfo); });
|
|
50
50
|
});
|
|
51
51
|
eventEmitter.addListener("Purchases-ShouldPurchasePromoProduct", function (_a) {
|
|
52
52
|
var callbackID = _a.callbackID;
|
|
@@ -54,15 +54,6 @@ eventEmitter.addListener("Purchases-ShouldPurchasePromoProduct", function (_a) {
|
|
|
54
54
|
return listener(function () { return RNPurchases.makeDeferredPurchase(callbackID); });
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
|
-
var ATTRIBUTION_NETWORK;
|
|
58
|
-
(function (ATTRIBUTION_NETWORK) {
|
|
59
|
-
ATTRIBUTION_NETWORK[ATTRIBUTION_NETWORK["APPLE_SEARCH_ADS"] = 0] = "APPLE_SEARCH_ADS";
|
|
60
|
-
ATTRIBUTION_NETWORK[ATTRIBUTION_NETWORK["ADJUST"] = 1] = "ADJUST";
|
|
61
|
-
ATTRIBUTION_NETWORK[ATTRIBUTION_NETWORK["APPSFLYER"] = 2] = "APPSFLYER";
|
|
62
|
-
ATTRIBUTION_NETWORK[ATTRIBUTION_NETWORK["BRANCH"] = 3] = "BRANCH";
|
|
63
|
-
ATTRIBUTION_NETWORK[ATTRIBUTION_NETWORK["TENJIN"] = 4] = "TENJIN";
|
|
64
|
-
ATTRIBUTION_NETWORK[ATTRIBUTION_NETWORK["FACEBOOK"] = 5] = "FACEBOOK";
|
|
65
|
-
})(ATTRIBUTION_NETWORK = exports.ATTRIBUTION_NETWORK || (exports.ATTRIBUTION_NETWORK = {}));
|
|
66
57
|
var PURCHASE_TYPE;
|
|
67
58
|
(function (PURCHASE_TYPE) {
|
|
68
59
|
/**
|
|
@@ -109,17 +100,22 @@ var Purchases = /** @class */ (function () {
|
|
|
109
100
|
* Sets up Purchases with your API key and an app user id.
|
|
110
101
|
* @param {String} apiKey RevenueCat API Key. Needs to be a String
|
|
111
102
|
* @param {String?} appUserID An optional unique id for identifying the user. Needs to be a string.
|
|
112
|
-
* @param {boolean
|
|
103
|
+
* @param {boolean} [observerMode=false] An optional boolean. Set this to TRUE if you have your own IAP implementation and want to use only RevenueCat's backend. Default is FALSE.
|
|
104
|
+
* @param {boolean} [usesStoreKit2IfAvailable=false] An optional boolean. iOS-only. Set this to TRUE to enable StoreKit2 on compatible devices.
|
|
105
|
+
* @param {boolean} [useAmazon=false] An optional boolean. Android-only. Set this to TRUE to enable Amazon on compatible devices.
|
|
113
106
|
* @param {String?} userDefaultsSuiteName An optional string. iOS-only, will be ignored for Android.
|
|
114
107
|
* Set this if you would like the RevenueCat SDK to store its preferences in a different NSUserDefaults suite, otherwise it will use standardUserDefaults.
|
|
115
108
|
* Default is null, which will make the SDK use standardUserDefaults.
|
|
116
109
|
*/
|
|
117
|
-
Purchases.
|
|
118
|
-
|
|
110
|
+
Purchases.configure = function (_a) {
|
|
111
|
+
var apiKey = _a.apiKey, _b = _a.appUserID, appUserID = _b === void 0 ? null : _b, _c = _a.observerMode, observerMode = _c === void 0 ? false : _c, userDefaultsSuiteName = _a.userDefaultsSuiteName, _d = _a.usesStoreKit2IfAvailable, usesStoreKit2IfAvailable = _d === void 0 ? false : _d, _e = _a.useAmazon, useAmazon = _e === void 0 ? false : _e;
|
|
112
|
+
if (apiKey === undefined || typeof apiKey !== "string") {
|
|
113
|
+
throw new Error("Invalid API key. It must be called with an Object: configure({apiKey: \"key\"})");
|
|
114
|
+
}
|
|
119
115
|
if (appUserID !== null && typeof appUserID !== "undefined" && typeof appUserID !== "string") {
|
|
120
116
|
throw new Error("appUserID needs to be a string");
|
|
121
117
|
}
|
|
122
|
-
RNPurchases.setupPurchases(apiKey, appUserID, observerMode, userDefaultsSuiteName);
|
|
118
|
+
RNPurchases.setupPurchases(apiKey, appUserID, observerMode, userDefaultsSuiteName, usesStoreKit2IfAvailable, useAmazon);
|
|
123
119
|
};
|
|
124
120
|
/**
|
|
125
121
|
* @deprecated, configure behavior through the RevenueCat dashboard instead.
|
|
@@ -177,23 +173,23 @@ var Purchases = /** @class */ (function () {
|
|
|
177
173
|
});
|
|
178
174
|
};
|
|
179
175
|
/**
|
|
180
|
-
* Sets a function to be called on updated
|
|
181
|
-
* @param {
|
|
176
|
+
* Sets a function to be called on updated customer info
|
|
177
|
+
* @param {CustomerInfoUpdateListener} customerInfoUpdateListener CustomerInfo update listener
|
|
182
178
|
*/
|
|
183
|
-
Purchases.
|
|
184
|
-
if (typeof
|
|
185
|
-
throw new Error("
|
|
179
|
+
Purchases.addCustomerInfoUpdateListener = function (customerInfoUpdateListener) {
|
|
180
|
+
if (typeof customerInfoUpdateListener !== "function") {
|
|
181
|
+
throw new Error("addCustomerInfoUpdateListener needs a function");
|
|
186
182
|
}
|
|
187
|
-
|
|
183
|
+
customerInfoUpdateListeners.push(customerInfoUpdateListener);
|
|
188
184
|
};
|
|
189
185
|
/**
|
|
190
|
-
* Removes a given
|
|
191
|
-
* @param {
|
|
186
|
+
* Removes a given CustomerInfoUpdateListener
|
|
187
|
+
* @param {CustomerInfoUpdateListener} listenerToRemove CustomerInfoUpdateListener reference of the listener to remove
|
|
192
188
|
* @returns {boolean} True if listener was removed, false otherwise
|
|
193
189
|
*/
|
|
194
|
-
Purchases.
|
|
195
|
-
if (
|
|
196
|
-
|
|
190
|
+
Purchases.removeCustomerInfoUpdateListener = function (listenerToRemove) {
|
|
191
|
+
if (customerInfoUpdateListeners.includes(listenerToRemove)) {
|
|
192
|
+
customerInfoUpdateListeners = customerInfoUpdateListeners.filter(function (listener) { return listenerToRemove !== listener; });
|
|
197
193
|
return true;
|
|
198
194
|
}
|
|
199
195
|
return false;
|
|
@@ -226,23 +222,6 @@ var Purchases = /** @class */ (function () {
|
|
|
226
222
|
}
|
|
227
223
|
return false;
|
|
228
224
|
};
|
|
229
|
-
/**
|
|
230
|
-
* @deprecated, use set<NetworkId> methods instead.
|
|
231
|
-
*
|
|
232
|
-
* Add a dict of attribution information
|
|
233
|
-
* @param {Dict} data Attribution data from AppsFlyer, Adjust, or Branch
|
|
234
|
-
* @param {ATTRIBUTION_NETWORKS} network Which network, see Purchases.ATTRIBUTION_NETWORKS
|
|
235
|
-
* @param {String?} networkUserId An optional unique id for identifying the user. Needs to be a string.
|
|
236
|
-
* @returns {Promise<void>} The promise will be rejected if setup has not been called yet.
|
|
237
|
-
*/
|
|
238
|
-
Purchases.addAttributionData = function (data, network, networkUserId) {
|
|
239
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
240
|
-
return __generator(this, function (_a) {
|
|
241
|
-
RNPurchases.addAttributionData(data, network, networkUserId);
|
|
242
|
-
return [2 /*return*/];
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
};
|
|
246
225
|
/**
|
|
247
226
|
* Gets the map of entitlements -> offerings -> products
|
|
248
227
|
* @returns {Promise<PurchasesOfferings>} Promise of entitlements structure. The promise will be rejected if setup
|
|
@@ -264,7 +243,7 @@ var Purchases = /** @class */ (function () {
|
|
|
264
243
|
* Fetch the product info
|
|
265
244
|
* @param {String[]} productIdentifiers Array of product identifiers
|
|
266
245
|
* @param {String} type Optional type of products to fetch, can be inapp or subs. Subs by default
|
|
267
|
-
* @returns {Promise<
|
|
246
|
+
* @returns {Promise<PurchasesStoreProduct[]>} A promise containing an array of products. The promise will be rejected
|
|
268
247
|
* if the products are not properly configured in RevenueCat or if there is another error retrieving them.
|
|
269
248
|
* Rejections return an error code, and a userInfo object with more information. The promise will also be rejected
|
|
270
249
|
* if setup has not been called yet.
|
|
@@ -289,8 +268,8 @@ var Purchases = /** @class */ (function () {
|
|
|
289
268
|
* @param {UpgradeInfo} upgradeInfo Android only. Optional UpgradeInfo you wish to upgrade from containing the oldSKU
|
|
290
269
|
* and the optional prorationMode.
|
|
291
270
|
* @param {String} type Optional type of product, can be inapp or subs. Subs by default
|
|
292
|
-
* @returns {Promise<{ productIdentifier: string,
|
|
293
|
-
* a
|
|
271
|
+
* @returns {Promise<{ productIdentifier: string, customerInfo:CustomerInfo }>} A promise of an object containing
|
|
272
|
+
* a customer info object and a product identifier. Rejections return an error code,
|
|
294
273
|
* a boolean indicating if the user cancelled the purchase, and an object with more information. The promise will
|
|
295
274
|
* also be rejected if setup has not been called yet.
|
|
296
275
|
*/
|
|
@@ -313,10 +292,10 @@ var Purchases = /** @class */ (function () {
|
|
|
313
292
|
/**
|
|
314
293
|
* iOS only. Purchase a product applying a given discount.
|
|
315
294
|
*
|
|
316
|
-
* @param {
|
|
317
|
-
* @param {
|
|
318
|
-
* @returns {Promise<{ productIdentifier: string,
|
|
319
|
-
* a
|
|
295
|
+
* @param {PurchasesStoreProduct} product The product you want to purchase
|
|
296
|
+
* @param {PurchasesPromotionalOffer} discount Discount to apply to this package. Retrieve this discount using getPromotionalOffer.
|
|
297
|
+
* @returns {Promise<{ productIdentifier: string, customerInfo:CustomerInfo }>} A promise of an object containing
|
|
298
|
+
* a customer info object and a product identifier. Rejections return an error code,
|
|
320
299
|
* a boolean indicating if the user cancelled the purchase, and an object with more information. The promise will be
|
|
321
300
|
* rejected if setup has not been called yet.
|
|
322
301
|
*/
|
|
@@ -344,8 +323,8 @@ var Purchases = /** @class */ (function () {
|
|
|
344
323
|
* @param {PurchasesPackage} aPackage The Package you wish to purchase. You can get the Packages by calling getOfferings
|
|
345
324
|
* @param {UpgradeInfo} upgradeInfo Android only. Optional UpgradeInfo you wish to upgrade from containing the oldSKU
|
|
346
325
|
* and the optional prorationMode.
|
|
347
|
-
* @returns {Promise<{ productIdentifier: string,
|
|
348
|
-
* a
|
|
326
|
+
* @returns {Promise<{ productIdentifier: string, customerInfo: CustomerInfo }>} A promise of an object containing
|
|
327
|
+
* a customer info object and a product identifier. Rejections return an error code, a boolean indicating if the
|
|
349
328
|
* user cancelled the purchase, and an object with more information. The promise will be also be rejected if setup
|
|
350
329
|
* has not been called yet.
|
|
351
330
|
*/
|
|
@@ -368,9 +347,9 @@ var Purchases = /** @class */ (function () {
|
|
|
368
347
|
* iOS only. Purchase a package applying a given discount.
|
|
369
348
|
*
|
|
370
349
|
* @param {PurchasesPackage} aPackage The Package you wish to purchase. You can get the Packages by calling getOfferings
|
|
371
|
-
* @param {
|
|
372
|
-
* @returns {Promise<{ productIdentifier: string,
|
|
373
|
-
* a
|
|
350
|
+
* @param {PurchasesPromotionalOffer} discount Discount to apply to this package. Retrieve this discount using getPromotionalOffer.
|
|
351
|
+
* @returns {Promise<{ productIdentifier: string, customerInfo: CustomerInfo }>} A promise of an object containing
|
|
352
|
+
* a customer info object and a product identifier. Rejections return an error code, a boolean indicating if the
|
|
374
353
|
* user cancelled the purchase, and an object with more information. The promise will be also be rejected if setup
|
|
375
354
|
* has not been called yet.
|
|
376
355
|
*/
|
|
@@ -394,17 +373,17 @@ var Purchases = /** @class */ (function () {
|
|
|
394
373
|
};
|
|
395
374
|
/**
|
|
396
375
|
* Restores a user's previous purchases and links their appUserIDs to any user's also using those purchases.
|
|
397
|
-
* @returns {Promise<
|
|
376
|
+
* @returns {Promise<CustomerInfo>} A promise of a customer info object. Rejections return an error code, and an
|
|
398
377
|
* userInfo object with more information. The promise will be also be rejected if setup has not been called yet.
|
|
399
378
|
*/
|
|
400
|
-
Purchases.
|
|
379
|
+
Purchases.restorePurchases = function () {
|
|
401
380
|
return __awaiter(this, void 0, void 0, function () {
|
|
402
381
|
return __generator(this, function (_a) {
|
|
403
382
|
switch (_a.label) {
|
|
404
383
|
case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
|
|
405
384
|
case 1:
|
|
406
385
|
_a.sent();
|
|
407
|
-
return [2 /*return*/, RNPurchases.
|
|
386
|
+
return [2 /*return*/, RNPurchases.restorePurchases()];
|
|
408
387
|
}
|
|
409
388
|
});
|
|
410
389
|
});
|
|
@@ -429,7 +408,7 @@ var Purchases = /** @class */ (function () {
|
|
|
429
408
|
* This function will logIn the current user with an appUserID. Typically this would be used after a log in
|
|
430
409
|
* to identify a user without calling configure.
|
|
431
410
|
* @param {String} appUserID The appUserID that should be linked to the currently user
|
|
432
|
-
* @returns {Promise<LogInResult>} A promise of an object that contains the
|
|
411
|
+
* @returns {Promise<LogInResult>} A promise of an object that contains the customerInfo after logging in, as well
|
|
433
412
|
* as a boolean indicating whether the user has just been created for the first time in the RevenueCat backend. The
|
|
434
413
|
* promise will be rejected if setup has not been called yet or if there's an issue logging in.
|
|
435
414
|
*/
|
|
@@ -451,7 +430,7 @@ var Purchases = /** @class */ (function () {
|
|
|
451
430
|
};
|
|
452
431
|
/**
|
|
453
432
|
* Logs out the Purchases client clearing the saved appUserID. This will generate a random user id and save it in the cache.
|
|
454
|
-
* @returns {Promise<
|
|
433
|
+
* @returns {Promise<CustomerInfo>} A promise of a customer info object. Rejections return an error code,
|
|
455
434
|
* and a userInfo object with more information. The promise will be rejected if setup has not been called yet or if
|
|
456
435
|
* there's an issue logging out.
|
|
457
436
|
*/
|
|
@@ -467,76 +446,6 @@ var Purchases = /** @class */ (function () {
|
|
|
467
446
|
});
|
|
468
447
|
});
|
|
469
448
|
};
|
|
470
|
-
/**
|
|
471
|
-
* @deprecated, use logIn instead.
|
|
472
|
-
* This function will alias two appUserIDs together.
|
|
473
|
-
* @param {String} newAppUserID The new appUserID that should be linked to the currently identified appUserID.
|
|
474
|
-
* Needs to be a string.
|
|
475
|
-
* @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and a
|
|
476
|
-
* userInfo object with more information. The promise will be rejected if setup has not been called yet or if
|
|
477
|
-
* there's an issue creating the alias.
|
|
478
|
-
*/
|
|
479
|
-
Purchases.createAlias = function (newAppUserID) {
|
|
480
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
481
|
-
return __generator(this, function (_a) {
|
|
482
|
-
switch (_a.label) {
|
|
483
|
-
case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
|
|
484
|
-
case 1:
|
|
485
|
-
_a.sent();
|
|
486
|
-
// noinspection SuspiciousTypeOfGuard
|
|
487
|
-
if (typeof newAppUserID !== "string") {
|
|
488
|
-
throw new Error("newAppUserID needs to be a string");
|
|
489
|
-
}
|
|
490
|
-
return [2 /*return*/, RNPurchases.createAlias(newAppUserID)];
|
|
491
|
-
}
|
|
492
|
-
});
|
|
493
|
-
});
|
|
494
|
-
};
|
|
495
|
-
/**
|
|
496
|
-
* @deprecated, use logIn instead.
|
|
497
|
-
* This function will identify the current user with an appUserID. Typically this would be used after a logout to
|
|
498
|
-
* identify a new user without calling configure
|
|
499
|
-
* @param {String} newAppUserID The appUserID that should be linked to the currently user
|
|
500
|
-
* @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and an
|
|
501
|
-
* userInfo object with more information. The promise will be rejected if setup has not been called yet or if
|
|
502
|
-
* there's an issue identifying the user.
|
|
503
|
-
*/
|
|
504
|
-
Purchases.identify = function (newAppUserID) {
|
|
505
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
506
|
-
return __generator(this, function (_a) {
|
|
507
|
-
switch (_a.label) {
|
|
508
|
-
case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
|
|
509
|
-
case 1:
|
|
510
|
-
_a.sent();
|
|
511
|
-
// noinspection SuspiciousTypeOfGuard
|
|
512
|
-
if (typeof newAppUserID !== "string") {
|
|
513
|
-
throw new Error("newAppUserID needs to be a string");
|
|
514
|
-
}
|
|
515
|
-
return [2 /*return*/, RNPurchases.identify(newAppUserID)];
|
|
516
|
-
}
|
|
517
|
-
});
|
|
518
|
-
});
|
|
519
|
-
};
|
|
520
|
-
/**
|
|
521
|
-
* @deprecated, use logOut instead.
|
|
522
|
-
* Resets the Purchases client clearing the saved appUserID. This will generate a random user id and save it in the
|
|
523
|
-
* cache.
|
|
524
|
-
* @returns {Promise<PurchaserInfo>} A promise of a purchaser info object. Rejections return an error code, and an
|
|
525
|
-
* userInfo object with more information. The promise will be rejected if setup has not been called yet or if
|
|
526
|
-
* there's an issue resetting the user.
|
|
527
|
-
*/
|
|
528
|
-
Purchases.reset = function () {
|
|
529
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
530
|
-
return __generator(this, function (_a) {
|
|
531
|
-
switch (_a.label) {
|
|
532
|
-
case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
|
|
533
|
-
case 1:
|
|
534
|
-
_a.sent();
|
|
535
|
-
return [2 /*return*/, RNPurchases.reset()];
|
|
536
|
-
}
|
|
537
|
-
});
|
|
538
|
-
});
|
|
539
|
-
};
|
|
540
449
|
/**
|
|
541
450
|
* Enables/Disables debugs logs
|
|
542
451
|
* @param {boolean} enabled Enable or not debug logs
|
|
@@ -550,19 +459,19 @@ var Purchases = /** @class */ (function () {
|
|
|
550
459
|
});
|
|
551
460
|
};
|
|
552
461
|
/**
|
|
553
|
-
* Gets current
|
|
554
|
-
* @returns {Promise<
|
|
462
|
+
* Gets current customer info
|
|
463
|
+
* @returns {Promise<CustomerInfo>} A promise of a customer info object. Rejections return an error code, and an
|
|
555
464
|
* userInfo object with more information. The promise will be rejected if setup has not been called yet or if
|
|
556
|
-
* there's an issue getting the
|
|
465
|
+
* there's an issue getting the customer information.
|
|
557
466
|
*/
|
|
558
|
-
Purchases.
|
|
467
|
+
Purchases.getCustomerInfo = function () {
|
|
559
468
|
return __awaiter(this, void 0, void 0, function () {
|
|
560
469
|
return __generator(this, function (_a) {
|
|
561
470
|
switch (_a.label) {
|
|
562
471
|
case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
|
|
563
472
|
case 1:
|
|
564
473
|
_a.sent();
|
|
565
|
-
return [2 /*return*/, RNPurchases.
|
|
474
|
+
return [2 /*return*/, RNPurchases.getCustomerInfo()];
|
|
566
475
|
}
|
|
567
476
|
});
|
|
568
477
|
});
|
|
@@ -647,15 +556,15 @@ var Purchases = /** @class */ (function () {
|
|
|
647
556
|
});
|
|
648
557
|
};
|
|
649
558
|
/**
|
|
650
|
-
* iOS only. Use this function to retrieve the `
|
|
559
|
+
* iOS only. Use this function to retrieve the `PurchasesPromotionalOffer` for a given `PurchasesPackage`.
|
|
651
560
|
*
|
|
652
561
|
* @param product The `PurchasesProduct` the user intends to purchase.
|
|
653
562
|
* @param discount The `PurchasesDiscount` to apply to the product.
|
|
654
|
-
* @returns { Promise<
|
|
563
|
+
* @returns { Promise<PurchasesPromotionalOffer> } Returns when the `PurchasesPaymentDiscount` is returned.
|
|
655
564
|
* Null is returned for Android and incompatible iOS versions. The promise will be rejected if setup has not been
|
|
656
565
|
* called yet or if there's an error getting the payment discount.
|
|
657
566
|
*/
|
|
658
|
-
Purchases.
|
|
567
|
+
Purchases.getPromotionalOffer = function (product, discount) {
|
|
659
568
|
return __awaiter(this, void 0, void 0, function () {
|
|
660
569
|
return __generator(this, function (_a) {
|
|
661
570
|
switch (_a.label) {
|
|
@@ -668,31 +577,31 @@ var Purchases = /** @class */ (function () {
|
|
|
668
577
|
if (typeof discount === "undefined" || discount == null) {
|
|
669
578
|
throw new Error("A discount is required");
|
|
670
579
|
}
|
|
671
|
-
return [2 /*return*/, RNPurchases.
|
|
580
|
+
return [2 /*return*/, RNPurchases.getPromotionalOffer(product.identifier, discount.identifier)];
|
|
672
581
|
}
|
|
673
582
|
});
|
|
674
583
|
});
|
|
675
584
|
};
|
|
676
585
|
/**
|
|
677
|
-
* Invalidates the cache for
|
|
586
|
+
* Invalidates the cache for customer information.
|
|
678
587
|
*
|
|
679
588
|
* Most apps will not need to use this method; invalidating the cache can leave your app in an invalid state.
|
|
680
|
-
* Refer to https://docs.revenuecat.com/docs/
|
|
589
|
+
* Refer to https://docs.revenuecat.com/docs/customer-info#section-get-user-information for more information on
|
|
681
590
|
* using the cache properly.
|
|
682
591
|
*
|
|
683
|
-
* This is useful for cases where
|
|
592
|
+
* This is useful for cases where customer information might have been updated outside of the app, like if a
|
|
684
593
|
* promotional subscription is granted through the RevenueCat dashboard.
|
|
685
594
|
* @returns {Promise<void>} The promise will be rejected if setup has not been called yet or there's an error
|
|
686
|
-
* invalidating the
|
|
595
|
+
* invalidating the customer info cache.
|
|
687
596
|
*/
|
|
688
|
-
Purchases.
|
|
597
|
+
Purchases.invalidateCustomerInfoCache = function () {
|
|
689
598
|
return __awaiter(this, void 0, void 0, function () {
|
|
690
599
|
return __generator(this, function (_a) {
|
|
691
600
|
switch (_a.label) {
|
|
692
601
|
case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
|
|
693
602
|
case 1:
|
|
694
603
|
_a.sent();
|
|
695
|
-
RNPurchases.
|
|
604
|
+
RNPurchases.invalidateCustomerInfoCache();
|
|
696
605
|
return [2 /*return*/];
|
|
697
606
|
}
|
|
698
607
|
});
|
|
@@ -1116,9 +1025,9 @@ var Purchases = /** @class */ (function () {
|
|
|
1116
1025
|
* Note: Billing features are only relevant to Google Play Android users.
|
|
1117
1026
|
* For other stores and platforms, billing features won't be checked.
|
|
1118
1027
|
*
|
|
1119
|
-
* @param
|
|
1028
|
+
* @param features An array of feature types to check for support. Feature types must be one of
|
|
1120
1029
|
* [BILLING_FEATURE]. By default, is an empty list and no specific feature support will be checked.
|
|
1121
|
-
* @returns {Promise<
|
|
1030
|
+
* @returns {Promise<boolean>} promise with boolean response. True if billing is supported, false otherwise.
|
|
1122
1031
|
*/
|
|
1123
1032
|
Purchases.canMakePayments = function (features) {
|
|
1124
1033
|
if (features === void 0) { features = []; }
|
|
@@ -1148,20 +1057,6 @@ var Purchases = /** @class */ (function () {
|
|
|
1148
1057
|
});
|
|
1149
1058
|
});
|
|
1150
1059
|
};
|
|
1151
|
-
/**
|
|
1152
|
-
* Enum for attribution networks
|
|
1153
|
-
* @readonly
|
|
1154
|
-
* @enum {number}
|
|
1155
|
-
*/
|
|
1156
|
-
Purchases.ATTRIBUTION_NETWORK = ATTRIBUTION_NETWORK;
|
|
1157
|
-
/**
|
|
1158
|
-
* @deprecated use ATTRIBUTION_NETWORK instead
|
|
1159
|
-
*
|
|
1160
|
-
* Enum for attribution networks
|
|
1161
|
-
* @readonly
|
|
1162
|
-
* @enum {number}
|
|
1163
|
-
*/
|
|
1164
|
-
Purchases.ATTRIBUTION_NETWORKS = ATTRIBUTION_NETWORK;
|
|
1165
1060
|
/**
|
|
1166
1061
|
* Supported SKU types.
|
|
1167
1062
|
* @readonly
|
|
@@ -1200,6 +1095,9 @@ var Purchases = /** @class */ (function () {
|
|
|
1200
1095
|
* @enum {string}
|
|
1201
1096
|
*/
|
|
1202
1097
|
Purchases.PURCHASES_ERROR_CODE = errors_1.PURCHASES_ERROR_CODE;
|
|
1098
|
+
/**
|
|
1099
|
+
* @internal
|
|
1100
|
+
*/
|
|
1203
1101
|
Purchases.UninitializedPurchasesError = errors_1.UninitializedPurchasesError;
|
|
1204
1102
|
return Purchases;
|
|
1205
1103
|
}());
|
package/ios/RNPurchases.h
CHANGED
package/ios/RNPurchases.m
CHANGED
|
@@ -8,15 +8,17 @@
|
|
|
8
8
|
|
|
9
9
|
@import StoreKit;
|
|
10
10
|
|
|
11
|
+
typedef void (^PurchaseCompletedBlock)(RCStoreTransaction *, RCCustomerInfo *, NSError *, BOOL);
|
|
12
|
+
typedef void (^StartPurchaseBlock)(PurchaseCompletedBlock);
|
|
11
13
|
|
|
12
14
|
@interface RNPurchases () <RCPurchasesDelegate>
|
|
13
15
|
|
|
14
|
-
@property (nonatomic, retain) NSMutableArray<
|
|
16
|
+
@property (nonatomic, retain) NSMutableArray<StartPurchaseBlock> *defermentBlocks;
|
|
15
17
|
|
|
16
18
|
@end
|
|
17
19
|
|
|
18
20
|
|
|
19
|
-
NSString *
|
|
21
|
+
NSString *RNPurchasesCustomerInfoUpdatedEvent = @"Purchases-CustomerInfoUpdated";
|
|
20
22
|
NSString *RNPurchasesShouldPurchasePromoProductEvent = @"Purchases-ShouldPurchasePromoProduct";
|
|
21
23
|
|
|
22
24
|
|
|
@@ -27,7 +29,7 @@ NSString *RNPurchasesShouldPurchasePromoProductEvent = @"Purchases-ShouldPurchas
|
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
- (NSArray<NSString *> *)supportedEvents {
|
|
30
|
-
return @[
|
|
32
|
+
return @[RNPurchasesCustomerInfoUpdatedEvent, RNPurchasesShouldPurchasePromoProductEvent];
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
RCT_EXPORT_MODULE();
|
|
@@ -35,16 +37,18 @@ RCT_EXPORT_MODULE();
|
|
|
35
37
|
RCT_EXPORT_METHOD(setupPurchases:(NSString *)apiKey
|
|
36
38
|
appUserID:(nullable NSString *)appUserID
|
|
37
39
|
observerMode:(BOOL)observerMode
|
|
38
|
-
userDefaultsSuiteName:(nullable NSString *)userDefaultsSuiteName
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
userDefaultsSuiteName:(nullable NSString *)userDefaultsSuiteName
|
|
41
|
+
usesStoreKit2IfAvailable:(BOOL)usesStoreKit2IfAvailable
|
|
42
|
+
useAmazon:(BOOL)useAmazon) {
|
|
43
|
+
RCPurchases *purchases = [RCPurchases configureWithAPIKey:apiKey
|
|
44
|
+
appUserID:appUserID
|
|
45
|
+
observerMode:observerMode
|
|
46
|
+
userDefaultsSuiteName:userDefaultsSuiteName
|
|
47
|
+
platformFlavor:self.platformFlavor
|
|
48
|
+
platformFlavorVersion:self.platformFlavorVersion
|
|
49
|
+
usesStoreKit2IfAvailable:usesStoreKit2IfAvailable
|
|
50
|
+
dangerousSettings:nil];
|
|
51
|
+
purchases.delegate = self;
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
RCT_EXPORT_METHOD(setAllowSharingStoreAccount:(BOOL)allowSharingStoreAccount) {
|
|
@@ -58,15 +62,6 @@ RCT_EXPORT_METHOD(setFinishTransactions:(BOOL)finishTransactions) {
|
|
|
58
62
|
[RCCommonFunctionality setFinishTransactions:finishTransactions];
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
RCT_EXPORT_METHOD(addAttributionData:(NSDictionary *)data
|
|
62
|
-
forNetwork:(NSInteger)network
|
|
63
|
-
forNetworkUserId:(nullable NSString *)networkUserId) {
|
|
64
|
-
#pragma GCC diagnostic push
|
|
65
|
-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
66
|
-
[RCCommonFunctionality addAttributionData:data network:network networkUserId:networkUserId];
|
|
67
|
-
#pragma GCC diagnostic pop
|
|
68
|
-
}
|
|
69
|
-
|
|
70
65
|
RCT_REMAP_METHOD(getOfferings,
|
|
71
66
|
getOfferingsWithResolve:(RCTPromiseResolveBlock)resolve
|
|
72
67
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
@@ -109,11 +104,11 @@ RCT_REMAP_METHOD(purchasePackage,
|
|
|
109
104
|
completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
|
|
110
105
|
}
|
|
111
106
|
|
|
112
|
-
RCT_REMAP_METHOD(
|
|
113
|
-
|
|
107
|
+
RCT_REMAP_METHOD(restorePurchases,
|
|
108
|
+
restorePurchasesWithResolve:(RCTPromiseResolveBlock)resolve
|
|
114
109
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
115
|
-
[RCCommonFunctionality
|
|
116
|
-
|
|
110
|
+
[RCCommonFunctionality restorePurchasesWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve
|
|
111
|
+
reject:reject]];
|
|
117
112
|
}
|
|
118
113
|
|
|
119
114
|
RCT_EXPORT_METHOD(syncPurchases) {
|
|
@@ -126,13 +121,6 @@ RCT_REMAP_METHOD(getAppUserID,
|
|
|
126
121
|
resolve([RCCommonFunctionality appUserID]);
|
|
127
122
|
}
|
|
128
123
|
|
|
129
|
-
RCT_EXPORT_METHOD(createAlias:(nullable NSString *)newAppUserID
|
|
130
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
131
|
-
reject:(RCTPromiseRejectBlock)reject) {
|
|
132
|
-
[RCCommonFunctionality createAlias:newAppUserID
|
|
133
|
-
completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
124
|
RCT_EXPORT_METHOD(logIn:(nonnull NSString *)appUserID
|
|
137
125
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
138
126
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
@@ -146,25 +134,6 @@ RCT_REMAP_METHOD(logOut,
|
|
|
146
134
|
[RCCommonFunctionality logOutWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
|
|
147
135
|
}
|
|
148
136
|
|
|
149
|
-
RCT_EXPORT_METHOD(identify:(nullable NSString *)appUserID
|
|
150
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
151
|
-
reject:(RCTPromiseRejectBlock)reject) {
|
|
152
|
-
#pragma GCC diagnostic push
|
|
153
|
-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
154
|
-
[RCCommonFunctionality identify:appUserID
|
|
155
|
-
completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
|
|
156
|
-
#pragma GCC diagnostic pop
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
RCT_REMAP_METHOD(reset,
|
|
160
|
-
resetWithResolve:(RCTPromiseResolveBlock)resolve
|
|
161
|
-
reject:(RCTPromiseRejectBlock)reject) {
|
|
162
|
-
#pragma GCC diagnostic push
|
|
163
|
-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
164
|
-
[RCCommonFunctionality resetWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
|
|
165
|
-
#pragma GCC diagnostic pop
|
|
166
|
-
}
|
|
167
|
-
|
|
168
137
|
RCT_REMAP_METHOD(setDebugLogsEnabled,
|
|
169
138
|
debugLogsEnabled:(BOOL)enabled) {
|
|
170
139
|
[RCCommonFunctionality setDebugLogsEnabled:enabled];
|
|
@@ -175,10 +144,10 @@ RCT_EXPORT_METHOD(setSimulatesAskToBuyInSandbox:(BOOL)simulatesAskToBuyInSandbox
|
|
|
175
144
|
[RCCommonFunctionality setSimulatesAskToBuyInSandbox:simulatesAskToBuyInSandbox];
|
|
176
145
|
}
|
|
177
146
|
|
|
178
|
-
RCT_REMAP_METHOD(
|
|
179
|
-
|
|
147
|
+
RCT_REMAP_METHOD(getCustomerInfo,
|
|
148
|
+
customerInfoWithResolve:(RCTPromiseResolveBlock)resolve
|
|
180
149
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
181
|
-
[RCCommonFunctionality
|
|
150
|
+
[RCCommonFunctionality getCustomerInfoWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
|
|
182
151
|
}
|
|
183
152
|
|
|
184
153
|
RCT_EXPORT_METHOD(setAutomaticAppleSearchAdsAttributionCollection:(BOOL)automaticAppleSearchAdsAttributionCollection)
|
|
@@ -195,7 +164,7 @@ RCT_REMAP_METHOD(isAnonymous,
|
|
|
195
164
|
RCT_EXPORT_METHOD(makeDeferredPurchase:(nonnull NSNumber *)callbackID
|
|
196
165
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
197
166
|
reject:(RCTPromiseRejectBlock)reject) {
|
|
198
|
-
|
|
167
|
+
StartPurchaseBlock defermentBlock = [self.defermentBlocks objectAtIndex:[callbackID integerValue]];
|
|
199
168
|
[RCCommonFunctionality makeDeferredPurchase:defermentBlock
|
|
200
169
|
completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
|
|
201
170
|
}
|
|
@@ -209,19 +178,18 @@ RCT_EXPORT_METHOD(checkTrialOrIntroductoryPriceEligibility:(NSArray *)products
|
|
|
209
178
|
}];
|
|
210
179
|
}
|
|
211
180
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
discountIdentifier:(nullable NSString *)discountIdentifier
|
|
215
|
-
resolve:(RCTPromiseResolveBlock)resolve
|
|
216
|
-
reject:(RCTPromiseRejectBlock)reject) {
|
|
217
|
-
[RCCommonFunctionality paymentDiscountForProductIdentifier:productIdentifier
|
|
218
|
-
discount:discountIdentifier
|
|
219
|
-
completionBlock:[self getResponseCompletionBlockWithResolve:resolve
|
|
220
|
-
reject:reject]];
|
|
181
|
+
RCT_EXPORT_METHOD(invalidateCustomerInfoCache) {
|
|
182
|
+
[RCCommonFunctionality invalidateCustomerInfoCache];
|
|
221
183
|
}
|
|
222
184
|
|
|
223
|
-
|
|
224
|
-
|
|
185
|
+
RCT_REMAP_METHOD(getPromotionalOffer,
|
|
186
|
+
getPromotionalOfferForProductIdentifier:(NSString *)productIdentifier
|
|
187
|
+
discount:(NSString *)discount
|
|
188
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
189
|
+
reject:(RCTPromiseRejectBlock)reject) {
|
|
190
|
+
[RCCommonFunctionality promotionalOfferForProductIdentifier:productIdentifier
|
|
191
|
+
discount:discount
|
|
192
|
+
completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
|
|
225
193
|
}
|
|
226
194
|
|
|
227
195
|
RCT_EXPORT_METHOD(presentCodeRedemptionSheet) {
|
|
@@ -329,17 +297,17 @@ RCT_REMAP_METHOD(isConfigured,
|
|
|
329
297
|
|
|
330
298
|
#pragma mark -
|
|
331
299
|
#pragma mark Delegate Methods
|
|
332
|
-
- (void)purchases:(RCPurchases *)purchases
|
|
333
|
-
[self sendEventWithName:
|
|
300
|
+
- (void)purchases:(RCPurchases *)purchases didReceiveUpdatedCustomerInfo:(RCCustomerInfo *)customerInfo {
|
|
301
|
+
[self sendEventWithName:RNPurchasesCustomerInfoUpdatedEvent body:customerInfo.dictionary];
|
|
334
302
|
}
|
|
335
303
|
|
|
336
|
-
- (void)
|
|
337
|
-
|
|
338
|
-
|
|
304
|
+
- (void)purchases:(RCPurchases *)purchases
|
|
305
|
+
readyForPromotedProduct:(RCStoreProduct *)product
|
|
306
|
+
purchase:(void (^)(void (^ _Nonnull)(RCStoreTransaction * _Nullable, RCCustomerInfo * _Nullable, NSError * _Nullable, BOOL)))startPurchase {
|
|
339
307
|
if (!self.defermentBlocks) {
|
|
340
308
|
self.defermentBlocks = [NSMutableArray array];
|
|
341
309
|
}
|
|
342
|
-
[self.defermentBlocks addObject:
|
|
310
|
+
[self.defermentBlocks addObject:startPurchase];
|
|
343
311
|
NSInteger position = [self.defermentBlocks count] - 1;
|
|
344
312
|
[self sendEventWithName:RNPurchasesShouldPurchasePromoProductEvent body:@{@"callbackID": @(position)}];
|
|
345
313
|
}
|
|
@@ -369,7 +337,7 @@ shouldPurchasePromoProduct:(SKProduct *)product
|
|
|
369
337
|
}
|
|
370
338
|
|
|
371
339
|
- (NSString *)platformFlavorVersion {
|
|
372
|
-
return @"
|
|
340
|
+
return @"5.0.0-beta.3";
|
|
373
341
|
}
|
|
374
342
|
|
|
375
343
|
@end
|