react-native-purchases 7.28.1 → 8.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.
package/README.md CHANGED
@@ -53,61 +53,11 @@ Our full SDK reference [can be found here](https://revenuecat.github.io/react-na
53
53
 
54
54
  ## Installation
55
55
 
56
- ExpoKit projects of version 33 or higher can successfully use react-native-purchases. If you haven't upgraded, you can follow [the instructions here to upgrade](https://docs.expo.io/versions/latest/expokit/expokit/#upgrading-expokit).
56
+ Expo supports in-app payments and is compatible with react-native-purchases. To use the library, [create a new project](https://docs.expo.dev/get-started/create-a-project/) and set up a [development build](https://docs.expo.dev/get-started/set-up-your-environment/?mode=development-build). A development build helps you iterate quickly and provides a complete development environment. After you've created the project, install the library:
57
57
 
58
- > ❗️ If you're planning on ejecting from Expo, upgrade your expo version _first_, THEN eject. It'll save you a whole lot of hassle. ❗️
59
-
60
- ### 1. Add the library to the project
61
-
62
- ```
63
- $ npm install react-native-purchases --save
64
- ```
65
-
66
- or
67
-
68
- ```
69
- $ yarn add react-native-purchases
70
- ```
71
-
72
- ### 2. Link library to the project
73
-
74
- ```
75
- $ react-native link react-native-purchases
76
58
  ```
77
-
78
- ### Additional iOS Setup
79
-
80
- #### If your project uses Cocoapods
81
- If your project already uses Cocoapods to install iOS dependencies, common in ExpoKit projects, linking the library should have added it to the podfile. If it hasn't, add the following to your project's podfile to reference the library from your node_modules folder:
82
-
83
- ```ruby
84
- pod 'RNPurchases', :path => '../node_modules/react-native-purchases'
85
- :inhibit_warnings => true
59
+ $ npx expo install react-native-purchases
86
60
  ```
87
61
 
88
- In your `ios` folder, run `pod install`. If you've just upgraded ExpoKit, you might need to upgrade cocoapods to the newest version: `sudo gem install cocoapods`.
89
-
90
- #### Migrating from manual installation (if your project doesn't use CocoapodsCreate)
91
-
92
- ##### Remove the Framework Reference from your project
93
-
94
- 1. Remove `Purchases.framework` and `PurchasesHybridCommon.framework` from the libraries section of the project.
95
-
96
- ##### Remove iOS Frameworks to Embedded Binaries
97
- 1. In Xcode, in project manager, select your app target.
98
- 1. Select the general tab
99
- 1. Look for `Purchases.framework` and `PurchasesHybridCommon.framework` in the Embedded Binaries section and remove them.
100
-
101
- Remove `$(PROJECT_DIR)/../node_modules/react-native-purchases/ios` from Framework Search paths in build settings
102
-
103
- ##### Remove Strip Frameworks Phase
104
- During the old manual installation instructions, now deprecated, we indicated to add a build phase to strip fat frameworks.
105
- 1. In Xcode, in project manager, select your app target.
106
- 2. Open the `Build Phases` tab
107
- 3. Remove the added `Strip Frameworks` phase
108
- 4. Clean `Derived Data`
109
-
110
- ##### Link static library
111
- The `react-native link` command should have added the `libRNPurchases.a` library to the _Linked Frameworks and Libraries_ section of your app target. If it hasn't add it like this:
112
-
113
- ![](https://media.giphy.com/media/U2MMgrdYlkRhEcy80J/giphy.gif)
62
+ ### Bare workflow
63
+ If you are using [bare workflow](https://docs.expo.dev/bare/overview/) (that is, your project is created using `react-native init`), [install `expo`](https://docs.expo.dev/bare/installing-expo-modules/) into your project and [leverage Expo CLI](https://docs.expo.dev/bare/using-expo-cli/) to use Expo tooling and services.
@@ -10,7 +10,7 @@ Pod::Spec.new do |spec|
10
10
  spec.authors = package['author']
11
11
  spec.homepage = "https://github.com/RevenueCat/react-native-purchases"
12
12
  spec.license = package['license']
13
- spec.platforms = {:ios => "11.0", :tvos => "11.0"}
13
+ spec.platforms = {:ios => "13.0", :tvos => "13.0"}
14
14
 
15
15
  spec.source = { :git => "https://github.com/RevenueCat/react-native-purchases.git" }
16
16
  spec.source_files = "ios/**/*.{h,m,swift}"
@@ -25,6 +25,6 @@ Pod::Spec.new do |spec|
25
25
  ]
26
26
 
27
27
  spec.dependency "React-Core"
28
- spec.dependency "PurchasesHybridCommon", '11.1.1'
28
+ spec.dependency "PurchasesHybridCommon", '13.0.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 '7.28.1'
32
+ versionName '8.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:11.1.1'
124
+ implementation 'com.revenuecat.purchases:purchases-hybrid-common:13.0.0'
125
125
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
126
126
  }
@@ -1,5 +1,5 @@
1
1
  android.useAndroidX=true
2
- Purchases_kotlinVersion=1.7.21
3
- Purchases_compileSdkVersion=28
4
- Purchases_targetSdkVersion=28
5
- Purchases_minSdkVersion=19
2
+ Purchases_kotlinVersion=1.8.22
3
+ Purchases_compileSdkVersion=34
4
+ Purchases_targetSdkVersion=34
5
+ Purchases_minSdkVersion=21
@@ -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 = "7.28.1";
50
+ public static final String PLUGIN_VERSION = "8.0.0";
51
51
 
52
52
  private final ReactApplicationContext reactContext;
53
53
 
@@ -83,10 +83,11 @@ public class RNPurchasesModule extends ReactContextBaseJavaModule implements Upd
83
83
 
84
84
  @ReactMethod
85
85
  public void setupPurchases(String apiKey, @Nullable String appUserID,
86
- boolean observerMode, @Nullable String userDefaultsSuiteName,
87
- @Nullable Boolean usesStoreKit2IfAvailable, boolean useAmazon,
86
+ @Nullable String purchasesAreCompletedBy, @Nullable String userDefaultsSuiteName,
87
+ @Nullable String storeKitVersion, boolean useAmazon,
88
88
  boolean shouldShowInAppMessagesAutomatically,
89
- @Nullable String entitlementVerificationMode) {
89
+ @Nullable String entitlementVerificationMode,
90
+ boolean pendingTransactionsForPrepaidPlansEnabled) {
90
91
  PlatformInfo platformInfo = new PlatformInfo(PLATFORM_NAME, PLUGIN_VERSION);
91
92
  Store store = Store.PLAY_STORE;
92
93
  if (useAmazon) {
@@ -96,12 +97,13 @@ public class RNPurchasesModule extends ReactContextBaseJavaModule implements Upd
96
97
  reactContext,
97
98
  apiKey,
98
99
  appUserID,
99
- observerMode ? PurchasesAreCompletedBy.MY_APP : PurchasesAreCompletedBy.REVENUECAT,
100
+ purchasesAreCompletedBy,
100
101
  platformInfo,
101
102
  store,
102
103
  new DangerousSettings(),
103
104
  shouldShowInAppMessagesAutomatically,
104
- entitlementVerificationMode
105
+ entitlementVerificationMode,
106
+ pendingTransactionsForPrepaidPlansEnabled
105
107
  );
106
108
  Purchases.getSharedInstance().setUpdatedCustomerInfoListener(this);
107
109
  }
@@ -275,12 +277,6 @@ public class RNPurchasesModule extends ReactContextBaseJavaModule implements Upd
275
277
  CommonKt.getCustomerInfo(getOnResult(promise));
276
278
  }
277
279
 
278
- @ReactMethod
279
- public void setFinishTransactions(boolean enabled) {
280
- CommonKt.setPurchasesAreCompletedBy(enabled ?
281
- PurchasesAreCompletedBy.REVENUECAT : PurchasesAreCompletedBy.MY_APP);
282
- }
283
-
284
280
  @ReactMethod
285
281
  public void syncPurchases() {
286
282
  CommonKt.syncPurchases();
@@ -463,14 +459,23 @@ public class RNPurchasesModule extends ReactContextBaseJavaModule implements Upd
463
459
  }
464
460
 
465
461
  @ReactMethod
466
- public void syncObserverModeAmazonPurchase(String productID, String receiptID,
462
+ public void syncAmazonPurchase(String productID, String receiptID,
467
463
  String amazonUserID, String isoCurrencyCode,
468
464
  Double price, final Promise promise) {
469
- Purchases.getSharedInstance().syncObserverModeAmazonPurchase(productID, receiptID,
465
+ Purchases.getSharedInstance().syncAmazonPurchase(productID, receiptID,
470
466
  amazonUserID, isoCurrencyCode, price);
471
467
  promise.resolve(null);
472
468
  }
473
469
 
470
+ @ReactMethod
471
+ @Deprecated // Use syncAmazonPurchase instead
472
+ public void syncObserverModeAmazonPurchase(String productID, String receiptID,
473
+ String amazonUserID, String isoCurrencyCode,
474
+ Double price, final Promise promise) {
475
+ syncAmazonPurchase(productID, receiptID, amazonUserID, isoCurrencyCode, price, promise);
476
+ }
477
+
478
+
474
479
  @ReactMethod
475
480
  public void showInAppMessages(ReadableArray messageTypes, final Promise promise) {
476
481
  if (messageTypes == null) {
@@ -1,5 +1,5 @@
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, PurchasesOffering } from "@revenuecat/purchases-typescript-internal";
2
- export { 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, ENTITLEMENT_VERIFICATION_MODE, VERIFICATION_RESULT, STOREKIT_VERSION, PurchasesStoreTransaction, PurchasesOffering, PURCHASES_ARE_COMPLETED_BY_TYPE } from "@revenuecat/purchases-typescript-internal";
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
  /**
5
5
  * Supported SKU types.
@@ -76,6 +76,18 @@ export default class Purchases {
76
76
  * @enum {string}
77
77
  */
78
78
  static VERIFICATION_RESULT: typeof VERIFICATION_RESULT;
79
+ /**
80
+ * Enum of StoreKit version.
81
+ * @readonly
82
+ * @enum {string}
83
+ */
84
+ static STOREKIT_VERSION: typeof STOREKIT_VERSION;
85
+ /**
86
+ * Enum of PurchasesAreCompletedByType.
87
+ * @readonly
88
+ * @enum {string}
89
+ */
90
+ static PURCHASES_ARE_COMPLETED_BY_TYPE: typeof PURCHASES_ARE_COMPLETED_BY_TYPE;
79
91
  /**
80
92
  * @internal
81
93
  */
@@ -88,16 +100,18 @@ export default class Purchases {
88
100
  * Sets up Purchases with your API key and an app user id.
89
101
  * @param {String} apiKey RevenueCat API Key. Needs to be a String
90
102
  * @param {String?} appUserID An optional unique id for identifying the user. Needs to be a string.
91
- * @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.
92
- * @param {boolean} [usesStoreKit2IfAvailable=false] DEPRECATED. An optional boolean. iOS-only. Defaults to FALSE. Setting this to TRUE will enable StoreKit2 on compatible devices.
93
- * We recommend not using this parameter, letting RevenueCat decide for you which StoreKit implementation to use.
103
+ * @param {PurchasesAreCompletedBy} [purchasesAreCompletedBy=PURCHASES_ARE_COMPLETED_BY_TYPE.REVENUECAT] Set this to an instance of PurchasesAreCompletedByMyApp if you have your own IAP implementation and want to use only RevenueCat's backend. Default is PURCHASES_ARE_COMPLETED_BY_TYPE.REVENUECAT.
104
+ * @param {STOREKIT_VERSION} [storeKitVersion=DEFAULT] iOS-only. Defaults to STOREKIT_2. StoreKit 2 is only available on iOS 16+. StoreKit 1 will be used for previous iOS versions regardless of this setting.
94
105
  * @param {ENTITLEMENT_VERIFICATION_MODE} [entitlementVerificationMode=ENTITLEMENT_VERIFICATION_MODE.DISABLED] Sets the entitlement verifciation mode to use. For more details, check https://rev.cat/trusted-entitlements
95
106
  * @param {boolean} [useAmazon=false] An optional boolean. Android-only. Set this to TRUE to enable Amazon on compatible devices.
96
107
  * @param {String?} userDefaultsSuiteName An optional string. iOS-only, will be ignored for Android.
97
108
  * Set this if you would like the RevenueCat SDK to store its preferences in a different NSUserDefaults suite, otherwise it will use standardUserDefaults.
98
109
  * Default is null, which will make the SDK use standardUserDefaults.
110
+ * @param {boolean} [pendingTransactionsForPrepaidPlansEnabled=false] An optional boolean. Android-only. Set this to TRUE to enable pending transactions for prepaid subscriptions in Google Play.
111
+ *
112
+ * @warning If you use purchasesAreCompletedBy=PurchasesAreCompletedByMyApp, you must also provide a value for storeKitVersion.
99
113
  */
100
- static configure({ apiKey, appUserID, observerMode, userDefaultsSuiteName, usesStoreKit2IfAvailable, useAmazon, shouldShowInAppMessagesAutomatically, entitlementVerificationMode, }: PurchasesConfiguration): void;
114
+ static configure({ apiKey, appUserID, purchasesAreCompletedBy, userDefaultsSuiteName, storeKitVersion, useAmazon, shouldShowInAppMessagesAutomatically, entitlementVerificationMode, pendingTransactionsForPrepaidPlansEnabled, }: PurchasesConfiguration): void;
101
115
  /**
102
116
  * @deprecated, configure behavior through the RevenueCat dashboard instead.
103
117
  * If an user tries to purchase a product that is active on the current app store account,
@@ -107,12 +121,6 @@ export default class Purchases {
107
121
  * @returns {Promise<void>} The promise will be rejected if configure has not been called yet.
108
122
  */
109
123
  static setAllowSharingStoreAccount(allowSharing: boolean): Promise<void>;
110
- /**
111
- * @param {boolean} finishTransactions Set finishTransactions to false if you aren't using Purchases SDK to
112
- * make the purchase
113
- * @returns {Promise<void>} The promise will be rejected if configure has not been called yet.
114
- */
115
- static setFinishTransactions(finishTransactions: boolean): Promise<void>;
116
124
  /**
117
125
  * iOS only.
118
126
  * @param {boolean} simulatesAskToBuyInSandbox Set this property to true *only* when testing the ask-to-buy / SCA
@@ -338,14 +346,40 @@ export default class Purchases {
338
346
  * @returns {Promise<void>} The promise will be rejected if configure has not been called yet or if there's an error
339
347
  * syncing purchases.
340
348
  */
349
+ static syncAmazonPurchase(productID: string, receiptID: string, amazonUserID: string, isoCurrencyCode?: string | null, price?: number | null): Promise<void>;
350
+ /**
351
+ * @deprecated, use syncAmazonPurchase instead.
352
+ *
353
+ * This method will send a purchase to the RevenueCat backend. This function should only be called if you are
354
+ * in Amazon observer mode or performing a client side migration of your current users to RevenueCat.
355
+ *
356
+ * The receipt IDs are cached if successfully posted so they are not posted more than once.
357
+ *
358
+ * @param {string} productID Product ID associated to the purchase.
359
+ * @param {string} receiptID ReceiptId that represents the Amazon purchase.
360
+ * @param {string} amazonUserID Amazon's userID. This parameter will be ignored when syncing a Google purchase.
361
+ * @param {(string|null|undefined)} isoCurrencyCode Product's currency code in ISO 4217 format.
362
+ * @param {(number|null|undefined)} price Product's price.
363
+ * @returns {Promise<void>} The promise will be rejected if configure has not been called yet or if there's an error
364
+ * syncing purchases.
365
+ */
341
366
  static syncObserverModeAmazonPurchase(productID: string, receiptID: string, amazonUserID: string, isoCurrencyCode?: string | null, price?: number | null): Promise<void>;
342
367
  /**
343
- * @deprecated, use enableAdServicesAttributionTokenCollection instead.
344
- * Enable automatic collection of Apple Search Ad attribution. Disabled by default
345
- * @param {boolean} enabled Enable or not automatic apple search ads attribution collection
346
- * @returns {Promise<void>} The promise will be rejected if configure has not been called yet.
368
+ * iOS only. Always returns an error on iOS < 15.
369
+ *
370
+ * Use this method only if you already have your own IAP implementation using StoreKit 2 and want to use
371
+ * RevenueCat's backend. If you are using StoreKit 1 for your implementation, you do not need this method.
372
+ *
373
+ * You only need to use this method with *new* purchases. Subscription updates are observed automatically.
374
+ *
375
+ * Important: This should only be used if you have set PurchasesAreCompletedBy to MY_APP during SDK configuration.
376
+ *
377
+ * @warning You need to finish the transaction yourself after calling this method.
378
+ *
379
+ * @param {string} productID Product ID that was just purchased
380
+ * @returns {Promise<PurchasesStoreTransaction>} If there was a transacton found and handled for the provided product ID.
347
381
  */
348
- static setAutomaticAppleSearchAdsAttributionCollection(enabled: boolean): Promise<void>;
382
+ static recordPurchase(productID: string): Promise<PurchasesStoreTransaction>;
349
383
  /**
350
384
  * Enable automatic collection of Apple Search Ad attribution on iOS. Disabled by default
351
385
  * @returns {Promise<void>} The promise will be rejected if configure has not been called yet.
@@ -666,5 +700,6 @@ export default class Purchases {
666
700
  private static throwIfNotConfigured;
667
701
  private static throwIfAndroidPlatform;
668
702
  private static throwIfIOSPlatform;
703
+ private static isPurchasesAreCompletedByMyApp;
669
704
  private static convertIntToRefundRequestStatus;
670
705
  }
package/dist/purchases.js CHANGED
@@ -36,15 +36,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.LOG_LEVEL = exports.REFUND_REQUEST_STATUS = exports.BILLING_FEATURE = exports.PURCHASE_TYPE = void 0;
39
+ exports.STOREKIT_VERSION = exports.LOG_LEVEL = exports.REFUND_REQUEST_STATUS = exports.BILLING_FEATURE = exports.PURCHASES_ARE_COMPLETED_BY_TYPE = exports.PURCHASE_TYPE = void 0;
40
40
  var react_native_1 = require("react-native");
41
41
  var purchases_typescript_internal_1 = require("@revenuecat/purchases-typescript-internal");
42
42
  // This export is kept to keep backwards compatibility to any possible users using this file directly
43
43
  var purchases_typescript_internal_2 = require("@revenuecat/purchases-typescript-internal");
44
44
  Object.defineProperty(exports, "PURCHASE_TYPE", { enumerable: true, get: function () { return purchases_typescript_internal_2.PURCHASE_TYPE; } });
45
+ Object.defineProperty(exports, "PURCHASES_ARE_COMPLETED_BY_TYPE", { enumerable: true, get: function () { return purchases_typescript_internal_2.PURCHASES_ARE_COMPLETED_BY_TYPE; } });
45
46
  Object.defineProperty(exports, "BILLING_FEATURE", { enumerable: true, get: function () { return purchases_typescript_internal_2.BILLING_FEATURE; } });
46
47
  Object.defineProperty(exports, "REFUND_REQUEST_STATUS", { enumerable: true, get: function () { return purchases_typescript_internal_2.REFUND_REQUEST_STATUS; } });
47
48
  Object.defineProperty(exports, "LOG_LEVEL", { enumerable: true, get: function () { return purchases_typescript_internal_2.LOG_LEVEL; } });
49
+ Object.defineProperty(exports, "STOREKIT_VERSION", { enumerable: true, get: function () { return purchases_typescript_internal_2.STOREKIT_VERSION; } });
48
50
  var react_native_2 = require("react-native");
49
51
  var RNPurchases = react_native_1.NativeModules.RNPurchases;
50
52
  var eventEmitter = new react_native_1.NativeEventEmitter(RNPurchases);
@@ -72,17 +74,19 @@ var Purchases = /** @class */ (function () {
72
74
  * Sets up Purchases with your API key and an app user id.
73
75
  * @param {String} apiKey RevenueCat API Key. Needs to be a String
74
76
  * @param {String?} appUserID An optional unique id for identifying the user. Needs to be a string.
75
- * @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.
76
- * @param {boolean} [usesStoreKit2IfAvailable=false] DEPRECATED. An optional boolean. iOS-only. Defaults to FALSE. Setting this to TRUE will enable StoreKit2 on compatible devices.
77
- * We recommend not using this parameter, letting RevenueCat decide for you which StoreKit implementation to use.
77
+ * @param {PurchasesAreCompletedBy} [purchasesAreCompletedBy=PURCHASES_ARE_COMPLETED_BY_TYPE.REVENUECAT] Set this to an instance of PurchasesAreCompletedByMyApp if you have your own IAP implementation and want to use only RevenueCat's backend. Default is PURCHASES_ARE_COMPLETED_BY_TYPE.REVENUECAT.
78
+ * @param {STOREKIT_VERSION} [storeKitVersion=DEFAULT] iOS-only. Defaults to STOREKIT_2. StoreKit 2 is only available on iOS 16+. StoreKit 1 will be used for previous iOS versions regardless of this setting.
78
79
  * @param {ENTITLEMENT_VERIFICATION_MODE} [entitlementVerificationMode=ENTITLEMENT_VERIFICATION_MODE.DISABLED] Sets the entitlement verifciation mode to use. For more details, check https://rev.cat/trusted-entitlements
79
80
  * @param {boolean} [useAmazon=false] An optional boolean. Android-only. Set this to TRUE to enable Amazon on compatible devices.
80
81
  * @param {String?} userDefaultsSuiteName An optional string. iOS-only, will be ignored for Android.
81
82
  * Set this if you would like the RevenueCat SDK to store its preferences in a different NSUserDefaults suite, otherwise it will use standardUserDefaults.
82
83
  * Default is null, which will make the SDK use standardUserDefaults.
84
+ * @param {boolean} [pendingTransactionsForPrepaidPlansEnabled=false] An optional boolean. Android-only. Set this to TRUE to enable pending transactions for prepaid subscriptions in Google Play.
85
+ *
86
+ * @warning If you use purchasesAreCompletedBy=PurchasesAreCompletedByMyApp, you must also provide a value for storeKitVersion.
83
87
  */
84
88
  Purchases.configure = function (_a) {
85
- 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, _g = _a.entitlementVerificationMode, entitlementVerificationMode = _g === void 0 ? purchases_typescript_internal_1.ENTITLEMENT_VERIFICATION_MODE.DISABLED : _g;
89
+ var apiKey = _a.apiKey, _b = _a.appUserID, appUserID = _b === void 0 ? null : _b, _c = _a.purchasesAreCompletedBy, purchasesAreCompletedBy = _c === void 0 ? purchases_typescript_internal_1.PURCHASES_ARE_COMPLETED_BY_TYPE.REVENUECAT : _c, userDefaultsSuiteName = _a.userDefaultsSuiteName, _d = _a.storeKitVersion, storeKitVersion = _d === void 0 ? purchases_typescript_internal_1.STOREKIT_VERSION.DEFAULT : _d, _e = _a.useAmazon, useAmazon = _e === void 0 ? false : _e, _f = _a.shouldShowInAppMessagesAutomatically, shouldShowInAppMessagesAutomatically = _f === void 0 ? true : _f, _g = _a.entitlementVerificationMode, entitlementVerificationMode = _g === void 0 ? purchases_typescript_internal_1.ENTITLEMENT_VERIFICATION_MODE.DISABLED : _g, _h = _a.pendingTransactionsForPrepaidPlansEnabled, pendingTransactionsForPrepaidPlansEnabled = _h === void 0 ? false : _h;
86
90
  if (apiKey === undefined || typeof apiKey !== "string") {
87
91
  throw new Error('Invalid API key. It must be called with an Object: configure({apiKey: "key"})');
88
92
  }
@@ -91,7 +95,20 @@ var Purchases = /** @class */ (function () {
91
95
  typeof appUserID !== "string") {
92
96
  throw new Error("appUserID needs to be a string");
93
97
  }
94
- RNPurchases.setupPurchases(apiKey, appUserID, observerMode, userDefaultsSuiteName, usesStoreKit2IfAvailable, useAmazon, shouldShowInAppMessagesAutomatically, entitlementVerificationMode);
98
+ var purchasesCompletedByToUse = purchases_typescript_internal_1.PURCHASES_ARE_COMPLETED_BY_TYPE.REVENUECAT;
99
+ var storeKitVersionToUse = storeKitVersion;
100
+ if (Purchases.isPurchasesAreCompletedByMyApp(purchasesAreCompletedBy)) {
101
+ purchasesCompletedByToUse = purchases_typescript_internal_1.PURCHASES_ARE_COMPLETED_BY_TYPE.MY_APP;
102
+ storeKitVersionToUse = purchasesAreCompletedBy.storeKitVersion;
103
+ if (storeKitVersionToUse !== storeKitVersion) {
104
+ // Typically, console messages aren't used in TS libraries, but in this case it's worth calling out the difference in
105
+ // StoreKit versions, and since the difference isn't possible farther down the call chain, we should go ahead
106
+ // and log it here.
107
+ // tslint:disable-next-line:no-console
108
+ console.warn("Warning: The storeKitVersion in purchasesAreCompletedBy does not match the function's storeKitVersion parameter. We will use the value found in purchasesAreCompletedBy.");
109
+ }
110
+ }
111
+ RNPurchases.setupPurchases(apiKey, appUserID, purchasesCompletedByToUse, userDefaultsSuiteName, storeKitVersionToUse, useAmazon, shouldShowInAppMessagesAutomatically, entitlementVerificationMode, pendingTransactionsForPrepaidPlansEnabled);
95
112
  };
96
113
  /**
97
114
  * @deprecated, configure behavior through the RevenueCat dashboard instead.
@@ -114,24 +131,6 @@ var Purchases = /** @class */ (function () {
114
131
  });
115
132
  });
116
133
  };
117
- /**
118
- * @param {boolean} finishTransactions Set finishTransactions to false if you aren't using Purchases SDK to
119
- * make the purchase
120
- * @returns {Promise<void>} The promise will be rejected if configure has not been called yet.
121
- */
122
- Purchases.setFinishTransactions = function (finishTransactions) {
123
- return __awaiter(this, void 0, void 0, function () {
124
- return __generator(this, function (_a) {
125
- switch (_a.label) {
126
- case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
127
- case 1:
128
- _a.sent();
129
- RNPurchases.setFinishTransactions(finishTransactions);
130
- return [2 /*return*/];
131
- }
132
- });
133
- });
134
- };
135
134
  /**
136
135
  * iOS only.
137
136
  * @param {boolean} simulatesAskToBuyInSandbox Set this property to true *only* when testing the ask-to-buy / SCA
@@ -263,9 +262,9 @@ var Purchases = /** @class */ (function () {
263
262
  * Rejections return an error code, and a userInfo object with more information. The promise will also be rejected
264
263
  * if configure has not been called yet.
265
264
  */
266
- Purchases.getProducts = function (productIdentifiers, type) {
267
- if (type === void 0) { type = purchases_typescript_internal_1.PRODUCT_CATEGORY.SUBSCRIPTION; }
268
- return __awaiter(this, void 0, void 0, function () {
265
+ Purchases.getProducts = function (productIdentifiers_1) {
266
+ return __awaiter(this, arguments, void 0, function (productIdentifiers, type) {
267
+ if (type === void 0) { type = purchases_typescript_internal_1.PRODUCT_CATEGORY.SUBSCRIPTION; }
269
268
  return __generator(this, function (_a) {
270
269
  switch (_a.label) {
271
270
  case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
@@ -285,9 +284,9 @@ var Purchases = /** @class */ (function () {
285
284
  * @param {String} type Optional type of product, can be inapp or subs. Subs by default
286
285
  * @deprecated, use purchaseStoreProduct instead
287
286
  */
288
- Purchases.purchaseProduct = function (productIdentifier, upgradeInfo, type) {
289
- if (type === void 0) { type = purchases_typescript_internal_1.PURCHASE_TYPE.SUBS; }
290
- return __awaiter(this, void 0, void 0, function () {
287
+ Purchases.purchaseProduct = function (productIdentifier_1, upgradeInfo_1) {
288
+ return __awaiter(this, arguments, void 0, function (productIdentifier, upgradeInfo, type) {
289
+ if (type === void 0) { type = purchases_typescript_internal_1.PURCHASE_TYPE.SUBS; }
291
290
  return __generator(this, function (_a) {
292
291
  switch (_a.label) {
293
292
  case 0: return [4 /*yield*/, Purchases.throwIfNotConfigured()];
@@ -628,6 +627,38 @@ var Purchases = /** @class */ (function () {
628
627
  * @returns {Promise<void>} The promise will be rejected if configure has not been called yet or if there's an error
629
628
  * syncing purchases.
630
629
  */
630
+ Purchases.syncAmazonPurchase = function (productID, receiptID, amazonUserID, isoCurrencyCode, price) {
631
+ return __awaiter(this, void 0, void 0, function () {
632
+ return __generator(this, function (_a) {
633
+ switch (_a.label) {
634
+ case 0: return [4 /*yield*/, Purchases.throwIfIOSPlatform()];
635
+ case 1:
636
+ _a.sent();
637
+ return [4 /*yield*/, Purchases.throwIfNotConfigured()];
638
+ case 2:
639
+ _a.sent();
640
+ RNPurchases.syncAmazonPurchase(productID, receiptID, amazonUserID, isoCurrencyCode, price);
641
+ return [2 /*return*/];
642
+ }
643
+ });
644
+ });
645
+ };
646
+ /**
647
+ * @deprecated, use syncAmazonPurchase instead.
648
+ *
649
+ * This method will send a purchase to the RevenueCat backend. This function should only be called if you are
650
+ * in Amazon observer mode or performing a client side migration of your current users to RevenueCat.
651
+ *
652
+ * The receipt IDs are cached if successfully posted so they are not posted more than once.
653
+ *
654
+ * @param {string} productID Product ID associated to the purchase.
655
+ * @param {string} receiptID ReceiptId that represents the Amazon purchase.
656
+ * @param {string} amazonUserID Amazon's userID. This parameter will be ignored when syncing a Google purchase.
657
+ * @param {(string|null|undefined)} isoCurrencyCode Product's currency code in ISO 4217 format.
658
+ * @param {(number|null|undefined)} price Product's price.
659
+ * @returns {Promise<void>} The promise will be rejected if configure has not been called yet or if there's an error
660
+ * syncing purchases.
661
+ */
631
662
  Purchases.syncObserverModeAmazonPurchase = function (productID, receiptID, amazonUserID, isoCurrencyCode, price) {
632
663
  return __awaiter(this, void 0, void 0, function () {
633
664
  return __generator(this, function (_a) {
@@ -645,18 +676,32 @@ var Purchases = /** @class */ (function () {
645
676
  });
646
677
  };
647
678
  /**
648
- * @deprecated, use enableAdServicesAttributionTokenCollection instead.
649
- * Enable automatic collection of Apple Search Ad attribution. Disabled by default
650
- * @param {boolean} enabled Enable or not automatic apple search ads attribution collection
651
- * @returns {Promise<void>} The promise will be rejected if configure has not been called yet.
679
+ * iOS only. Always returns an error on iOS < 15.
680
+ *
681
+ * Use this method only if you already have your own IAP implementation using StoreKit 2 and want to use
682
+ * RevenueCat's backend. If you are using StoreKit 1 for your implementation, you do not need this method.
683
+ *
684
+ * You only need to use this method with *new* purchases. Subscription updates are observed automatically.
685
+ *
686
+ * Important: This should only be used if you have set PurchasesAreCompletedBy to MY_APP during SDK configuration.
687
+ *
688
+ * @warning You need to finish the transaction yourself after calling this method.
689
+ *
690
+ * @param {string} productID Product ID that was just purchased
691
+ * @returns {Promise<PurchasesStoreTransaction>} If there was a transacton found and handled for the provided product ID.
652
692
  */
653
- Purchases.setAutomaticAppleSearchAdsAttributionCollection = function (enabled) {
693
+ Purchases.recordPurchase = function (productID) {
654
694
  return __awaiter(this, void 0, void 0, function () {
655
695
  return __generator(this, function (_a) {
656
- if (react_native_2.Platform.OS === "ios") {
657
- RNPurchases.setAutomaticAppleSearchAdsAttributionCollection(enabled);
696
+ switch (_a.label) {
697
+ case 0: return [4 /*yield*/, Purchases.throwIfAndroidPlatform()];
698
+ case 1:
699
+ _a.sent();
700
+ return [4 /*yield*/, Purchases.throwIfNotConfigured()];
701
+ case 2:
702
+ _a.sent();
703
+ return [2 /*return*/, RNPurchases.recordPurchaseForProductID(productID)];
658
704
  }
659
- return [2 /*return*/];
660
705
  });
661
706
  });
662
707
  };
@@ -1427,6 +1472,12 @@ var Purchases = /** @class */ (function () {
1427
1472
  });
1428
1473
  });
1429
1474
  };
1475
+ Purchases.isPurchasesAreCompletedByMyApp = function (obj) {
1476
+ return (typeof obj === "object" &&
1477
+ obj !== null &&
1478
+ obj.type ===
1479
+ purchases_typescript_internal_1.PURCHASES_ARE_COMPLETED_BY_TYPE.MY_APP);
1480
+ };
1430
1481
  Purchases.convertIntToRefundRequestStatus = function (refundRequestStatusInt) {
1431
1482
  switch (refundRequestStatusInt) {
1432
1483
  case 0:
@@ -1512,6 +1563,18 @@ var Purchases = /** @class */ (function () {
1512
1563
  * @enum {string}
1513
1564
  */
1514
1565
  Purchases.VERIFICATION_RESULT = purchases_typescript_internal_1.VERIFICATION_RESULT;
1566
+ /**
1567
+ * Enum of StoreKit version.
1568
+ * @readonly
1569
+ * @enum {string}
1570
+ */
1571
+ Purchases.STOREKIT_VERSION = purchases_typescript_internal_1.STOREKIT_VERSION;
1572
+ /**
1573
+ * Enum of PurchasesAreCompletedByType.
1574
+ * @readonly
1575
+ * @enum {string}
1576
+ */
1577
+ Purchases.PURCHASES_ARE_COMPLETED_BY_TYPE = purchases_typescript_internal_1.PURCHASES_ARE_COMPLETED_BY_TYPE;
1515
1578
  /**
1516
1579
  * @internal
1517
1580
  */
package/ios/RNPurchases.m CHANGED
@@ -39,19 +39,20 @@ RCT_EXPORT_MODULE();
39
39
 
40
40
  RCT_EXPORT_METHOD(setupPurchases:(NSString *)apiKey
41
41
  appUserID:(nullable NSString *)appUserID
42
- observerMode:(BOOL)observerMode
42
+ purchasesAreCompletedBy:(nullable NSString *)purchasesAreCompletedBy
43
43
  userDefaultsSuiteName:(nullable NSString *)userDefaultsSuiteName
44
- usesStoreKit2IfAvailable:(BOOL)usesStoreKit2IfAvailable
44
+ storeKitVersion:(nullable NSString *)storeKitVersion
45
45
  useAmazon:(BOOL)useAmazon
46
46
  shouldShowInAppMessagesAutomatically:(BOOL)shouldShowInAppMessagesAutomatically
47
- entitlementVerificationMode:(nullable NSString *)entitlementVerificationMode) {
47
+ entitlementVerificationMode:(nullable NSString *)entitlementVerificationMode
48
+ pendingTransactionsForPrepaidPlansEnabled:(BOOL)pendingTransactionsForPrepaidPlansEnabled) {
48
49
  RCPurchases *purchases = [RCPurchases configureWithAPIKey:apiKey
49
50
  appUserID:appUserID
50
- purchasesAreCompletedBy:(observerMode ? RCPurchasesAreCompletedByMyApp : RCPurchasesAreCompletedByRevenueCat)
51
+ purchasesAreCompletedBy:purchasesAreCompletedBy
51
52
  userDefaultsSuiteName:userDefaultsSuiteName
52
53
  platformFlavor:self.platformFlavor
53
54
  platformFlavorVersion:self.platformFlavorVersion
54
- usesStoreKit2IfAvailable:usesStoreKit2IfAvailable
55
+ storeKitVersion:storeKitVersion
55
56
  dangerousSettings:nil
56
57
  shouldShowInAppMessagesAutomatically:shouldShowInAppMessagesAutomatically
57
58
  verificationMode:entitlementVerificationMode];
@@ -65,14 +66,6 @@ RCT_EXPORT_METHOD(setAllowSharingStoreAccount:(BOOL)allowSharingStoreAccount) {
65
66
  #pragma GCC diagnostic pop
66
67
  }
67
68
 
68
- RCT_EXPORT_METHOD(setFinishTransactions:(BOOL)finishTransactions) {
69
- if (finishTransactions) {
70
- [RCCommonFunctionality setPurchasesAreCompletedBy:RCPurchasesAreCompletedByRevenueCat];
71
- } else {
72
- [RCCommonFunctionality setPurchasesAreCompletedBy:RCPurchasesAreCompletedByMyApp];
73
- }
74
- }
75
-
76
69
  RCT_REMAP_METHOD(getOfferings,
77
70
  getOfferingsWithResolve:(RCTPromiseResolveBlock)resolve
78
71
  reject:(RCTPromiseRejectBlock)reject) {
@@ -187,11 +180,6 @@ RCT_REMAP_METHOD(getCustomerInfo,
187
180
  [RCCommonFunctionality getCustomerInfoWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
188
181
  }
189
182
 
190
- RCT_EXPORT_METHOD(setAutomaticAppleSearchAdsAttributionCollection:(BOOL)automaticAppleSearchAdsAttributionCollection)
191
- {
192
- [RCCommonFunctionality setAutomaticAppleSearchAdsAttributionCollection:automaticAppleSearchAdsAttributionCollection];
193
- }
194
-
195
183
  RCT_EXPORT_METHOD(enableAdServicesAttributionTokenCollection)
196
184
  {
197
185
  #if !TARGET_OS_TV
@@ -445,6 +433,24 @@ RCT_EXPORT_METHOD(setLogHandler) {
445
433
  }];
446
434
  }
447
435
 
436
+ #pragma mark -
437
+ #pragma mark PurchasesAreCompletedBy Helper Functions
438
+ RCT_EXPORT_METHOD(recordPurchaseForProductID:(nonnull NSString *)productID
439
+ resolve:(RCTPromiseResolveBlock)resolve
440
+ reject:(RCTPromiseRejectBlock)reject) {
441
+ if (@available(iOS 15.0, *)) {
442
+ [RCCommonFunctionality recordPurchaseForProductID:productID
443
+ completion:[self getResponseCompletionBlockWithResolve:resolve
444
+ reject:reject]];
445
+ } 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}];
450
+ reject([NSString stringWithFormat:@"%ld", (long) error.code], [error localizedDescription], error);
451
+ }
452
+ }
453
+
448
454
  #pragma mark -
449
455
  #pragma mark Delegate Methods
450
456
  - (void)purchases:(RCPurchases *)purchases receivedUpdatedCustomerInfo:(RCCustomerInfo *)customerInfo {
@@ -501,7 +507,7 @@ readyForPromotedProduct:(RCStoreProduct *)product
501
507
  }
502
508
 
503
509
  - (NSString *)platformFlavorVersion {
504
- return @"7.28.1";
510
+ return @"8.0.0";
505
511
  }
506
512
 
507
513
  @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": "7.28.1",
4
+ "version": "8.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",
@@ -100,6 +100,6 @@
100
100
  ]
101
101
  },
102
102
  "dependencies": {
103
- "@revenuecat/purchases-typescript-internal": "11.1.1"
103
+ "@revenuecat/purchases-typescript-internal": "13.0.0"
104
104
  }
105
105
  }