react-native-purchases 6.6.5 → 7.0.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", '6.1.2'
27
+ spec.dependency "PurchasesHybridCommon", '7.0.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 '6.6.5'
32
+ versionName '7.0.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:6.1.2'
124
+ implementation 'com.revenuecat.purchases:purchases-hybrid-common:7.0.0'
125
125
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
126
126
  }
@@ -2,4 +2,4 @@ android.useAndroidX=true
2
2
  Purchases_kotlinVersion=1.7.21
3
3
  Purchases_compileSdkVersion=28
4
4
  Purchases_targetSdkVersion=28
5
- Purchases_minSdkVersion=16
5
+ Purchases_minSdkVersion=19
@@ -1,5 +1,7 @@
1
1
  package com.revenuecat.purchases.react;
2
2
 
3
+ import static com.revenuecat.purchases.react.RNPurchasesConverters.convertMapToWriteableMap;
4
+
3
5
  import android.util.Log;
4
6
 
5
7
  import androidx.annotation.NonNull;
@@ -15,6 +17,7 @@ import com.facebook.react.bridge.ReadableMap;
15
17
  import com.facebook.react.bridge.WritableArray;
16
18
  import com.facebook.react.modules.core.DeviceEventManagerModule;
17
19
  import com.revenuecat.purchases.CustomerInfo;
20
+ import com.revenuecat.purchases.DangerousSettings;
18
21
  import com.revenuecat.purchases.Purchases;
19
22
  import com.revenuecat.purchases.Store;
20
23
  import com.revenuecat.purchases.common.PlatformInfo;
@@ -26,26 +29,24 @@ import com.revenuecat.purchases.hybridcommon.OnResultList;
26
29
  import com.revenuecat.purchases.hybridcommon.SubscriberAttributesKt;
27
30
  import com.revenuecat.purchases.hybridcommon.mappers.CustomerInfoMapperKt;
28
31
  import com.revenuecat.purchases.interfaces.UpdatedCustomerInfoListener;
29
- import com.revenuecat.purchases.models.GoogleProrationMode;
32
+ import com.revenuecat.purchases.models.InAppMessageType;
30
33
 
31
34
  import org.jetbrains.annotations.NotNull;
32
- import org.json.JSONException;
33
35
 
34
36
  import java.util.ArrayList;
35
37
  import java.util.HashMap;
36
38
  import java.util.List;
37
39
  import java.util.Map;
40
+ import java.util.Set;
38
41
 
39
42
  import kotlin.UninitializedPropertyAccessException;
40
43
 
41
- import static com.revenuecat.purchases.react.RNPurchasesConverters.convertMapToWriteableMap;
42
-
43
44
  public class RNPurchasesModule extends ReactContextBaseJavaModule implements UpdatedCustomerInfoListener {
44
45
 
45
46
  private static final String CUSTOMER_INFO_UPDATED = "Purchases-CustomerInfoUpdated";
46
47
  private static final String LOG_HANDLER_EVENT = "Purchases-LogHandlerEvent";
47
48
  public static final String PLATFORM_NAME = "react-native";
48
- public static final String PLUGIN_VERSION = "6.6.5";
49
+ public static final String PLUGIN_VERSION = "7.0.0";
49
50
 
50
51
  private final ReactApplicationContext reactContext;
51
52
 
@@ -82,13 +83,23 @@ public class RNPurchasesModule extends ReactContextBaseJavaModule implements Upd
82
83
  @ReactMethod
83
84
  public void setupPurchases(String apiKey, @Nullable String appUserID,
84
85
  boolean observerMode, @Nullable String userDefaultsSuiteName,
85
- @Nullable Boolean usesStoreKit2IfAvailable, boolean useAmazon) {
86
+ @Nullable Boolean usesStoreKit2IfAvailable, boolean useAmazon,
87
+ boolean shouldShowInAppMessagesAutomatically) {
86
88
  PlatformInfo platformInfo = new PlatformInfo(PLATFORM_NAME, PLUGIN_VERSION);
87
89
  Store store = Store.PLAY_STORE;
88
90
  if (useAmazon) {
89
91
  store = Store.AMAZON;
90
92
  }
91
- CommonKt.configure(reactContext, apiKey, appUserID, observerMode, platformInfo, store);
93
+ CommonKt.configure(
94
+ reactContext,
95
+ apiKey,
96
+ appUserID,
97
+ observerMode,
98
+ platformInfo,
99
+ store,
100
+ new DangerousSettings(),
101
+ shouldShowInAppMessagesAutomatically
102
+ );
92
103
  Purchases.getSharedInstance().setUpdatedCustomerInfoListener(this);
93
104
  }
94
105
 
@@ -457,6 +468,30 @@ public class RNPurchasesModule extends ReactContextBaseJavaModule implements Upd
457
468
  promise.resolve(null);
458
469
  }
459
470
 
471
+ @ReactMethod
472
+ public void showInAppMessages(ReadableArray messageTypes, final Promise promise) {
473
+ if (messageTypes == null) {
474
+ CommonKt.showInAppMessagesIfNeeded(getCurrentActivity());
475
+ } else {
476
+ ArrayList<InAppMessageType> messageTypesList = new ArrayList<>();
477
+ InAppMessageType[] inAppMessageTypes = InAppMessageType.values();
478
+ for (int i = 0; i < messageTypes.size(); i++) {
479
+ int messageTypeInt = messageTypes.getInt(i);
480
+ InAppMessageType messageType = null;
481
+ if (messageTypeInt < inAppMessageTypes.length) {
482
+ messageType = inAppMessageTypes[messageTypeInt];
483
+ }
484
+ if (messageType != null) {
485
+ messageTypesList.add(messageType);
486
+ } else {
487
+ Log.e("RNPurchases", "Invalid in-app message type: " + messageTypeInt);
488
+ }
489
+ }
490
+ CommonKt.showInAppMessagesIfNeeded(getCurrentActivity(), messageTypesList);
491
+ }
492
+ promise.resolve(null);
493
+ }
494
+
460
495
  // endregion
461
496
 
462
497
  //================================================================================
@@ -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 } 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 } from '@revenuecat/purchases-typescript-internal';
2
2
  export { PURCHASE_TYPE, BILLING_FEATURE, REFUND_REQUEST_STATUS, LOG_LEVEL, PurchasesConfiguration, CustomerInfoUpdateListener, ShouldPurchasePromoProductListener, MakePurchaseResult, LogHandler, LogInResult } from '@revenuecat/purchases-typescript-internal';
3
3
  export default class Purchases {
4
4
  /**
@@ -58,6 +58,12 @@ export default class Purchases {
58
58
  * @enum {string}
59
59
  */
60
60
  static LOG_LEVEL: typeof LOG_LEVEL;
61
+ /**
62
+ * List of valid in app message types.
63
+ * @readonly
64
+ * @enum {number}
65
+ */
66
+ static IN_APP_MESSAGE_TYPE: typeof IN_APP_MESSAGE_TYPE;
61
67
  /**
62
68
  * @internal
63
69
  */
@@ -78,7 +84,7 @@ export default class Purchases {
78
84
  * Set this if you would like the RevenueCat SDK to store its preferences in a different NSUserDefaults suite, otherwise it will use standardUserDefaults.
79
85
  * Default is null, which will make the SDK use standardUserDefaults.
80
86
  */
81
- static configure({ apiKey, appUserID, observerMode, userDefaultsSuiteName, usesStoreKit2IfAvailable, useAmazon }: PurchasesConfiguration): void;
87
+ static configure({ apiKey, appUserID, observerMode, userDefaultsSuiteName, usesStoreKit2IfAvailable, useAmazon, shouldShowInAppMessagesAutomatically }: PurchasesConfiguration): void;
82
88
  /**
83
89
  * @deprecated, configure behavior through the RevenueCat dashboard instead.
84
90
  * If an user tries to purchase a product that is active on the current app store account,
@@ -611,6 +617,18 @@ export default class Purchases {
611
617
  * refund request. Keep in mind the status could be REFUND_REQUEST_STATUS.USER_CANCELLED
612
618
  */
613
619
  static beginRefundRequestForProduct(storeProduct: PurchasesStoreProduct): Promise<REFUND_REQUEST_STATUS>;
620
+ /**
621
+ * Shows in-app messages available from the App Store or Google Play. You need to disable messages from showing
622
+ * automatically using [PurchasesConfiguration.shouldShowInAppMessagesAutomatically].
623
+ *
624
+ * Note: In iOS, this requires version 16+. In older versions the promise will be resolved successfully
625
+ * immediately.
626
+ *
627
+ * @param messageTypes An array of message types that the stores can display inside your app. Must be one of
628
+ * [IN_APP_MESSAGE_TYPE]. By default, is undefined and all message types will be shown.
629
+ * @returns {Promise<void>} The promise will be rejected if configure has not been called yet.
630
+ */
631
+ static showInAppMessages(messageTypes?: IN_APP_MESSAGE_TYPE[]): Promise<void>;
614
632
  /**
615
633
  * Check if configure has finished and Purchases has been configured.
616
634
  *
package/dist/purchases.js CHANGED
@@ -81,14 +81,14 @@ var Purchases = /** @class */ (function () {
81
81
  * Default is null, which will make the SDK use standardUserDefaults.
82
82
  */
83
83
  Purchases.configure = function (_a) {
84
- 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;
84
+ 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, _f = _a.shouldShowInAppMessagesAutomatically, shouldShowInAppMessagesAutomatically = _f === void 0 ? true : _f;
85
85
  if (apiKey === undefined || typeof apiKey !== "string") {
86
86
  throw new Error("Invalid API key. It must be called with an Object: configure({apiKey: \"key\"})");
87
87
  }
88
88
  if (appUserID !== null && typeof appUserID !== "undefined" && typeof appUserID !== "string") {
89
89
  throw new Error("appUserID needs to be a string");
90
90
  }
91
- RNPurchases.setupPurchases(apiKey, appUserID, observerMode, userDefaultsSuiteName, usesStoreKit2IfAvailable, useAmazon);
91
+ RNPurchases.setupPurchases(apiKey, appUserID, observerMode, userDefaultsSuiteName, usesStoreKit2IfAvailable, useAmazon, shouldShowInAppMessagesAutomatically);
92
92
  };
93
93
  /**
94
94
  * @deprecated, configure behavior through the RevenueCat dashboard instead.
@@ -1313,6 +1313,29 @@ var Purchases = /** @class */ (function () {
1313
1313
  });
1314
1314
  });
1315
1315
  };
1316
+ /**
1317
+ * Shows in-app messages available from the App Store or Google Play. You need to disable messages from showing
1318
+ * automatically using [PurchasesConfiguration.shouldShowInAppMessagesAutomatically].
1319
+ *
1320
+ * Note: In iOS, this requires version 16+. In older versions the promise will be resolved successfully
1321
+ * immediately.
1322
+ *
1323
+ * @param messageTypes An array of message types that the stores can display inside your app. Must be one of
1324
+ * [IN_APP_MESSAGE_TYPE]. By default, is undefined and all message types will be shown.
1325
+ * @returns {Promise<void>} The promise will be rejected if configure has not been called yet.
1326
+ */
1327
+ Purchases.showInAppMessages = function (messageTypes) {
1328
+ return __awaiter(this, void 0, void 0, function () {
1329
+ return __generator(this, function (_a) {
1330
+ switch (_a.label) {
1331
+ case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
1332
+ case 1:
1333
+ _a.sent();
1334
+ return [2 /*return*/, RNPurchases.showInAppMessages(messageTypes)];
1335
+ }
1336
+ });
1337
+ });
1338
+ };
1316
1339
  /**
1317
1340
  * Check if configure has finished and Purchases has been configured.
1318
1341
  *
@@ -1424,6 +1447,12 @@ var Purchases = /** @class */ (function () {
1424
1447
  * @enum {string}
1425
1448
  */
1426
1449
  Purchases.LOG_LEVEL = purchases_typescript_internal_1.LOG_LEVEL;
1450
+ /**
1451
+ * List of valid in app message types.
1452
+ * @readonly
1453
+ * @enum {number}
1454
+ */
1455
+ Purchases.IN_APP_MESSAGE_TYPE = purchases_typescript_internal_1.IN_APP_MESSAGE_TYPE;
1427
1456
  /**
1428
1457
  * @internal
1429
1458
  */
package/ios/RNPurchases.m CHANGED
@@ -42,7 +42,8 @@ RCT_EXPORT_METHOD(setupPurchases:(NSString *)apiKey
42
42
  observerMode:(BOOL)observerMode
43
43
  userDefaultsSuiteName:(nullable NSString *)userDefaultsSuiteName
44
44
  usesStoreKit2IfAvailable:(BOOL)usesStoreKit2IfAvailable
45
- useAmazon:(BOOL)useAmazon) {
45
+ useAmazon:(BOOL)useAmazon
46
+ shouldShowInAppMessagesAutomatically:(BOOL)shouldShowInAppMessagesAutomatically) {
46
47
  RCPurchases *purchases = [RCPurchases configureWithAPIKey:apiKey
47
48
  appUserID:appUserID
48
49
  observerMode:observerMode
@@ -50,7 +51,8 @@ RCT_EXPORT_METHOD(setupPurchases:(NSString *)apiKey
50
51
  platformFlavor:self.platformFlavor
51
52
  platformFlavorVersion:self.platformFlavorVersion
52
53
  usesStoreKit2IfAvailable:usesStoreKit2IfAvailable
53
- dangerousSettings:nil];
54
+ dangerousSettings:nil
55
+ shouldShowInAppMessagesAutomatically:shouldShowInAppMessagesAutomatically];
54
56
  purchases.delegate = self;
55
57
  }
56
58
 
@@ -375,6 +377,31 @@ RCT_EXPORT_METHOD(beginRefundRequestForProductId:(NSString *)productIdentifier
375
377
  #endif
376
378
  }
377
379
 
380
+ RCT_EXPORT_METHOD(showInAppMessages:(NSArray<NSNumber *> *)messageTypes
381
+ resolve:(RCTPromiseResolveBlock)resolve
382
+ reject:(RCTPromiseRejectBlock)reject) {
383
+ #if TARGET_OS_IPHONE
384
+ if (@available(iOS 16.0, *)) {
385
+ if (messageTypes == nil) {
386
+ [RCCommonFunctionality showStoreMessagesCompletion:^{
387
+ resolve(nil);
388
+ }];
389
+ } else {
390
+ NSSet *types = [[NSSet alloc] initWithArray:messageTypes];
391
+ [RCCommonFunctionality showStoreMessagesForTypes:types completion:^{
392
+ resolve(nil);
393
+ }];
394
+ }
395
+ } else {
396
+ NSLog(@"[Purchases] Warning: tried to showInAppMessages in iOS <16.0. That's not supported.");
397
+ resolve(nil);
398
+ }
399
+ #else
400
+ NSLog(@"[Purchases] Warning: tried to showInAppMessages in non-ios devices. That's not supported.");
401
+ resolve(nil);
402
+ #endif
403
+ }
404
+
378
405
  RCT_REMAP_METHOD(isConfigured,
379
406
  isConfiguredWithResolve:(RCTPromiseResolveBlock)resolve
380
407
  reject:(RCTPromiseRejectBlock)reject) {
@@ -443,7 +470,7 @@ readyForPromotedProduct:(RCStoreProduct *)product
443
470
  }
444
471
 
445
472
  - (NSString *)platformFlavorVersion {
446
- return @"6.6.5";
473
+ return @"7.0.0";
447
474
  }
448
475
 
449
476
  @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": "6.6.5",
4
+ "version": "7.0.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",
@@ -95,6 +95,6 @@
95
95
  ]
96
96
  },
97
97
  "dependencies": {
98
- "@revenuecat/purchases-typescript-internal": "6.1.2"
98
+ "@revenuecat/purchases-typescript-internal": "7.0.0"
99
99
  }
100
100
  }
@@ -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/6.6.5/" />
5
+ <meta http-equiv="refresh" content="0; url=https://revenuecat.github.io/react-native-purchases-docs/7.0.0/" />
6
6
  </head>
7
7
  <body>
8
8
  </body>
@@ -778,6 +778,7 @@ NativeModules.RNPurchases = {
778
778
  beginRefundRequestForActiveEntitlement: jest.fn(),
779
779
  beginRefundRequestForEntitlementId: jest.fn(),
780
780
  beginRefundRequestForProductId: jest.fn(),
781
+ showInAppMessages: jest.fn(),
781
782
  isConfigured: jest.fn()
782
783
  };
783
784