react-native-purchases 5.6.0 → 5.8.0

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.
@@ -24,6 +24,6 @@ Pod::Spec.new do |spec|
24
24
  ]
25
25
 
26
26
  spec.dependency "React-Core"
27
- spec.dependency "PurchasesHybridCommon", '4.8.0'
27
+ spec.dependency "PurchasesHybridCommon", '4.12.0'
28
28
  spec.swift_version = '5.0'
29
29
  end
@@ -29,7 +29,7 @@ android {
29
29
  minSdkVersion getExtOrIntegerDefault('minSdkVersion')
30
30
  targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
31
31
  versionCode 1
32
- versionName '5.6.0'
32
+ versionName '5.8.0'
33
33
  }
34
34
 
35
35
  buildTypes {
@@ -121,6 +121,6 @@ def kotlin_version = getExtOrDefault('kotlinVersion')
121
121
  dependencies {
122
122
  //noinspection GradleDynamicVersion
123
123
  api 'com.facebook.react:react-native:+'
124
- implementation 'com.revenuecat.purchases:purchases-hybrid-common:4.8.0'
124
+ implementation 'com.revenuecat.purchases:purchases-hybrid-common:4.12.0'
125
125
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
126
126
  }
package/dist/errors.d.ts CHANGED
@@ -21,7 +21,19 @@ export declare enum PURCHASES_ERROR_CODE {
21
21
  INSUFFICIENT_PERMISSIONS_ERROR = "19",
22
22
  PAYMENT_PENDING_ERROR = "20",
23
23
  INVALID_SUBSCRIBER_ATTRIBUTES_ERROR = "21",
24
- LOG_OUT_ANONYMOUS_USER_ERROR = "22"
24
+ LOG_OUT_ANONYMOUS_USER_ERROR = "22",
25
+ CONFIGURATION_ERROR = "23",
26
+ UNSUPPORTED_ERROR = "24",
27
+ EMPTY_SUBSCRIBER_ATTRIBUTES_ERROR = "25",
28
+ PRODUCT_DISCOUNT_MISSING_IDENTIFIER_ERROR = "26",
29
+ PRODUCT_DISCOUNT_MISSING_SUBSCRIPTION_GROUP_IDENTIFIER_ERROR = "28",
30
+ CUSTOMER_INFO_ERROR = "29",
31
+ SYSTEM_INFO_ERROR = "30",
32
+ BEGIN_REFUND_REQUEST_ERROR = "31",
33
+ PRODUCT_REQUEST_TIMED_OUT_ERROR = "32",
34
+ API_ENDPOINT_BLOCKED = "33",
35
+ INVALID_PROMOTIONAL_OFFER_ERROR = "34",
36
+ OFFLINE_CONNECTION_ERROR = "35"
25
37
  }
26
38
  export interface PurchasesError {
27
39
  code: PURCHASES_ERROR_CODE;
@@ -40,3 +52,9 @@ export interface ErrorInfo {
40
52
  export declare class UninitializedPurchasesError extends Error {
41
53
  constructor();
42
54
  }
55
+ /**
56
+ * @internal
57
+ */
58
+ export declare class UnsupportedPlatformError extends Error {
59
+ constructor();
60
+ }
package/dist/errors.js CHANGED
@@ -15,7 +15,8 @@ var __extends = (this && this.__extends) || (function () {
15
15
  };
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.UninitializedPurchasesError = exports.PURCHASES_ERROR_CODE = void 0;
18
+ exports.UnsupportedPlatformError = exports.UninitializedPurchasesError = exports.PURCHASES_ERROR_CODE = void 0;
19
+ /* tslint:disable:max-classes-per-file */
19
20
  // Error codes indicating the reason for an error.
20
21
  var PURCHASES_ERROR_CODE;
21
22
  (function (PURCHASES_ERROR_CODE) {
@@ -42,6 +43,18 @@ var PURCHASES_ERROR_CODE;
42
43
  PURCHASES_ERROR_CODE["PAYMENT_PENDING_ERROR"] = "20";
43
44
  PURCHASES_ERROR_CODE["INVALID_SUBSCRIBER_ATTRIBUTES_ERROR"] = "21";
44
45
  PURCHASES_ERROR_CODE["LOG_OUT_ANONYMOUS_USER_ERROR"] = "22";
46
+ PURCHASES_ERROR_CODE["CONFIGURATION_ERROR"] = "23";
47
+ PURCHASES_ERROR_CODE["UNSUPPORTED_ERROR"] = "24";
48
+ PURCHASES_ERROR_CODE["EMPTY_SUBSCRIBER_ATTRIBUTES_ERROR"] = "25";
49
+ PURCHASES_ERROR_CODE["PRODUCT_DISCOUNT_MISSING_IDENTIFIER_ERROR"] = "26";
50
+ PURCHASES_ERROR_CODE["PRODUCT_DISCOUNT_MISSING_SUBSCRIPTION_GROUP_IDENTIFIER_ERROR"] = "28";
51
+ PURCHASES_ERROR_CODE["CUSTOMER_INFO_ERROR"] = "29";
52
+ PURCHASES_ERROR_CODE["SYSTEM_INFO_ERROR"] = "30";
53
+ PURCHASES_ERROR_CODE["BEGIN_REFUND_REQUEST_ERROR"] = "31";
54
+ PURCHASES_ERROR_CODE["PRODUCT_REQUEST_TIMED_OUT_ERROR"] = "32";
55
+ PURCHASES_ERROR_CODE["API_ENDPOINT_BLOCKED"] = "33";
56
+ PURCHASES_ERROR_CODE["INVALID_PROMOTIONAL_OFFER_ERROR"] = "34";
57
+ PURCHASES_ERROR_CODE["OFFLINE_CONNECTION_ERROR"] = "35";
45
58
  })(PURCHASES_ERROR_CODE = exports.PURCHASES_ERROR_CODE || (exports.PURCHASES_ERROR_CODE = {}));
46
59
  /**
47
60
  * @internal
@@ -59,3 +72,17 @@ var UninitializedPurchasesError = /** @class */ (function (_super) {
59
72
  return UninitializedPurchasesError;
60
73
  }(Error));
61
74
  exports.UninitializedPurchasesError = UninitializedPurchasesError;
75
+ /**
76
+ * @internal
77
+ */
78
+ var UnsupportedPlatformError = /** @class */ (function (_super) {
79
+ __extends(UnsupportedPlatformError, _super);
80
+ function UnsupportedPlatformError() {
81
+ var _this = _super.call(this, "This method is not available in the current platform.") || this;
82
+ // Set the prototype explicitly.
83
+ Object.setPrototypeOf(_this, UnsupportedPlatformError.prototype);
84
+ return _this;
85
+ }
86
+ return UnsupportedPlatformError;
87
+ }(Error));
88
+ exports.UnsupportedPlatformError = UnsupportedPlatformError;
@@ -87,6 +87,14 @@ export interface PurchasesStoreProduct {
87
87
  * Collection of discount offers for a product. Null for Android.
88
88
  */
89
89
  readonly discounts: PurchasesStoreProductDiscount[] | null;
90
+ /**
91
+ * Subscription period, specified in ISO 8601 format. For example,
92
+ * P1W equates to one week, P1M equates to one month,
93
+ * P3M equates to three months, P6M equates to six months,
94
+ * and P1Y equates to one year.
95
+ * Note: Not available for Amazon.
96
+ */
97
+ readonly subscriptionPeriod: string | null;
90
98
  }
91
99
  export interface PurchasesStoreProductDiscount {
92
100
  /**
@@ -1,5 +1,5 @@
1
- import { PURCHASES_ERROR_CODE, UninitializedPurchasesError } from "./errors";
2
- import { CustomerInfo } from "./customerInfo";
1
+ import { PURCHASES_ERROR_CODE, UninitializedPurchasesError, UnsupportedPlatformError } from "./errors";
2
+ import { CustomerInfo, PurchasesEntitlementInfo } from "./customerInfo";
3
3
  import { PRORATION_MODE, PACKAGE_TYPE, INTRO_ELIGIBILITY_STATUS, PurchasesOfferings, PurchasesStoreProduct, UpgradeInfo, PurchasesPromotionalOffer, PurchasesPackage, IntroEligibility, PurchasesStoreProductDiscount } from "./offerings";
4
4
  /**
5
5
  * Listener used on updated customer info
@@ -49,6 +49,20 @@ export declare enum BILLING_FEATURE {
49
49
  */
50
50
  PRICE_CHANGE_CONFIRMATION = 4
51
51
  }
52
+ export declare enum REFUND_REQUEST_STATUS {
53
+ /**
54
+ * Apple has received the refund request.
55
+ */
56
+ SUCCESS = 0,
57
+ /**
58
+ * User canceled submission of the refund request.
59
+ */
60
+ USER_CANCELLED = 1,
61
+ /**
62
+ * There was an error with the request. See message for more details.
63
+ */
64
+ ERROR = 2
65
+ }
52
66
  /**
53
67
  * Holds the logIn result
54
68
  */
@@ -66,11 +80,35 @@ export interface LogInResult {
66
80
  * Holds parameters to initialize the SDK.
67
81
  */
68
82
  export interface PurchasesConfiguration {
83
+ /**
84
+ * RevenueCat API Key. Needs to be a string
85
+ */
69
86
  apiKey: string;
87
+ /**
88
+ * A unique id for identifying the user
89
+ */
70
90
  appUserID?: string | null;
91
+ /**
92
+ * An optional boolean. Set this to TRUE if you have your own IAP implementation and
93
+ * want to use only RevenueCat's backend. Default is FALSE. If you are on Android and setting this to ON, you will have
94
+ * to acknowledge the purchases yourself.
95
+ */
71
96
  observerMode?: boolean;
97
+ /**
98
+ * An optional string. iOS-only, will be ignored for Android.
99
+ * Set this if you would like the RevenueCat SDK to store its preferences in a different NSUserDefaults
100
+ * suite, otherwise it will use standardUserDefaults. Default is null, which will make the SDK use standardUserDefaults.
101
+ */
72
102
  userDefaultsSuiteName?: string;
103
+ /**
104
+ * iOS-only, will be ignored for Android.
105
+ * Set this to TRUE to enable StoreKit2.
106
+ * Default is FALSE.
107
+ */
73
108
  usesStoreKit2IfAvailable?: boolean;
109
+ /**
110
+ * An optional boolean. Android only. Required to configure the plugin to be used in the Amazon Appstore.
111
+ */
74
112
  useAmazon?: boolean;
75
113
  }
76
114
  export default class Purchases {
@@ -88,6 +126,12 @@ export default class Purchases {
88
126
  * @enum {string}
89
127
  */
90
128
  static BILLING_FEATURE: typeof BILLING_FEATURE;
129
+ /**
130
+ * Enum with possible return states for beginning refund request.
131
+ * @readonly
132
+ * @enum {string}
133
+ */
134
+ static REFUND_REQUEST_STATUS: typeof REFUND_REQUEST_STATUS;
91
135
  /**
92
136
  * Replace SKU's ProrationMode.
93
137
  * @readonly
@@ -116,6 +160,10 @@ export default class Purchases {
116
160
  * @internal
117
161
  */
118
162
  static UninitializedPurchasesError: typeof UninitializedPurchasesError;
163
+ /**
164
+ * @internal
165
+ */
166
+ static UnsupportedPlatformError: typeof UnsupportedPlatformError;
119
167
  /**
120
168
  * Sets up Purchases with your API key and an app user id.
121
169
  * @param {String} apiKey RevenueCat API Key. Needs to be a String
@@ -556,6 +604,46 @@ export default class Purchases {
556
604
  * @returns {Promise<boolean>} promise with boolean response. True if billing is supported, false otherwise.
557
605
  */
558
606
  static canMakePayments(features?: BILLING_FEATURE[]): Promise<boolean>;
607
+ /**
608
+ * iOS 15+ only. Presents a refund request sheet in the current window scene for
609
+ * the latest transaction associated with the active entitlement.
610
+ *
611
+ * If the request was unsuccessful, no active entitlements could be found for
612
+ * the user, or multiple active entitlements were found for the user,
613
+ * the promise will return an error.
614
+ * If called in an unsupported platform (Android or iOS < 15), an `UnsupportedPlatformException` will be thrown.
615
+ *
616
+ * Important: This method should only be used if your user can only have a single active entitlement at a given time.
617
+ * If a user could have more than one entitlement at a time, use `beginRefundRequestForEntitlement` instead.
618
+ *
619
+ * @returns {Promise<REFUND_REQUEST_STATUS>} Returns REFUND_REQUEST_STATUS: The status of the
620
+ * refund request. Keep in mind the status could be REFUND_REQUEST_STATUS.USER_CANCELLED
621
+ */
622
+ static beginRefundRequestForActiveEntitlement(): Promise<REFUND_REQUEST_STATUS>;
623
+ /**
624
+ * iOS 15+ only. Presents a refund request sheet in the current window scene for
625
+ * the latest transaction associated with the `entitlement`.
626
+ *
627
+ * If the request was unsuccessful, the promise will return an error.
628
+ * If called in an unsupported platform (Android or iOS < 15), an `UnsupportedPlatformException` will be thrown.
629
+ *
630
+ * @param entitlementInfo The entitlement to begin a refund request for.
631
+ * @returns {Promise<REFUND_REQUEST_STATUS>} Returns REFUND_REQUEST_STATUS: The status of the
632
+ * refund request. Keep in mind the status could be REFUND_REQUEST_STATUS.USER_CANCELLED
633
+ */
634
+ static beginRefundRequestForEntitlement(entitlementInfo: PurchasesEntitlementInfo): Promise<REFUND_REQUEST_STATUS>;
635
+ /**
636
+ * iOS 15+ only. Presents a refund request sheet in the current window scene for
637
+ * the latest transaction associated with the `product`.
638
+ *
639
+ * If the request was unsuccessful, the promise will return an error.
640
+ * If called in an unsupported platform (Android or iOS < 15), an `UnsupportedPlatformException` will be thrown.
641
+ *
642
+ * @param storeProduct The StoreProduct to begin a refund request for.
643
+ * @returns {Promise<REFUND_REQUEST_STATUS>} Returns a REFUND_REQUEST_STATUS: The status of the
644
+ * refund request. Keep in mind the status could be REFUND_REQUEST_STATUS.USER_CANCELLED
645
+ */
646
+ static beginRefundRequestForProduct(storeProduct: PurchasesStoreProduct): Promise<REFUND_REQUEST_STATUS>;
559
647
  /**
560
648
  * Check if configure has finished and Purchases has been configured.
561
649
  *
@@ -563,4 +651,6 @@ export default class Purchases {
563
651
  */
564
652
  static isConfigured(): Promise<boolean>;
565
653
  private static throwIfNotConfigured;
654
+ private static throwIfAndroidPlatform;
655
+ private static convertIntToRefundRequestStatus;
566
656
  }
package/dist/purchases.js CHANGED
@@ -36,7 +36,7 @@ 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 = void 0;
39
+ exports.REFUND_REQUEST_STATUS = 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");
@@ -93,6 +93,21 @@ var BILLING_FEATURE;
93
93
  */
94
94
  BILLING_FEATURE[BILLING_FEATURE["PRICE_CHANGE_CONFIRMATION"] = 4] = "PRICE_CHANGE_CONFIRMATION";
95
95
  })(BILLING_FEATURE = exports.BILLING_FEATURE || (exports.BILLING_FEATURE = {}));
96
+ var REFUND_REQUEST_STATUS;
97
+ (function (REFUND_REQUEST_STATUS) {
98
+ /**
99
+ * Apple has received the refund request.
100
+ */
101
+ REFUND_REQUEST_STATUS[REFUND_REQUEST_STATUS["SUCCESS"] = 0] = "SUCCESS";
102
+ /**
103
+ * User canceled submission of the refund request.
104
+ */
105
+ REFUND_REQUEST_STATUS[REFUND_REQUEST_STATUS["USER_CANCELLED"] = 1] = "USER_CANCELLED";
106
+ /**
107
+ * There was an error with the request. See message for more details.
108
+ */
109
+ REFUND_REQUEST_STATUS[REFUND_REQUEST_STATUS["ERROR"] = 2] = "ERROR";
110
+ })(REFUND_REQUEST_STATUS = exports.REFUND_REQUEST_STATUS || (exports.REFUND_REQUEST_STATUS = {}));
96
111
  var Purchases = /** @class */ (function () {
97
112
  function Purchases() {
98
113
  }
@@ -1117,6 +1132,109 @@ var Purchases = /** @class */ (function () {
1117
1132
  if (features === void 0) { features = []; }
1118
1133
  return RNPurchases.canMakePayments(features);
1119
1134
  };
1135
+ /**
1136
+ * iOS 15+ only. Presents a refund request sheet in the current window scene for
1137
+ * the latest transaction associated with the active entitlement.
1138
+ *
1139
+ * If the request was unsuccessful, no active entitlements could be found for
1140
+ * the user, or multiple active entitlements were found for the user,
1141
+ * the promise will return an error.
1142
+ * If called in an unsupported platform (Android or iOS < 15), an `UnsupportedPlatformException` will be thrown.
1143
+ *
1144
+ * Important: This method should only be used if your user can only have a single active entitlement at a given time.
1145
+ * If a user could have more than one entitlement at a time, use `beginRefundRequestForEntitlement` instead.
1146
+ *
1147
+ * @returns {Promise<REFUND_REQUEST_STATUS>} Returns REFUND_REQUEST_STATUS: The status of the
1148
+ * refund request. Keep in mind the status could be REFUND_REQUEST_STATUS.USER_CANCELLED
1149
+ */
1150
+ Purchases.beginRefundRequestForActiveEntitlement = function () {
1151
+ return __awaiter(this, void 0, void 0, function () {
1152
+ var refundRequestStatusInt;
1153
+ return __generator(this, function (_a) {
1154
+ switch (_a.label) {
1155
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
1156
+ case 1:
1157
+ _a.sent();
1158
+ return [4 /*yield*/, Purchases.throwIfAndroidPlatform()];
1159
+ case 2:
1160
+ _a.sent();
1161
+ return [4 /*yield*/, RNPurchases.beginRefundRequestForActiveEntitlement()];
1162
+ case 3:
1163
+ refundRequestStatusInt = _a.sent();
1164
+ if (refundRequestStatusInt == null) {
1165
+ throw new errors_1.UnsupportedPlatformError();
1166
+ }
1167
+ return [2 /*return*/, Purchases.convertIntToRefundRequestStatus(refundRequestStatusInt)];
1168
+ }
1169
+ });
1170
+ });
1171
+ };
1172
+ /**
1173
+ * iOS 15+ only. Presents a refund request sheet in the current window scene for
1174
+ * the latest transaction associated with the `entitlement`.
1175
+ *
1176
+ * If the request was unsuccessful, the promise will return an error.
1177
+ * If called in an unsupported platform (Android or iOS < 15), an `UnsupportedPlatformException` will be thrown.
1178
+ *
1179
+ * @param entitlementInfo The entitlement to begin a refund request for.
1180
+ * @returns {Promise<REFUND_REQUEST_STATUS>} Returns REFUND_REQUEST_STATUS: The status of the
1181
+ * refund request. Keep in mind the status could be REFUND_REQUEST_STATUS.USER_CANCELLED
1182
+ */
1183
+ Purchases.beginRefundRequestForEntitlement = function (entitlementInfo) {
1184
+ return __awaiter(this, void 0, void 0, function () {
1185
+ var refundRequestStatusInt;
1186
+ return __generator(this, function (_a) {
1187
+ switch (_a.label) {
1188
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
1189
+ case 1:
1190
+ _a.sent();
1191
+ return [4 /*yield*/, Purchases.throwIfAndroidPlatform()];
1192
+ case 2:
1193
+ _a.sent();
1194
+ return [4 /*yield*/, RNPurchases.beginRefundRequestForEntitlementId(entitlementInfo.identifier)];
1195
+ case 3:
1196
+ refundRequestStatusInt = _a.sent();
1197
+ if (refundRequestStatusInt == null) {
1198
+ throw new errors_1.UnsupportedPlatformError();
1199
+ }
1200
+ return [2 /*return*/, Purchases.convertIntToRefundRequestStatus(refundRequestStatusInt)];
1201
+ }
1202
+ });
1203
+ });
1204
+ };
1205
+ /**
1206
+ * iOS 15+ only. Presents a refund request sheet in the current window scene for
1207
+ * the latest transaction associated with the `product`.
1208
+ *
1209
+ * If the request was unsuccessful, the promise will return an error.
1210
+ * If called in an unsupported platform (Android or iOS < 15), an `UnsupportedPlatformException` will be thrown.
1211
+ *
1212
+ * @param storeProduct The StoreProduct to begin a refund request for.
1213
+ * @returns {Promise<REFUND_REQUEST_STATUS>} Returns a REFUND_REQUEST_STATUS: The status of the
1214
+ * refund request. Keep in mind the status could be REFUND_REQUEST_STATUS.USER_CANCELLED
1215
+ */
1216
+ Purchases.beginRefundRequestForProduct = function (storeProduct) {
1217
+ return __awaiter(this, void 0, void 0, function () {
1218
+ var refundRequestStatusInt;
1219
+ return __generator(this, function (_a) {
1220
+ switch (_a.label) {
1221
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
1222
+ case 1:
1223
+ _a.sent();
1224
+ return [4 /*yield*/, Purchases.throwIfAndroidPlatform()];
1225
+ case 2:
1226
+ _a.sent();
1227
+ return [4 /*yield*/, RNPurchases.beginRefundRequestForProductId(storeProduct.identifier)];
1228
+ case 3:
1229
+ refundRequestStatusInt = _a.sent();
1230
+ if (refundRequestStatusInt == null) {
1231
+ throw new errors_1.UnsupportedPlatformError();
1232
+ }
1233
+ return [2 /*return*/, Purchases.convertIntToRefundRequestStatus(refundRequestStatusInt)];
1234
+ }
1235
+ });
1236
+ });
1237
+ };
1120
1238
  /**
1121
1239
  * Check if configure has finished and Purchases has been configured.
1122
1240
  *
@@ -1141,6 +1259,26 @@ var Purchases = /** @class */ (function () {
1141
1259
  });
1142
1260
  });
1143
1261
  };
1262
+ Purchases.throwIfAndroidPlatform = function () {
1263
+ return __awaiter(this, void 0, void 0, function () {
1264
+ return __generator(this, function (_a) {
1265
+ if (react_native_2.Platform.OS === "android") {
1266
+ throw new errors_1.UnsupportedPlatformError();
1267
+ }
1268
+ return [2 /*return*/];
1269
+ });
1270
+ });
1271
+ };
1272
+ Purchases.convertIntToRefundRequestStatus = function (refundRequestStatusInt) {
1273
+ switch (refundRequestStatusInt) {
1274
+ case 0:
1275
+ return REFUND_REQUEST_STATUS.SUCCESS;
1276
+ case 1:
1277
+ return REFUND_REQUEST_STATUS.USER_CANCELLED;
1278
+ default:
1279
+ return REFUND_REQUEST_STATUS.ERROR;
1280
+ }
1281
+ };
1144
1282
  /**
1145
1283
  * Supported SKU types.
1146
1284
  * @readonly
@@ -1155,6 +1293,12 @@ var Purchases = /** @class */ (function () {
1155
1293
  * @enum {string}
1156
1294
  */
1157
1295
  Purchases.BILLING_FEATURE = BILLING_FEATURE;
1296
+ /**
1297
+ * Enum with possible return states for beginning refund request.
1298
+ * @readonly
1299
+ * @enum {string}
1300
+ */
1301
+ Purchases.REFUND_REQUEST_STATUS = REFUND_REQUEST_STATUS;
1158
1302
  /**
1159
1303
  * Replace SKU's ProrationMode.
1160
1304
  * @readonly
@@ -1183,6 +1327,10 @@ var Purchases = /** @class */ (function () {
1183
1327
  * @internal
1184
1328
  */
1185
1329
  Purchases.UninitializedPurchasesError = errors_1.UninitializedPurchasesError;
1330
+ /**
1331
+ * @internal
1332
+ */
1333
+ Purchases.UnsupportedPlatformError = errors_1.UnsupportedPlatformError;
1186
1334
  return Purchases;
1187
1335
  }());
1188
1336
  exports.default = Purchases;
package/ios/RNPurchases.m CHANGED
@@ -318,6 +318,52 @@ RCT_REMAP_METHOD(canMakePayments,
318
318
  resolve(@([RCCommonFunctionality canMakePaymentsWithFeatures:features]));
319
319
  }
320
320
 
321
+ RCT_EXPORT_METHOD(beginRefundRequestForActiveEntitlement:(RCTPromiseResolveBlock)resolve
322
+ reject:(RCTPromiseRejectBlock)reject) {
323
+ #if TARGET_OS_IPHONE
324
+ if (@available(iOS 15.0, *)) {
325
+ [RCCommonFunctionality beginRefundRequestForActiveEntitlementCompletion:[self getBeginRefundResponseCompletionBlockWithResolve:resolve
326
+ reject:reject]];
327
+ } else {
328
+ resolve(nil);
329
+ }
330
+ #else
331
+ resolve(nil);
332
+ #endif
333
+ }
334
+
335
+ RCT_EXPORT_METHOD(beginRefundRequestForEntitlementId:(NSString *)entitlementIdentifier
336
+ resolve:(RCTPromiseResolveBlock)resolve
337
+ reject:(RCTPromiseRejectBlock)reject) {
338
+ #if TARGET_OS_IPHONE
339
+ if (@available(iOS 15.0, *)) {
340
+ [RCCommonFunctionality beginRefundRequestEntitlementId:entitlementIdentifier
341
+ completionBlock:[self getBeginRefundResponseCompletionBlockWithResolve:resolve
342
+ reject:reject]];
343
+ } else {
344
+ resolve(nil);
345
+ }
346
+ #else
347
+ resolve(nil);
348
+ #endif
349
+ }
350
+
351
+ RCT_EXPORT_METHOD(beginRefundRequestForProductId:(NSString *)productIdentifier
352
+ resolve:(RCTPromiseResolveBlock)resolve
353
+ reject:(RCTPromiseRejectBlock)reject) {
354
+ #if TARGET_OS_IPHONE
355
+ if (@available(iOS 15.0, *)) {
356
+ [RCCommonFunctionality beginRefundRequestProductId:productIdentifier
357
+ completionBlock:[self getBeginRefundResponseCompletionBlockWithResolve:resolve
358
+ reject:reject]];
359
+ } else {
360
+ resolve(nil);
361
+ }
362
+ #else
363
+ resolve(nil);
364
+ #endif
365
+ }
366
+
321
367
  RCT_REMAP_METHOD(isConfigured,
322
368
  isConfiguredWithResolve:(RCTPromiseResolveBlock)resolve
323
369
  reject:(RCTPromiseRejectBlock)reject) {
@@ -344,15 +390,15 @@ readyForPromotedProduct:(RCStoreProduct *)product
344
390
  #pragma mark -
345
391
  #pragma mark Helper Methods
346
392
 
347
- - (void)rejectPromiseWithBlock:(RCTPromiseRejectBlock)reject error:(NSError *)error {
348
- reject([NSString stringWithFormat: @"%ld", (long)error.code], error.localizedDescription, error);
393
+ - (void)rejectPromiseWithBlock:(RCTPromiseRejectBlock)reject error:(RCErrorContainer *)error {
394
+ reject([NSString stringWithFormat:@"%ld", (long) error.code], error.message, error.error);
349
395
  }
350
396
 
351
397
  - (void (^)(NSDictionary *, RCErrorContainer *))getResponseCompletionBlockWithResolve:(RCTPromiseResolveBlock)resolve
352
398
  reject:(RCTPromiseRejectBlock)reject {
353
399
  return ^(NSDictionary *_Nullable responseDictionary, RCErrorContainer *_Nullable error) {
354
400
  if (error) {
355
- reject([NSString stringWithFormat:@"%ld", (long) error.code], error.message, error.error);
401
+ [self rejectPromiseWithBlock:reject error:error];
356
402
  } else if (responseDictionary) {
357
403
  resolve([NSDictionary dictionaryWithDictionary:responseDictionary]);
358
404
  } else {
@@ -361,12 +407,25 @@ readyForPromotedProduct:(RCStoreProduct *)product
361
407
  };
362
408
  }
363
409
 
410
+ - (void (^)(RCErrorContainer *))getBeginRefundResponseCompletionBlockWithResolve:(RCTPromiseResolveBlock)resolve
411
+ reject:(RCTPromiseRejectBlock)reject {
412
+ return ^(RCErrorContainer * _Nullable error) {
413
+ if (error == nil) {
414
+ resolve(@0);
415
+ } else if ([error.info[@"userCancelled"] isEqual:@YES]) {
416
+ resolve(@1);
417
+ } else {
418
+ [self rejectPromiseWithBlock:reject error:error];
419
+ }
420
+ };
421
+ }
422
+
364
423
  - (NSString *)platformFlavor {
365
424
  return @"react-native";
366
425
  }
367
426
 
368
427
  - (NSString *)platformFlavorVersion {
369
- return @"5.6.0";
428
+ return @"5.8.0";
370
429
  }
371
430
 
372
431
  @end
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-purchases",
3
3
  "title": "React Native Purchases",
4
- "version": "5.6.0",
4
+ "version": "5.8.0",
5
5
  "description": "React Native in-app purchases and subscriptions made easy. Supports iOS and Android. ",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -31,7 +31,7 @@
31
31
  "build-watch": "tsc --watch",
32
32
  "test": "jest",
33
33
  "tslint": "tslint -c tslint.json 'src/*.ts'",
34
- "prepublish": "tsc",
34
+ "prepare": "tsc",
35
35
  "example": "yarn --cwd examples/MagicWeather && yarn --cwd examples/purchaseTesterTypescript",
36
36
  "pods": "(cd examples/MagicWeather && rm -f ios/Podfile.lock && npx pod-install --quiet) && (cd examples/purchaseTesterTypescript && rm -f ios/Podfile.lock && npx pod-install --quiet)",
37
37
  "bootstrap": "yarn example && yarn && yarn pods"
@@ -2,7 +2,7 @@
2
2
  <!DOCTYPE html>
3
3
  <html>
4
4
  <head>
5
- <meta http-equiv="refresh" content="0; url=https://revenuecat.github.io/react-native-purchases-docs/5.6.0/" />
5
+ <meta http-equiv="refresh" content="0; url=https://revenuecat.github.io/react-native-purchases-docs/5.8.0/" />
6
6
  </head>
7
7
  <body>
8
8
  </body>
@@ -67,6 +67,7 @@ global.offeringsStub = {
67
67
  weekly: {
68
68
  offeringIdentifier: 'default',
69
69
  product: {
70
+ introPrice: null,
70
71
  description: 'Product with intro price',
71
72
  currencyCode: 'USD',
72
73
  priceString: '$9.99',
@@ -94,7 +95,8 @@ global.offeringsStub = {
94
95
  priceString: '$19.99',
95
96
  price: 19.99,
96
97
  title: 'Annual Free Trial (PurchasesSample)',
97
- identifier: 'annual_freetrial'
98
+ identifier: 'annual_freetrial',
99
+ subscriptionPeriod: "P1Y"
98
100
  },
99
101
  packageType: 'TWO_MONTH',
100
102
  identifier: '$rc_two_month'
@@ -115,7 +117,8 @@ global.offeringsStub = {
115
117
  priceString: '$19.99',
116
118
  price: 19.99,
117
119
  title: 'Annual Free Trial (PurchasesSample)',
118
- identifier: 'annual_freetrial'
120
+ identifier: 'annual_freetrial',
121
+ subscriptionPeriod: "P1Y"
119
122
  },
120
123
  packageType: 'THREE_MONTH',
121
124
  identifier: '$rc_three_month'
@@ -136,7 +139,8 @@ global.offeringsStub = {
136
139
  priceString: '$19.99',
137
140
  price: 19.99,
138
141
  title: 'Annual Free Trial (PurchasesSample)',
139
- identifier: 'annual_freetrial'
142
+ identifier: 'annual_freetrial',
143
+ subscriptionPeriod: "P1Y"
140
144
  },
141
145
  packageType: 'SIX_MONTH',
142
146
  identifier: '$rc_six_month'
@@ -157,7 +161,8 @@ global.offeringsStub = {
157
161
  priceString: '$19.99',
158
162
  price: 19.99,
159
163
  title: 'Annual Free Trial (PurchasesSample)',
160
- identifier: 'annual_freetrial'
164
+ identifier: 'annual_freetrial',
165
+ subscriptionPeriod: "P1Y"
161
166
  },
162
167
  packageType: 'ANNUAL',
163
168
  identifier: '$rc_annual'
@@ -171,7 +176,8 @@ global.offeringsStub = {
171
176
  priceString: '$4.99',
172
177
  price: 4.99,
173
178
  title: 'Consumable (PurchasesSample)',
174
- identifier: 'consumable'
179
+ identifier: 'consumable',
180
+ subscriptionPeriod: null
175
181
  },
176
182
  packageType: 'LIFETIME',
177
183
  identifier: '$rc_lifetime'
@@ -193,7 +199,8 @@ global.offeringsStub = {
193
199
  priceString: '$19.99',
194
200
  price: 19.99,
195
201
  title: 'Annual Free Trial (PurchasesSample)',
196
- identifier: 'annual_freetrial'
202
+ identifier: 'annual_freetrial',
203
+ subscriptionPeriod: "P1Y"
197
204
  },
198
205
  packageType: 'ANNUAL',
199
206
  identifier: '$rc_annual'
@@ -214,7 +221,8 @@ global.offeringsStub = {
214
221
  priceString: '$19.99',
215
222
  price: 19.99,
216
223
  title: 'Annual Free Trial (PurchasesSample)',
217
- identifier: 'annual_freetrial'
224
+ identifier: 'annual_freetrial',
225
+ subscriptionPeriod: "P1Y"
218
226
  },
219
227
  packageType: 'SIX_MONTH',
220
228
  identifier: '$rc_six_month'
@@ -235,7 +243,8 @@ global.offeringsStub = {
235
243
  priceString: '$19.99',
236
244
  price: 19.99,
237
245
  title: 'Annual Free Trial (PurchasesSample)',
238
- identifier: 'annual_freetrial'
246
+ identifier: 'annual_freetrial',
247
+ subscriptionPeriod: "P1Y"
239
248
  },
240
249
  packageType: 'THREE_MONTH',
241
250
  identifier: '$rc_three_month'
@@ -256,7 +265,8 @@ global.offeringsStub = {
256
265
  priceString: '$19.99',
257
266
  price: 19.99,
258
267
  title: 'Annual Free Trial (PurchasesSample)',
259
- identifier: 'annual_freetrial'
268
+ identifier: 'annual_freetrial',
269
+ subscriptionPeriod: "P1Y"
260
270
  },
261
271
  packageType: 'TWO_MONTH',
262
272
  identifier: '$rc_two_month'
@@ -277,7 +287,8 @@ global.offeringsStub = {
277
287
  priceString: '$9.99',
278
288
  price: 9.99,
279
289
  title: 'Introductory Price (PurchasesSample)',
280
- identifier: 'introductory_price'
290
+ identifier: 'introductory_price',
291
+ subscriptionPeriod: "P1M"
281
292
  },
282
293
  packageType: 'WEEKLY',
283
294
  identifier: '$rc_weekly'
@@ -312,7 +323,8 @@ global.offeringsStub = {
312
323
  priceString: '$19.99',
313
324
  price: 19.99,
314
325
  title: 'Annual Free Trial (PurchasesSample)',
315
- identifier: 'annual_freetrial'
326
+ identifier: 'annual_freetrial',
327
+ subscriptionPeriod: "P1Y"
316
328
  },
317
329
  packageType: 'CUSTOM',
318
330
  identifier: 'Custom'
@@ -340,7 +352,8 @@ global.offeringsStub = {
340
352
  priceString: '$9.99',
341
353
  price: 9.99,
342
354
  title: 'Introductory Price (PurchasesSample)',
343
- identifier: 'introductory_price'
355
+ identifier: 'introductory_price',
356
+ subscriptionPeriod: "P1M"
344
357
  },
345
358
  packageType: 'MONTHLY',
346
359
  identifier: '$rc_monthly'
@@ -367,7 +380,8 @@ global.offeringsStub = {
367
380
  priceString: '$9.99',
368
381
  price: 9.99,
369
382
  title: 'Introductory Price (PurchasesSample)',
370
- identifier: 'introductory_price'
383
+ identifier: 'introductory_price',
384
+ subscriptionPeriod: "P1M"
371
385
  },
372
386
  packageType: 'MONTHLY',
373
387
  identifier: '$rc_monthly'
@@ -393,7 +407,8 @@ global.offeringsStub = {
393
407
  priceString: '$9.99',
394
408
  price: 9.99,
395
409
  title: 'Introductory Price (PurchasesSample)',
396
- identifier: 'introductory_price'
410
+ identifier: 'introductory_price',
411
+ subscriptionPeriod: "P1M"
397
412
  },
398
413
  packageType: 'WEEKLY',
399
414
  identifier: '$rc_weekly'
@@ -415,7 +430,8 @@ global.offeringsStub = {
415
430
  priceString: '$19.99',
416
431
  price: 19.99,
417
432
  title: 'Annual Free Trial (PurchasesSample)',
418
- identifier: 'annual_freetrial'
433
+ identifier: 'annual_freetrial',
434
+ subscriptionPeriod: "P1Y"
419
435
  },
420
436
  packageType: 'TWO_MONTH',
421
437
  identifier: '$rc_two_month'
@@ -436,7 +452,8 @@ global.offeringsStub = {
436
452
  priceString: '$19.99',
437
453
  price: 19.99,
438
454
  title: 'Annual Free Trial (PurchasesSample)',
439
- identifier: 'annual_freetrial'
455
+ identifier: 'annual_freetrial',
456
+ subscriptionPeriod: "P1Y"
440
457
  },
441
458
  packageType: 'THREE_MONTH',
442
459
  identifier: '$rc_three_month'
@@ -457,7 +474,8 @@ global.offeringsStub = {
457
474
  priceString: '$19.99',
458
475
  price: 19.99,
459
476
  title: 'Annual Free Trial (PurchasesSample)',
460
- identifier: 'annual_freetrial'
477
+ identifier: 'annual_freetrial',
478
+ subscriptionPeriod: "P1Y"
461
479
  },
462
480
  packageType: 'SIX_MONTH',
463
481
  identifier: '$rc_six_month'
@@ -478,7 +496,8 @@ global.offeringsStub = {
478
496
  priceString: '$19.99',
479
497
  price: 19.99,
480
498
  title: 'Annual Free Trial (PurchasesSample)',
481
- identifier: 'annual_freetrial'
499
+ identifier: 'annual_freetrial',
500
+ subscriptionPeriod: "P1Y"
482
501
  },
483
502
  packageType: 'ANNUAL',
484
503
  identifier: '$rc_annual'
@@ -492,7 +511,8 @@ global.offeringsStub = {
492
511
  priceString: '$4.99',
493
512
  price: 4.99,
494
513
  title: 'Consumable (PurchasesSample)',
495
- identifier: 'consumable'
514
+ identifier: 'consumable',
515
+ subscriptionPeriod: null
496
516
  },
497
517
  packageType: 'LIFETIME',
498
518
  identifier: '$rc_lifetime'
@@ -514,7 +534,8 @@ global.offeringsStub = {
514
534
  priceString: '$19.99',
515
535
  price: 19.99,
516
536
  title: 'Annual Free Trial (PurchasesSample)',
517
- identifier: 'annual_freetrial'
537
+ identifier: 'annual_freetrial',
538
+ subscriptionPeriod: "P1Y"
518
539
  },
519
540
  packageType: 'ANNUAL',
520
541
  identifier: '$rc_annual'
@@ -535,7 +556,8 @@ global.offeringsStub = {
535
556
  priceString: '$19.99',
536
557
  price: 19.99,
537
558
  title: 'Annual Free Trial (PurchasesSample)',
538
- identifier: 'annual_freetrial'
559
+ identifier: 'annual_freetrial',
560
+ subscriptionPeriod: "P1Y"
539
561
  },
540
562
  packageType: 'SIX_MONTH',
541
563
  identifier: '$rc_six_month'
@@ -556,7 +578,8 @@ global.offeringsStub = {
556
578
  priceString: '$19.99',
557
579
  price: 19.99,
558
580
  title: 'Annual Free Trial (PurchasesSample)',
559
- identifier: 'annual_freetrial'
581
+ identifier: 'annual_freetrial',
582
+ subscriptionPeriod: "P1Y"
560
583
  },
561
584
  packageType: 'THREE_MONTH',
562
585
  identifier: '$rc_three_month'
@@ -577,7 +600,8 @@ global.offeringsStub = {
577
600
  priceString: '$19.99',
578
601
  price: 19.99,
579
602
  title: 'Annual Free Trial (PurchasesSample)',
580
- identifier: 'annual_freetrial'
603
+ identifier: 'annual_freetrial',
604
+ subscriptionPeriod: "P1Y"
581
605
  },
582
606
  packageType: 'TWO_MONTH',
583
607
  identifier: '$rc_two_month'
@@ -598,7 +622,8 @@ global.offeringsStub = {
598
622
  priceString: '$9.99',
599
623
  price: 9.99,
600
624
  title: 'Introductory Price (PurchasesSample)',
601
- identifier: 'introductory_price'
625
+ identifier: 'introductory_price',
626
+ subscriptionPeriod: "P1M"
602
627
  },
603
628
  packageType: 'WEEKLY',
604
629
  identifier: '$rc_weekly'
@@ -612,7 +637,8 @@ global.offeringsStub = {
612
637
  priceString: '$4.99',
613
638
  price: 4.99,
614
639
  title: 'Consumable (PurchasesSample)',
615
- identifier: 'consumable'
640
+ identifier: 'consumable',
641
+ subscriptionPeriod: null
616
642
  },
617
643
  packageType: 'LIFETIME',
618
644
  identifier: '$rc_lifetime'
@@ -633,7 +659,8 @@ global.offeringsStub = {
633
659
  priceString: '$19.99',
634
660
  price: 19.99,
635
661
  title: 'Annual Free Trial (PurchasesSample)',
636
- identifier: 'annual_freetrial'
662
+ identifier: 'annual_freetrial',
663
+ subscriptionPeriod: "P1Y"
637
664
  },
638
665
  packageType: 'CUSTOM',
639
666
  identifier: 'Custom'
@@ -683,7 +710,22 @@ global.promotionalOfferStub = {
683
710
  nonce: "nonce",
684
711
  signature: "signature",
685
712
  timestamp: 123,
686
- }
713
+ };
714
+
715
+ global.entitlementInfoStub = {
716
+ identifier: "entitlement_id",
717
+ isActive: true,
718
+ willRenew: true,
719
+ periodType: "",
720
+ latestPurchaseDate: "",
721
+ originalPurchaseDate: "",
722
+ expirationDate: "",
723
+ store: "APP_STORE",
724
+ productIdentifier: "product_id",
725
+ isSandbox: false,
726
+ unsubscribeDetectedAt: null,
727
+ billingIssueDetectedAt: null
728
+ };
687
729
 
688
730
  NativeModules.RNPurchases = {
689
731
  setupPurchases: jest.fn(),
@@ -718,6 +760,9 @@ NativeModules.RNPurchases = {
718
760
  setMixpanelDistinctID: jest.fn(),
719
761
  setFirebaseAppInstanceID: jest.fn(),
720
762
  canMakePayments: jest.fn(),
763
+ beginRefundRequestForActiveEntitlement: jest.fn(),
764
+ beginRefundRequestForEntitlementId: jest.fn(),
765
+ beginRefundRequestForProductId: jest.fn(),
721
766
  isConfigured: jest.fn()
722
767
  };
723
768