react-native-purchases 4.5.3 → 5.0.0-beta.1

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.
@@ -8,15 +8,17 @@
8
8
 
9
9
  @import StoreKit;
10
10
 
11
+ typedef void (^PurchaseCompletedBlock)(RCStoreTransaction *, RCCustomerInfo *, NSError *, BOOL);
12
+ typedef void (^StartPurchaseBlock)(PurchaseCompletedBlock);
11
13
 
12
14
  @interface RNPurchases () <RCPurchasesDelegate>
13
15
 
14
- @property (nonatomic, retain) NSMutableArray<RCDeferredPromotionalPurchaseBlock> *defermentBlocks;
16
+ @property (nonatomic, retain) NSMutableArray<StartPurchaseBlock> *defermentBlocks;
15
17
 
16
18
  @end
17
19
 
18
20
 
19
- NSString *RNPurchasesPurchaserInfoUpdatedEvent = @"Purchases-PurchaserInfoUpdated";
21
+ NSString *RNPurchasesCustomerInfoUpdatedEvent = @"Purchases-CustomerInfoUpdated";
20
22
  NSString *RNPurchasesShouldPurchasePromoProductEvent = @"Purchases-ShouldPurchasePromoProduct";
21
23
 
22
24
 
@@ -27,7 +29,7 @@ NSString *RNPurchasesShouldPurchasePromoProductEvent = @"Purchases-ShouldPurchas
27
29
  }
28
30
 
29
31
  - (NSArray<NSString *> *)supportedEvents {
30
- return @[RNPurchasesPurchaserInfoUpdatedEvent, RNPurchasesShouldPurchasePromoProductEvent];
32
+ return @[RNPurchasesCustomerInfoUpdatedEvent, RNPurchasesShouldPurchasePromoProductEvent];
31
33
  }
32
34
 
33
35
  RCT_EXPORT_MODULE();
@@ -35,16 +37,17 @@ RCT_EXPORT_MODULE();
35
37
  RCT_EXPORT_METHOD(setupPurchases:(NSString *)apiKey
36
38
  appUserID:(nullable NSString *)appUserID
37
39
  observerMode:(BOOL)observerMode
38
- userDefaultsSuiteName:(nullable NSString *)userDefaultsSuiteName) {
39
- [RCPurchases configureWithAPIKey:apiKey
40
- appUserID:appUserID
41
- observerMode:observerMode
42
- userDefaultsSuiteName:userDefaultsSuiteName
43
- platformFlavor:self.platformFlavor
44
- platformFlavorVersion:self.platformFlavorVersion
45
- dangerousSettings:nil];
46
- RCPurchases.sharedPurchases.delegate = self;
47
- [RCCommonFunctionality configure];
40
+ userDefaultsSuiteName:(nullable NSString *)userDefaultsSuiteName
41
+ usesStoreKit2IfAvailable:(BOOL)usesStoreKit2IfAvailable) {
42
+ RCPurchases *purchases = [RCPurchases configureWithAPIKey:apiKey
43
+ appUserID:appUserID
44
+ observerMode:observerMode
45
+ userDefaultsSuiteName:userDefaultsSuiteName
46
+ platformFlavor:self.platformFlavor
47
+ platformFlavorVersion:self.platformFlavorVersion
48
+ usesStoreKit2IfAvailable:usesStoreKit2IfAvailable
49
+ dangerousSettings:nil];
50
+ purchases.delegate = self;
48
51
  }
49
52
 
50
53
  RCT_EXPORT_METHOD(setAllowSharingStoreAccount:(BOOL)allowSharingStoreAccount) {
@@ -58,15 +61,6 @@ RCT_EXPORT_METHOD(setFinishTransactions:(BOOL)finishTransactions) {
58
61
  [RCCommonFunctionality setFinishTransactions:finishTransactions];
59
62
  }
60
63
 
61
- RCT_EXPORT_METHOD(addAttributionData:(NSDictionary *)data
62
- forNetwork:(NSInteger)network
63
- forNetworkUserId:(nullable NSString *)networkUserId) {
64
- #pragma GCC diagnostic push
65
- #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
66
- [RCCommonFunctionality addAttributionData:data network:network networkUserId:networkUserId];
67
- #pragma GCC diagnostic pop
68
- }
69
-
70
64
  RCT_REMAP_METHOD(getOfferings,
71
65
  getOfferingsWithResolve:(RCTPromiseResolveBlock)resolve
72
66
  reject:(RCTPromiseRejectBlock)reject) {
@@ -112,8 +106,8 @@ RCT_REMAP_METHOD(purchasePackage,
112
106
  RCT_REMAP_METHOD(restoreTransactions,
113
107
  restoreTransactionsWithResolve:(RCTPromiseResolveBlock)resolve
114
108
  reject:(RCTPromiseRejectBlock)reject) {
115
- [RCCommonFunctionality restoreTransactionsWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve
116
- reject:reject]];
109
+ [RCCommonFunctionality restorePurchasesWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve
110
+ reject:reject]];
117
111
  }
118
112
 
119
113
  RCT_EXPORT_METHOD(syncPurchases) {
@@ -126,13 +120,6 @@ RCT_REMAP_METHOD(getAppUserID,
126
120
  resolve([RCCommonFunctionality appUserID]);
127
121
  }
128
122
 
129
- RCT_EXPORT_METHOD(createAlias:(nullable NSString *)newAppUserID
130
- resolve:(RCTPromiseResolveBlock)resolve
131
- reject:(RCTPromiseRejectBlock)reject) {
132
- [RCCommonFunctionality createAlias:newAppUserID
133
- completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
134
- }
135
-
136
123
  RCT_EXPORT_METHOD(logIn:(nonnull NSString *)appUserID
137
124
  resolve:(RCTPromiseResolveBlock)resolve
138
125
  reject:(RCTPromiseRejectBlock)reject) {
@@ -146,25 +133,6 @@ RCT_REMAP_METHOD(logOut,
146
133
  [RCCommonFunctionality logOutWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
147
134
  }
148
135
 
149
- RCT_EXPORT_METHOD(identify:(nullable NSString *)appUserID
150
- resolve:(RCTPromiseResolveBlock)resolve
151
- reject:(RCTPromiseRejectBlock)reject) {
152
- #pragma GCC diagnostic push
153
- #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
154
- [RCCommonFunctionality identify:appUserID
155
- completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
156
- #pragma GCC diagnostic pop
157
- }
158
-
159
- RCT_REMAP_METHOD(reset,
160
- resetWithResolve:(RCTPromiseResolveBlock)resolve
161
- reject:(RCTPromiseRejectBlock)reject) {
162
- #pragma GCC diagnostic push
163
- #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
164
- [RCCommonFunctionality resetWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
165
- #pragma GCC diagnostic pop
166
- }
167
-
168
136
  RCT_REMAP_METHOD(setDebugLogsEnabled,
169
137
  debugLogsEnabled:(BOOL)enabled) {
170
138
  [RCCommonFunctionality setDebugLogsEnabled:enabled];
@@ -175,10 +143,10 @@ RCT_EXPORT_METHOD(setSimulatesAskToBuyInSandbox:(BOOL)simulatesAskToBuyInSandbox
175
143
  [RCCommonFunctionality setSimulatesAskToBuyInSandbox:simulatesAskToBuyInSandbox];
176
144
  }
177
145
 
178
- RCT_REMAP_METHOD(getPurchaserInfo,
179
- purchaserInfoWithResolve:(RCTPromiseResolveBlock)resolve
146
+ RCT_REMAP_METHOD(getCustomerInfo,
147
+ customerInfoWithResolve:(RCTPromiseResolveBlock)resolve
180
148
  reject:(RCTPromiseRejectBlock)reject) {
181
- [RCCommonFunctionality getPurchaserInfoWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
149
+ [RCCommonFunctionality getCustomerInfoWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
182
150
  }
183
151
 
184
152
  RCT_EXPORT_METHOD(setAutomaticAppleSearchAdsAttributionCollection:(BOOL)automaticAppleSearchAdsAttributionCollection)
@@ -195,7 +163,7 @@ RCT_REMAP_METHOD(isAnonymous,
195
163
  RCT_EXPORT_METHOD(makeDeferredPurchase:(nonnull NSNumber *)callbackID
196
164
  resolve:(RCTPromiseResolveBlock)resolve
197
165
  reject:(RCTPromiseRejectBlock)reject) {
198
- RCDeferredPromotionalPurchaseBlock defermentBlock = [self.defermentBlocks objectAtIndex:[callbackID integerValue]];
166
+ StartPurchaseBlock defermentBlock = [self.defermentBlocks objectAtIndex:[callbackID integerValue]];
199
167
  [RCCommonFunctionality makeDeferredPurchase:defermentBlock
200
168
  completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
201
169
  }
@@ -209,19 +177,18 @@ RCT_EXPORT_METHOD(checkTrialOrIntroductoryPriceEligibility:(NSArray *)products
209
177
  }];
210
178
  }
211
179
 
212
- RCT_REMAP_METHOD(getPaymentDiscount,
213
- getPaymentDiscountForProductIdentifier:(NSString *)productIdentifier
214
- discountIdentifier:(nullable NSString *)discountIdentifier
215
- resolve:(RCTPromiseResolveBlock)resolve
216
- reject:(RCTPromiseRejectBlock)reject) {
217
- [RCCommonFunctionality paymentDiscountForProductIdentifier:productIdentifier
218
- discount:discountIdentifier
219
- completionBlock:[self getResponseCompletionBlockWithResolve:resolve
220
- reject:reject]];
180
+ RCT_EXPORT_METHOD(invalidateCustomerInfoCache) {
181
+ [RCCommonFunctionality invalidateCustomerInfoCache];
221
182
  }
222
183
 
223
- RCT_EXPORT_METHOD(invalidatePurchaserInfoCache) {
224
- [RCCommonFunctionality invalidatePurchaserInfoCache];
184
+ RCT_REMAP_METHOD(getPromotionalOffer,
185
+ getPromotionalOfferForProductIdentifier:(NSString *)productIdentifier
186
+ discount:(NSString *)discount
187
+ resolve:(RCTPromiseResolveBlock)resolve
188
+ reject:(RCTPromiseRejectBlock)reject) {
189
+ [RCCommonFunctionality promotionalOfferForProductIdentifier:productIdentifier
190
+ discount:discount
191
+ completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
225
192
  }
226
193
 
227
194
  RCT_EXPORT_METHOD(presentCodeRedemptionSheet) {
@@ -329,17 +296,17 @@ RCT_REMAP_METHOD(isConfigured,
329
296
 
330
297
  #pragma mark -
331
298
  #pragma mark Delegate Methods
332
- - (void)purchases:(RCPurchases *)purchases didReceiveUpdatedPurchaserInfo:(RCPurchaserInfo *)purchaserInfo {
333
- [self sendEventWithName:RNPurchasesPurchaserInfoUpdatedEvent body:purchaserInfo.dictionary];
299
+ - (void)purchases:(RCPurchases *)purchases didReceiveUpdatedCustomerInfo:(RCCustomerInfo *)customerInfo {
300
+ [self sendEventWithName:RNPurchasesCustomerInfoUpdatedEvent body:customerInfo.dictionary];
334
301
  }
335
302
 
336
- - (void) purchases:(RCPurchases *)purchases
337
- shouldPurchasePromoProduct:(SKProduct *)product
338
- defermentBlock:(RCDeferredPromotionalPurchaseBlock)makeDeferredPurchase {
303
+ - (void)purchases:(RCPurchases *)purchases
304
+ readyForPromotedProduct:(RCStoreProduct *)product
305
+ purchase:(void (^)(void (^ _Nonnull)(RCStoreTransaction * _Nullable, RCCustomerInfo * _Nullable, NSError * _Nullable, BOOL)))startPurchase {
339
306
  if (!self.defermentBlocks) {
340
307
  self.defermentBlocks = [NSMutableArray array];
341
308
  }
342
- [self.defermentBlocks addObject:makeDeferredPurchase];
309
+ [self.defermentBlocks addObject:startPurchase];
343
310
  NSInteger position = [self.defermentBlocks count] - 1;
344
311
  [self sendEventWithName:RNPurchasesShouldPurchasePromoProductEvent body:@{@"callbackID": @(position)}];
345
312
  }
@@ -369,7 +336,7 @@ shouldPurchasePromoProduct:(SKProduct *)product
369
336
  }
370
337
 
371
338
  - (NSString *)platformFlavorVersion {
372
- return @"4.5.2";
339
+ return @"4.6.1";
373
340
  }
374
341
 
375
342
  @end
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "react-native-purchases",
3
3
  "title": "React Native Purchases",
4
- "version": "4.5.3",
4
+ "version": "5.0.0-beta.1",
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",
8
8
  "source": "src/index",
9
9
  "files": [
10
- "scripts/build.js",
11
10
  "dist",
12
11
  "android",
13
12
  "!android/gradlew*",
@@ -30,12 +29,11 @@
30
29
  "scripts": {
31
30
  "build": "tsc",
32
31
  "build-watch": "tsc --watch",
33
- "preinstall": "node scripts/build.js",
34
32
  "test": "jest",
35
33
  "tslint": "tslint -c tslint.json 'src/*.ts'",
36
34
  "prepublish": "tsc",
37
- "example": "(yarn --cwd examples/purchaseTester) && (yarn --cwd examples/purchaseTesterTypescript)",
38
- "pods": "(cd examples/purchaseTester && npx pod-install --quiet) && (cd examples/purchaseTesterTypescript && npx pod-install --quiet)",
35
+ "example": "yarn --cwd examples/MagicWeather && yarn --cwd examples/purchaseTesterTypescript",
36
+ "pods": "(cd examples/MagicWeather && npx pod-install --quiet) && (cd examples/purchaseTesterTypescript && npx pod-install --quiet)",
39
37
  "bootstrap": "yarn example && yarn && yarn pods"
40
38
  },
41
39
  "repository": {
@@ -77,7 +75,7 @@
77
75
  "jest": {
78
76
  "preset": "react-native",
79
77
  "modulePathIgnorePatterns": [
80
- "<rootDir>/examples/purchaseTester/node_modules",
78
+ "<rootDir>/examples/purchaseTesterTypescript/node_modules",
81
79
  "<rootDir>/lib/"
82
80
  ],
83
81
  "moduleFileExtensions": [
File without changes
@@ -1,6 +1,6 @@
1
1
  const {NativeModules} = require("react-native");
2
2
 
3
- global.purchaserInfoStub = {
3
+ global.customerInfoStub = {
4
4
  activeSubscriptions: ["annual_freetrial"],
5
5
  allExpirationDates: {
6
6
  onetime_purchase: null,
@@ -663,7 +663,7 @@ global.discountStub = {
663
663
  periodNumberOfUnits: 1,
664
664
  };
665
665
 
666
- global.paymentDiscountStub = {
666
+ global.promotionalOfferStub = {
667
667
  identifier: "promo_cat",
668
668
  keyIdentifier: "keyID",
669
669
  nonce: "nonce",
@@ -680,13 +680,10 @@ NativeModules.RNPurchases = {
680
680
  makePurchase: jest.fn(),
681
681
  restoreTransactions: jest.fn(),
682
682
  getAppUserID: jest.fn(),
683
- createAlias: jest.fn(),
684
- identify: jest.fn(),
685
683
  setDebugLogsEnabled: jest.fn(),
686
- getPurchaserInfo: jest.fn(),
684
+ getCustomerInfo: jest.fn(),
687
685
  logIn: jest.fn(),
688
686
  logOut: jest.fn(),
689
- reset: jest.fn(),
690
687
  syncPurchases: jest.fn(),
691
688
  setFinishTransactions: jest.fn(),
692
689
  purchaseProduct: jest.fn(),
@@ -696,8 +693,8 @@ NativeModules.RNPurchases = {
696
693
  checkTrialOrIntroductoryPriceEligibility: jest.fn(),
697
694
  purchaseDiscountedPackage: jest.fn(),
698
695
  purchaseDiscountedProduct: jest.fn(),
699
- getPaymentDiscount: jest.fn(),
700
- invalidatePurchaserInfoCache: jest.fn(),
696
+ getPromotionalOffer: jest.fn(),
697
+ invalidateCustomerInfoCache: jest.fn(),
701
698
  setAttributes: jest.fn(),
702
699
  setEmail: jest.fn(),
703
700
  setPhoneNumber: jest.fn(),
@@ -710,4 +707,3 @@ NativeModules.RNPurchases = {
710
707
  jest.mock(
711
708
  'react-native/Libraries/EventEmitter/NativeEventEmitter',
712
709
  );
713
-
@@ -1,39 +0,0 @@
1
- #!/bin/sh
2
-
3
- cd ios/
4
-
5
- VERSION=$1
6
- CURRENT_VERSION=$(cat .common_version)
7
-
8
- if [ "$VERSION" == "$CURRENT_VERSION" ]; then
9
- echo "The newest version is already installed. Exiting."
10
- exit 0
11
- fi
12
-
13
- pwd
14
-
15
- URL=https://github.com/RevenueCat/purchases-hybrid-common/releases/download/$VERSION/PurchasesHybridCommon.framework.zip
16
-
17
- echo "Downloading Purchases common hybrid SDKs classes $VERSION from $URL, this may take a minute."
18
-
19
- if ! which curl > /dev/null; then echo "curl command not found. Please install curl"; exit 1; fi;
20
- if ! which unzip > /dev/null; then echo "unzip command not found. Please install unzip"; exit 1; fi;
21
-
22
- if [ -d ./PurchasesHybridCommon.framework ]; then
23
- echo "Old classes found. Removing them and installing version $VERSION"
24
- rm -rf ./PurchasesHybridCommon.framework
25
- fi
26
-
27
- curl -sSL $URL > tempCommon.zip
28
- # In some cases the temp folder can not be created by unzip, https://github.com/RevenueCat/react-native-purchases/issues/26
29
- mkdir -p tempCommon
30
- unzip -o tempCommon.zip -d tempCommon
31
- mv tempCommon/Carthage/Build/iOS/PurchasesHybridCommon.framework ./PurchasesHybridCommon.framework
32
- rm -r tempCommon
33
- rm tempCommon.zip
34
-
35
- if ! [ -d ./PurchasesHybridCommon.framework ]; then
36
- echo "Common files not found. Please reinstall react-native-purchases"; exit 1;
37
- fi;
38
-
39
- echo "$VERSION" > .common_version
@@ -1,39 +0,0 @@
1
- #!/bin/sh
2
-
3
- cd ios/
4
-
5
- VERSION=$1
6
- CURRENT_VERSION=$(cat .framework_version)
7
-
8
- if [ "$VERSION" == "$CURRENT_VERSION" ]; then
9
- echo "The newest version is already installed. Exiting."
10
- exit 0
11
- fi
12
-
13
- pwd
14
-
15
- URL=https://github.com/RevenueCat/purchases-ios/releases/download/$VERSION/Purchases.framework.zip
16
-
17
- echo "Downloading Purchases iOS $VERSION from $URL, this may take a minute."
18
-
19
- if ! which curl > /dev/null; then echo "curl command not found. Please install curl"; exit 1; fi;
20
- if ! which unzip > /dev/null; then echo "unzip command not found. Please install unzip"; exit 1; fi;
21
-
22
- if [ -d ./Purchases.framework ]; then
23
- echo "Old Purchases.framework found. Removing it and installing a $VERSION"
24
- rm -rf ./Purchases.framework
25
- fi
26
-
27
- curl -sSL $URL > temp.zip
28
- # In some cases the temp folder can not be created by unzip, https://github.com/RevenueCat/react-native-purchases/issues/26
29
- mkdir -p temp
30
- unzip -o temp.zip -d temp
31
- mv temp/Carthage/Build/iOS/Purchases.framework ./Purchases.framework
32
- rm -r temp
33
- rm temp.zip
34
-
35
- if ! [ -d ./Purchases.framework ]; then
36
- echo "Purchases.framework not found. Please reinstall react-native-purchases"; exit 1;
37
- fi;
38
-
39
- echo "$VERSION" > .framework_version