react-native-purchases 8.2.6 → 8.3.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.
@@ -25,6 +25,6 @@ Pod::Spec.new do |spec|
25
25
  ]
26
26
 
27
27
  spec.dependency "React-Core"
28
- spec.dependency "PurchasesHybridCommon", '13.8.0'
28
+ spec.dependency "PurchasesHybridCommon", '13.12.0'
29
29
  spec.swift_version = '5.7'
30
30
  end
@@ -29,7 +29,7 @@ android {
29
29
  minSdkVersion getExtOrIntegerDefault('minSdkVersion')
30
30
  targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
31
31
  versionCode 1
32
- versionName '8.2.6'
32
+ versionName '8.3.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:13.8.0'
124
+ implementation 'com.revenuecat.purchases:purchases-hybrid-common:13.12.0'
125
125
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
126
126
  }
@@ -47,7 +47,7 @@ public class RNPurchasesModule extends ReactContextBaseJavaModule implements Upd
47
47
  private static final String CUSTOMER_INFO_UPDATED = "Purchases-CustomerInfoUpdated";
48
48
  private static final String LOG_HANDLER_EVENT = "Purchases-LogHandlerEvent";
49
49
  public static final String PLATFORM_NAME = "react-native";
50
- public static final String PLUGIN_VERSION = "8.2.6";
50
+ public static final String PLUGIN_VERSION = "8.3.0";
51
51
 
52
52
  private final ReactApplicationContext reactContext;
53
53
 
@@ -1,4 +1,4 @@
1
- import { PURCHASES_ERROR_CODE, UninitializedPurchasesError, UnsupportedPlatformError, CustomerInfo, PurchasesEntitlementInfo, PRORATION_MODE, PACKAGE_TYPE, INTRO_ELIGIBILITY_STATUS, PurchasesOfferings, PurchasesStoreProduct, UpgradeInfo, PurchasesPromotionalOffer, PurchasesPackage, IntroEligibility, PurchasesStoreProductDiscount, SubscriptionOption, PRODUCT_CATEGORY, GoogleProductChangeInfo, PURCHASE_TYPE, BILLING_FEATURE, REFUND_REQUEST_STATUS, LOG_LEVEL, PurchasesConfiguration, CustomerInfoUpdateListener, ShouldPurchasePromoProductListener, MakePurchaseResult, LogHandler, LogInResult, IN_APP_MESSAGE_TYPE, ENTITLEMENT_VERIFICATION_MODE, VERIFICATION_RESULT, STOREKIT_VERSION, PurchasesStoreTransaction, PurchasesOffering, PURCHASES_ARE_COMPLETED_BY_TYPE } from "@revenuecat/purchases-typescript-internal";
1
+ import { PURCHASES_ERROR_CODE, UninitializedPurchasesError, UnsupportedPlatformError, CustomerInfo, PurchasesEntitlementInfo, PRORATION_MODE, PACKAGE_TYPE, INTRO_ELIGIBILITY_STATUS, PurchasesOfferings, PurchasesStoreProduct, UpgradeInfo, PurchasesPromotionalOffer, PurchasesPackage, IntroEligibility, PurchasesStoreProductDiscount, SubscriptionOption, PRODUCT_CATEGORY, GoogleProductChangeInfo, PURCHASE_TYPE, BILLING_FEATURE, REFUND_REQUEST_STATUS, LOG_LEVEL, PurchasesConfiguration, CustomerInfoUpdateListener, ShouldPurchasePromoProductListener, MakePurchaseResult, LogHandler, LogInResult, IN_APP_MESSAGE_TYPE, ENTITLEMENT_VERIFICATION_MODE, VERIFICATION_RESULT, STOREKIT_VERSION, PurchasesStoreTransaction, PurchasesOffering, PURCHASES_ARE_COMPLETED_BY_TYPE, PurchasesWinBackOffer } from "@revenuecat/purchases-typescript-internal";
2
2
  export { PURCHASE_TYPE, PurchasesAreCompletedBy, PurchasesAreCompletedByMyApp, PURCHASES_ARE_COMPLETED_BY_TYPE, BILLING_FEATURE, REFUND_REQUEST_STATUS, LOG_LEVEL, STOREKIT_VERSION, PurchasesConfiguration, CustomerInfoUpdateListener, ShouldPurchasePromoProductListener, MakePurchaseResult, LogHandler, LogInResult, } from "@revenuecat/purchases-typescript-internal";
3
3
  export default class Purchases {
4
4
  /**
@@ -420,6 +420,52 @@ export default class Purchases {
420
420
  * called yet or if there's an error getting the payment discount.
421
421
  */
422
422
  static getPromotionalOffer(product: PurchasesStoreProduct, discount: PurchasesStoreProductDiscount): Promise<PurchasesPromotionalOffer | undefined>;
423
+ /**
424
+ * iOS only. Use this function to retrieve the eligible `PurchasesWinBackOffer`s that a subscriber
425
+ * is eligible for for a given `PurchasesProduct`.
426
+ *
427
+ * @param product The `PurchasesStoreProduct` the user intends to purchase.
428
+ * @returns { Promise<[PurchasesWinBackOffer]> } Returns an array of win-back offers that the subscriber is eligible for.
429
+ * Null is returned for Android and incompatible iOS versions. The promise will be rejected if configure has not been
430
+ * called yet or if there's an error getting the payment discount.
431
+ */
432
+ static getEligibleWinBackOffersForProduct(product: PurchasesStoreProduct): Promise<[PurchasesWinBackOffer] | undefined>;
433
+ /**
434
+ * iOS only. Use this function to retrieve the eligible `PurchasesWinBackOffer`s that a subscriber
435
+ * is eligible for for a given `PurchasesPackage`.
436
+ *
437
+ * @param aPackage The `PurchasesPackage` the user intends to purchase.
438
+ * @returns { Promise<[PurchasesWinBackOffer]> } Returns an array of win-back offers that the subscriber is eligible for.
439
+ * Null is returned for Android and incompatible iOS versions. The promise will be rejected if configure has not been
440
+ * called yet or if there's an error getting the payment discount.
441
+ */
442
+ static getEligibleWinBackOffersForPackage(aPackage: PurchasesPackage): Promise<[PurchasesWinBackOffer] | undefined>;
443
+ /**
444
+ * iOS only. Purchase a product applying a given win-back offer.
445
+ *
446
+ * Only available on iOS 18.0+ when StoreKit 2 is enabled.
447
+ *
448
+ * @param {PurchasesStoreProduct} product The product you want to purchase
449
+ * @param {PurchasesWinBackOffer} winBackOffer Win-back offer to apply to this package. Retrieve this offer using getEligibleWinBackOffers.
450
+ * @returns {Promise<{ productIdentifier: string, customerInfo:CustomerInfo }>} A promise of an object containing
451
+ * a customer info object and a product identifier. Rejections return an error code,
452
+ * a boolean indicating if the user cancelled the purchase, and an object with more information. The promise will be
453
+ * rejected if configure has not been called yet.
454
+ */
455
+ static purchaseProductWithWinBackOffer(product: PurchasesStoreProduct, winBackOffer: PurchasesWinBackOffer): Promise<MakePurchaseResult>;
456
+ /**
457
+ * iOS only. Purchase a package applying a given win-back offer.
458
+ *
459
+ * Only available on iOS 18.0+ when StoreKit 2 is enabled.
460
+ *
461
+ * @param {PurchasesStoreProduct} product The product you want to purchase
462
+ * @param {PurchasesWinBackOffer} winBackOffer Win-back offer to apply to this package. Retrieve this offer using getEligibleWinBackOffers.
463
+ * @returns {Promise<{ productIdentifier: string, customerInfo:CustomerInfo }>} A promise of an object containing
464
+ * a customer info object and a product identifier. Rejections return an error code,
465
+ * a boolean indicating if the user cancelled the purchase, and an object with more information. The promise will be
466
+ * rejected if configure has not been called yet.
467
+ */
468
+ static purchasePackageWithWinBackOffer(aPackage: PurchasesPackage, winBackOffer: PurchasesWinBackOffer): Promise<MakePurchaseResult>;
423
469
  /**
424
470
  * Invalidates the cache for customer information.
425
471
  *
package/dist/purchases.js CHANGED
@@ -802,6 +802,122 @@ var Purchases = /** @class */ (function () {
802
802
  });
803
803
  });
804
804
  };
805
+ /**
806
+ * iOS only. Use this function to retrieve the eligible `PurchasesWinBackOffer`s that a subscriber
807
+ * is eligible for for a given `PurchasesProduct`.
808
+ *
809
+ * @param product The `PurchasesStoreProduct` the user intends to purchase.
810
+ * @returns { Promise<[PurchasesWinBackOffer]> } Returns an array of win-back offers that the subscriber is eligible for.
811
+ * Null is returned for Android and incompatible iOS versions. The promise will be rejected if configure has not been
812
+ * called yet or if there's an error getting the payment discount.
813
+ */
814
+ Purchases.getEligibleWinBackOffersForProduct = function (product) {
815
+ return __awaiter(this, void 0, void 0, function () {
816
+ return __generator(this, function (_a) {
817
+ switch (_a.label) {
818
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
819
+ case 1:
820
+ _a.sent();
821
+ if (react_native_2.Platform.OS === "android") {
822
+ return [2 /*return*/, Promise.resolve(undefined)];
823
+ }
824
+ return [2 /*return*/, RNPurchases.eligibleWinBackOffersForProductIdentifier(product.identifier)];
825
+ }
826
+ });
827
+ });
828
+ };
829
+ /**
830
+ * iOS only. Use this function to retrieve the eligible `PurchasesWinBackOffer`s that a subscriber
831
+ * is eligible for for a given `PurchasesPackage`.
832
+ *
833
+ * @param aPackage The `PurchasesPackage` the user intends to purchase.
834
+ * @returns { Promise<[PurchasesWinBackOffer]> } Returns an array of win-back offers that the subscriber is eligible for.
835
+ * Null is returned for Android and incompatible iOS versions. The promise will be rejected if configure has not been
836
+ * called yet or if there's an error getting the payment discount.
837
+ */
838
+ Purchases.getEligibleWinBackOffersForPackage = function (aPackage) {
839
+ return __awaiter(this, void 0, void 0, function () {
840
+ return __generator(this, function (_a) {
841
+ switch (_a.label) {
842
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
843
+ case 1:
844
+ _a.sent();
845
+ if (react_native_2.Platform.OS === "android") {
846
+ return [2 /*return*/, Promise.resolve(undefined)];
847
+ }
848
+ return [2 /*return*/, RNPurchases.eligibleWinBackOffersForProductIdentifier(aPackage.product.identifier)];
849
+ }
850
+ });
851
+ });
852
+ };
853
+ /**
854
+ * iOS only. Purchase a product applying a given win-back offer.
855
+ *
856
+ * Only available on iOS 18.0+ when StoreKit 2 is enabled.
857
+ *
858
+ * @param {PurchasesStoreProduct} product The product you want to purchase
859
+ * @param {PurchasesWinBackOffer} winBackOffer Win-back offer to apply to this package. Retrieve this offer using getEligibleWinBackOffers.
860
+ * @returns {Promise<{ productIdentifier: string, customerInfo:CustomerInfo }>} A promise of an object containing
861
+ * a customer info object and a product identifier. Rejections return an error code,
862
+ * a boolean indicating if the user cancelled the purchase, and an object with more information. The promise will be
863
+ * rejected if configure has not been called yet.
864
+ */
865
+ Purchases.purchaseProductWithWinBackOffer = function (product, winBackOffer) {
866
+ return __awaiter(this, void 0, void 0, function () {
867
+ return __generator(this, function (_a) {
868
+ switch (_a.label) {
869
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
870
+ case 1:
871
+ _a.sent();
872
+ if (typeof winBackOffer === "undefined" || winBackOffer == null) {
873
+ throw new Error("A win-back offer is required");
874
+ }
875
+ if (react_native_2.Platform.OS === "android") {
876
+ throw new purchases_typescript_internal_1.UnsupportedPlatformError();
877
+ }
878
+ return [2 /*return*/, RNPurchases.purchaseProductWithWinBackOffer(product.identifier, winBackOffer.identifier).catch(function (error) {
879
+ error.userCancelled =
880
+ error.code === purchases_typescript_internal_1.PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
881
+ throw error;
882
+ })];
883
+ }
884
+ });
885
+ });
886
+ };
887
+ /**
888
+ * iOS only. Purchase a package applying a given win-back offer.
889
+ *
890
+ * Only available on iOS 18.0+ when StoreKit 2 is enabled.
891
+ *
892
+ * @param {PurchasesStoreProduct} product The product you want to purchase
893
+ * @param {PurchasesWinBackOffer} winBackOffer Win-back offer to apply to this package. Retrieve this offer using getEligibleWinBackOffers.
894
+ * @returns {Promise<{ productIdentifier: string, customerInfo:CustomerInfo }>} A promise of an object containing
895
+ * a customer info object and a product identifier. Rejections return an error code,
896
+ * a boolean indicating if the user cancelled the purchase, and an object with more information. The promise will be
897
+ * rejected if configure has not been called yet.
898
+ */
899
+ Purchases.purchasePackageWithWinBackOffer = function (aPackage, winBackOffer) {
900
+ return __awaiter(this, void 0, void 0, function () {
901
+ return __generator(this, function (_a) {
902
+ switch (_a.label) {
903
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
904
+ case 1:
905
+ _a.sent();
906
+ if (typeof winBackOffer === "undefined" || winBackOffer == null) {
907
+ throw new Error("A win-back offer is required");
908
+ }
909
+ if (react_native_2.Platform.OS === "android") {
910
+ throw new purchases_typescript_internal_1.UnsupportedPlatformError();
911
+ }
912
+ return [2 /*return*/, RNPurchases.purchasePackageWithWinBackOffer(aPackage.identifier, aPackage.presentedOfferingContext, winBackOffer.identifier).catch(function (error) {
913
+ error.userCancelled =
914
+ error.code === purchases_typescript_internal_1.PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR;
915
+ throw error;
916
+ })];
917
+ }
918
+ });
919
+ });
920
+ };
805
921
  /**
806
922
  * Invalidates the cache for customer information.
807
923
  *
package/ios/RNPurchases.m CHANGED
@@ -246,6 +246,60 @@ static void logUnavailablePresentCodeRedemptionSheet() {
246
246
  NSLog(@"[Purchases] Warning: tried to present codeRedemptionSheet, but it's only available on iOS 14.0 or greater.");
247
247
  }
248
248
 
249
+ #pragma mark - Win-Back getOfferings
250
+ RCT_EXPORT_METHOD(eligibleWinBackOffersForProductIdentifier:(nonnull NSString *)productID
251
+ resolve:(RCTPromiseResolveBlock)resolve
252
+ reject:(RCTPromiseRejectBlock)reject) {
253
+ if (@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *)) {
254
+ [RCCommonFunctionality eligibleWinBackOffersForProductIdentifier:productID
255
+ completionBlock:^(NSArray<NSDictionary *> * _Nullable offers, RCErrorContainer * _Nullable errorContainer) {
256
+ if (errorContainer) {
257
+ reject(
258
+ [NSString stringWithFormat:@"%ld", (long)errorContainer.code],
259
+ errorContainer.message,
260
+ errorContainer.error
261
+ );
262
+ } else {
263
+ resolve(offers ?: @[]);
264
+ }
265
+ }];
266
+ } else {
267
+ NSError *error = [self createUnsupportedErrorWithDescription:@"iOS win-back offers are only available on iOS 18.0 or greater."];
268
+ reject([NSString stringWithFormat:@"%ld", (long)error.code], [error localizedDescription], error);
269
+ }
270
+ }
271
+
272
+ RCT_EXPORT_METHOD(purchaseProductWithWinBackOffer:(nonnull NSString *)productID
273
+ winBackOfferID:(nonnull NSString *)winBackOfferID
274
+ resolve:(RCTPromiseResolveBlock)resolve
275
+ reject:(RCTPromiseRejectBlock)reject) {
276
+ if (@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *)) {
277
+ [RCCommonFunctionality purchaseProduct:productID
278
+ winBackOfferID:winBackOfferID
279
+ completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
280
+ } else {
281
+ NSError *error = [self createUnsupportedErrorWithDescription:@"iOS win-back offers are only available on iOS 18.0 or greater."];
282
+ reject([NSString stringWithFormat:@"%ld", (long)error.code], [error localizedDescription], error);
283
+ }
284
+ }
285
+
286
+ RCT_EXPORT_METHOD(purchasePackageWithWinBackOffer:(nonnull NSString *)packageID
287
+ presentedOfferingContext:(NSDictionary *)presentedOfferingContext
288
+ winBackOfferID:(nonnull NSString *)winBackOfferID
289
+ resolve:(RCTPromiseResolveBlock)resolve
290
+ reject:(RCTPromiseRejectBlock)reject) {
291
+ if (@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *)) {
292
+ [RCCommonFunctionality purchasePackage:packageID
293
+ presentedOfferingContext:presentedOfferingContext
294
+ winBackOfferID:winBackOfferID
295
+ completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
296
+ } else {
297
+ NSError *error = [self createUnsupportedErrorWithDescription:@"iOS win-back offers are only available on iOS 18.0 or greater."];
298
+ reject([NSString stringWithFormat:@"%ld", (long)error.code], [error localizedDescription], error);
299
+ }
300
+ }
301
+
302
+
249
303
  #pragma mark - Subscriber Attributes
250
304
 
251
305
  RCT_EXPORT_METHOD(setProxyURLString:(nullable NSString *)proxyURLString
@@ -443,10 +497,7 @@ RCT_EXPORT_METHOD(recordPurchaseForProductID:(nonnull NSString *)productID
443
497
  completion:[self getResponseCompletionBlockWithResolve:resolve
444
498
  reject:reject]];
445
499
  } else {
446
- NSString* description = @"Tried to handle transaction made by your app, but this functionality is only available on iOS 15.0 or greater.";
447
- NSError* error = [[NSError alloc] initWithDomain: RCPurchasesErrorCodeDomain
448
- code: RCUnsupportedError
449
- userInfo: @{NSLocalizedDescriptionKey : description}];
500
+ NSError *error = [self createUnsupportedErrorWithDescription:@"Tried to handle transaction made by your app, but this functionality is only available on iOS 15.0 or greater."];
450
501
  reject([NSString stringWithFormat:@"%ld", (long) error.code], [error localizedDescription], error);
451
502
  }
452
503
  }
@@ -502,12 +553,18 @@ readyForPromotedProduct:(RCStoreProduct *)product
502
553
  };
503
554
  }
504
555
 
556
+ - (NSError *)createUnsupportedErrorWithDescription:(NSString *)description {
557
+ return [[NSError alloc] initWithDomain:RCPurchasesErrorCodeDomain
558
+ code:RCUnsupportedError
559
+ userInfo:@{NSLocalizedDescriptionKey : description}];
560
+ }
561
+
505
562
  - (NSString *)platformFlavor {
506
563
  return @"react-native";
507
564
  }
508
565
 
509
566
  - (NSString *)platformFlavorVersion {
510
- return @"8.2.6";
567
+ return @"8.3.0";
511
568
  }
512
569
 
513
570
  @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": "8.2.6",
4
+ "version": "8.3.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",
@@ -100,6 +100,6 @@
100
100
  ]
101
101
  },
102
102
  "dependencies": {
103
- "@revenuecat/purchases-typescript-internal": "13.8.0"
103
+ "@revenuecat/purchases-typescript-internal": "13.12.0"
104
104
  }
105
105
  }