react-native-purchases 4.6.1 → 5.0.0-beta.3

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.
@@ -0,0 +1,343 @@
1
+
2
+ //
3
+ // Created by RevenueCat.
4
+ // Copyright © 2019 RevenueCat. All rights reserved.
5
+ //
6
+
7
+ #import "RNPurchases.h"
8
+
9
+ @import StoreKit;
10
+
11
+ typedef void (^PurchaseCompletedBlock)(RCStoreTransaction *, RCCustomerInfo *, NSError *, BOOL);
12
+ typedef void (^StartPurchaseBlock)(PurchaseCompletedBlock);
13
+
14
+ @interface RNPurchases () <RCPurchasesDelegate>
15
+
16
+ @property (nonatomic, retain) NSMutableArray<StartPurchaseBlock> *defermentBlocks;
17
+
18
+ @end
19
+
20
+
21
+ NSString *RNPurchasesCustomerInfoUpdatedEvent = @"Purchases-CustomerInfoUpdated";
22
+ NSString *RNPurchasesShouldPurchasePromoProductEvent = @"Purchases-ShouldPurchasePromoProduct";
23
+
24
+
25
+ @implementation RNPurchases
26
+
27
+ - (dispatch_queue_t)methodQueue {
28
+ return dispatch_get_main_queue();
29
+ }
30
+
31
+ - (NSArray<NSString *> *)supportedEvents {
32
+ return @[RNPurchasesCustomerInfoUpdatedEvent, RNPurchasesShouldPurchasePromoProductEvent];
33
+ }
34
+
35
+ RCT_EXPORT_MODULE();
36
+
37
+ RCT_EXPORT_METHOD(setupPurchases:(NSString *)apiKey
38
+ appUserID:(nullable NSString *)appUserID
39
+ observerMode:(BOOL)observerMode
40
+ userDefaultsSuiteName:(nullable NSString *)userDefaultsSuiteName
41
+ usesStoreKit2IfAvailable:(BOOL)usesStoreKit2IfAvailable
42
+ useAmazon:(BOOL)useAmazon) {
43
+ RCPurchases *purchases = [RCPurchases configureWithAPIKey:apiKey
44
+ appUserID:appUserID
45
+ observerMode:observerMode
46
+ userDefaultsSuiteName:userDefaultsSuiteName
47
+ platformFlavor:self.platformFlavor
48
+ platformFlavorVersion:self.platformFlavorVersion
49
+ usesStoreKit2IfAvailable:usesStoreKit2IfAvailable
50
+ dangerousSettings:nil];
51
+ purchases.delegate = self;
52
+ }
53
+
54
+ RCT_EXPORT_METHOD(setAllowSharingStoreAccount:(BOOL)allowSharingStoreAccount) {
55
+ #pragma GCC diagnostic push
56
+ #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
57
+ [RCCommonFunctionality setAllowSharingStoreAccount:allowSharingStoreAccount];
58
+ #pragma GCC diagnostic pop
59
+ }
60
+
61
+ RCT_EXPORT_METHOD(setFinishTransactions:(BOOL)finishTransactions) {
62
+ [RCCommonFunctionality setFinishTransactions:finishTransactions];
63
+ }
64
+
65
+ RCT_REMAP_METHOD(getOfferings,
66
+ getOfferingsWithResolve:(RCTPromiseResolveBlock)resolve
67
+ reject:(RCTPromiseRejectBlock)reject) {
68
+ [RCCommonFunctionality getOfferingsWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve
69
+ reject:reject]];
70
+ }
71
+
72
+ RCT_EXPORT_METHOD(getProductInfo:(NSArray *)products
73
+ type:(NSString *)type
74
+ resolve:(RCTPromiseResolveBlock)resolve
75
+ reject:(RCTPromiseRejectBlock)reject) {
76
+ [RCCommonFunctionality getProductInfo:products completionBlock:^(NSArray<NSDictionary *> *productObjects) {
77
+ resolve(productObjects);
78
+ }];
79
+ }
80
+
81
+ RCT_REMAP_METHOD(purchaseProduct,
82
+ purchaseProduct:(NSString *)productIdentifier
83
+ upgradeInfo:(NSDictionary *)upgradeInfo
84
+ type:(NSString *)type
85
+ signedDiscountTimestamp:(NSString *)signedDiscountTimestamp
86
+ resolve:(RCTPromiseResolveBlock)resolve
87
+ reject:(RCTPromiseRejectBlock)reject) {
88
+ [RCCommonFunctionality purchaseProduct:productIdentifier
89
+ signedDiscountTimestamp:signedDiscountTimestamp
90
+ completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
91
+ }
92
+
93
+
94
+ RCT_REMAP_METHOD(purchasePackage,
95
+ purchasePackage:(NSString *)packageIdentifier
96
+ offeringIdentifier:(NSString *)offeringIdentifier
97
+ upgradeInfo:(NSDictionary *)upgradeInfo
98
+ signedDiscountTimestamp:(NSString *)signedDiscountTimestamp
99
+ resolve:(RCTPromiseResolveBlock)resolve
100
+ reject:(RCTPromiseRejectBlock)reject) {
101
+ [RCCommonFunctionality purchasePackage:packageIdentifier
102
+ offering:offeringIdentifier
103
+ signedDiscountTimestamp:signedDiscountTimestamp
104
+ completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
105
+ }
106
+
107
+ RCT_REMAP_METHOD(restorePurchases,
108
+ restorePurchasesWithResolve:(RCTPromiseResolveBlock)resolve
109
+ reject:(RCTPromiseRejectBlock)reject) {
110
+ [RCCommonFunctionality restorePurchasesWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve
111
+ reject:reject]];
112
+ }
113
+
114
+ RCT_EXPORT_METHOD(syncPurchases) {
115
+ [RCCommonFunctionality syncPurchasesWithCompletionBlock:nil];
116
+ }
117
+
118
+ RCT_REMAP_METHOD(getAppUserID,
119
+ getAppUserIDWithResolve:(RCTPromiseResolveBlock)resolve
120
+ reject:(RCTPromiseRejectBlock)reject) {
121
+ resolve([RCCommonFunctionality appUserID]);
122
+ }
123
+
124
+ RCT_EXPORT_METHOD(logIn:(nonnull NSString *)appUserID
125
+ resolve:(RCTPromiseResolveBlock)resolve
126
+ reject:(RCTPromiseRejectBlock)reject) {
127
+ [RCCommonFunctionality logInWithAppUserID:appUserID
128
+ completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
129
+ }
130
+
131
+ RCT_REMAP_METHOD(logOut,
132
+ logOutWithResolve:(RCTPromiseResolveBlock)resolve
133
+ reject:(RCTPromiseRejectBlock)reject) {
134
+ [RCCommonFunctionality logOutWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
135
+ }
136
+
137
+ RCT_REMAP_METHOD(setDebugLogsEnabled,
138
+ debugLogsEnabled:(BOOL)enabled) {
139
+ [RCCommonFunctionality setDebugLogsEnabled:enabled];
140
+ }
141
+
142
+ RCT_EXPORT_METHOD(setSimulatesAskToBuyInSandbox:(BOOL)simulatesAskToBuyInSandbox)
143
+ {
144
+ [RCCommonFunctionality setSimulatesAskToBuyInSandbox:simulatesAskToBuyInSandbox];
145
+ }
146
+
147
+ RCT_REMAP_METHOD(getCustomerInfo,
148
+ customerInfoWithResolve:(RCTPromiseResolveBlock)resolve
149
+ reject:(RCTPromiseRejectBlock)reject) {
150
+ [RCCommonFunctionality getCustomerInfoWithCompletionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
151
+ }
152
+
153
+ RCT_EXPORT_METHOD(setAutomaticAppleSearchAdsAttributionCollection:(BOOL)automaticAppleSearchAdsAttributionCollection)
154
+ {
155
+ [RCCommonFunctionality setAutomaticAppleSearchAdsAttributionCollection:automaticAppleSearchAdsAttributionCollection];
156
+ }
157
+
158
+ RCT_REMAP_METHOD(isAnonymous,
159
+ isAnonymousWithResolve:(RCTPromiseResolveBlock)resolve
160
+ reject:(RCTPromiseRejectBlock)reject) {
161
+ resolve(@([RCCommonFunctionality isAnonymous]));
162
+ }
163
+
164
+ RCT_EXPORT_METHOD(makeDeferredPurchase:(nonnull NSNumber *)callbackID
165
+ resolve:(RCTPromiseResolveBlock)resolve
166
+ reject:(RCTPromiseRejectBlock)reject) {
167
+ StartPurchaseBlock defermentBlock = [self.defermentBlocks objectAtIndex:[callbackID integerValue]];
168
+ [RCCommonFunctionality makeDeferredPurchase:defermentBlock
169
+ completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
170
+ }
171
+
172
+ RCT_EXPORT_METHOD(checkTrialOrIntroductoryPriceEligibility:(NSArray *)products
173
+ resolve:(RCTPromiseResolveBlock)resolve
174
+ reject:(RCTPromiseRejectBlock)reject) {
175
+ [RCCommonFunctionality checkTrialOrIntroductoryPriceEligibility:products
176
+ completionBlock:^(NSDictionary<NSString *,RCIntroEligibility *> * _Nonnull responseDictionary) {
177
+ resolve([NSDictionary dictionaryWithDictionary:responseDictionary]);
178
+ }];
179
+ }
180
+
181
+ RCT_EXPORT_METHOD(invalidateCustomerInfoCache) {
182
+ [RCCommonFunctionality invalidateCustomerInfoCache];
183
+ }
184
+
185
+ RCT_REMAP_METHOD(getPromotionalOffer,
186
+ getPromotionalOfferForProductIdentifier:(NSString *)productIdentifier
187
+ discount:(NSString *)discount
188
+ resolve:(RCTPromiseResolveBlock)resolve
189
+ reject:(RCTPromiseRejectBlock)reject) {
190
+ [RCCommonFunctionality promotionalOfferForProductIdentifier:productIdentifier
191
+ discount:discount
192
+ completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
193
+ }
194
+
195
+ RCT_EXPORT_METHOD(presentCodeRedemptionSheet) {
196
+ if (@available(iOS 14.0, *)) {
197
+ [RCCommonFunctionality presentCodeRedemptionSheet];
198
+ } else {
199
+ NSLog(@"[Purchases] Warning: tried to present codeRedemptionSheet, but it's only available on iOS 14.0 or greater.");
200
+ }
201
+ }
202
+
203
+ #pragma mark - Subscriber Attributes
204
+
205
+ RCT_EXPORT_METHOD(setProxyURLString:(nullable NSString *)proxyURLString) {
206
+ [RCCommonFunctionality setProxyURLString:proxyURLString];
207
+ }
208
+
209
+ RCT_EXPORT_METHOD(setAttributes:(NSDictionary *)attributes) {
210
+ [RCCommonFunctionality setAttributes:attributes];
211
+ }
212
+
213
+ RCT_EXPORT_METHOD(setEmail:(NSString *)email) {
214
+ [RCCommonFunctionality setEmail:email];
215
+ }
216
+
217
+ RCT_EXPORT_METHOD(setPhoneNumber:(NSString *)phoneNumber) {
218
+ [RCCommonFunctionality setPhoneNumber:phoneNumber];
219
+ }
220
+
221
+ RCT_EXPORT_METHOD(setDisplayName:(NSString *)displayName) {
222
+ [RCCommonFunctionality setDisplayName:displayName];
223
+ }
224
+
225
+ RCT_EXPORT_METHOD(setPushToken:(NSString *)pushToken) {
226
+ [RCCommonFunctionality setPushToken:pushToken];
227
+ }
228
+
229
+ # pragma mark Attribution IDs
230
+
231
+ RCT_EXPORT_METHOD(collectDeviceIdentifiers) {
232
+ [RCCommonFunctionality collectDeviceIdentifiers];
233
+ }
234
+
235
+ RCT_EXPORT_METHOD(setAdjustID:(NSString *)adjustID) {
236
+ [RCCommonFunctionality setAdjustID:adjustID];
237
+ }
238
+
239
+ RCT_EXPORT_METHOD(setAppsflyerID:(NSString *)appsflyerID) {
240
+ [RCCommonFunctionality setAppsflyerID:appsflyerID];
241
+ }
242
+
243
+ RCT_EXPORT_METHOD(setFBAnonymousID:(NSString *)fbAnonymousID) {
244
+ [RCCommonFunctionality setFBAnonymousID:fbAnonymousID];
245
+ }
246
+
247
+ RCT_EXPORT_METHOD(setMparticleID:(NSString *)mparticleID) {
248
+ [RCCommonFunctionality setMparticleID:mparticleID];
249
+ }
250
+
251
+ RCT_EXPORT_METHOD(setOnesignalID:(NSString *)onesignalID) {
252
+ [RCCommonFunctionality setOnesignalID:onesignalID];
253
+ }
254
+
255
+ RCT_EXPORT_METHOD(setAirshipChannelID:(NSString *)airshipChannelID) {
256
+ [RCCommonFunctionality setAirshipChannelID:airshipChannelID];
257
+ }
258
+
259
+ # pragma mark Campaign parameters
260
+
261
+ RCT_EXPORT_METHOD(setMediaSource:(NSString *)mediaSource) {
262
+ [RCCommonFunctionality setMediaSource:mediaSource];
263
+ }
264
+
265
+ RCT_EXPORT_METHOD(setCampaign:(NSString *)campaign) {
266
+ [RCCommonFunctionality setCampaign:campaign];
267
+ }
268
+
269
+ RCT_EXPORT_METHOD(setAdGroup:(NSString *)adGroup) {
270
+ [RCCommonFunctionality setAdGroup:adGroup];
271
+ }
272
+
273
+ RCT_EXPORT_METHOD(setAd:(NSString *)ad) {
274
+ [RCCommonFunctionality setAd:ad];
275
+ }
276
+
277
+ RCT_EXPORT_METHOD(setKeyword:(NSString *)keyword) {
278
+ [RCCommonFunctionality setKeyword:keyword];
279
+ }
280
+
281
+ RCT_EXPORT_METHOD(setCreative:(NSString *)creative) {
282
+ [RCCommonFunctionality setCreative:creative];
283
+ }
284
+
285
+ RCT_REMAP_METHOD(canMakePayments,
286
+ canMakePaymentsWithFeatures:(NSArray<NSNumber *> *)features
287
+ resolve:(RCTPromiseResolveBlock)resolve
288
+ reject:(RCTPromiseRejectBlock)reject) {
289
+ resolve(@([RCCommonFunctionality canMakePaymentsWithFeatures:features]));
290
+ }
291
+
292
+ RCT_REMAP_METHOD(isConfigured,
293
+ isConfiguredWithResolve:(RCTPromiseResolveBlock)resolve
294
+ reject:(RCTPromiseRejectBlock)reject) {
295
+ resolve(@(RCPurchases.isConfigured));
296
+ }
297
+
298
+ #pragma mark -
299
+ #pragma mark Delegate Methods
300
+ - (void)purchases:(RCPurchases *)purchases didReceiveUpdatedCustomerInfo:(RCCustomerInfo *)customerInfo {
301
+ [self sendEventWithName:RNPurchasesCustomerInfoUpdatedEvent body:customerInfo.dictionary];
302
+ }
303
+
304
+ - (void)purchases:(RCPurchases *)purchases
305
+ readyForPromotedProduct:(RCStoreProduct *)product
306
+ purchase:(void (^)(void (^ _Nonnull)(RCStoreTransaction * _Nullable, RCCustomerInfo * _Nullable, NSError * _Nullable, BOOL)))startPurchase {
307
+ if (!self.defermentBlocks) {
308
+ self.defermentBlocks = [NSMutableArray array];
309
+ }
310
+ [self.defermentBlocks addObject:startPurchase];
311
+ NSInteger position = [self.defermentBlocks count] - 1;
312
+ [self sendEventWithName:RNPurchasesShouldPurchasePromoProductEvent body:@{@"callbackID": @(position)}];
313
+ }
314
+
315
+ #pragma mark -
316
+ #pragma mark Helper Methods
317
+
318
+ - (void)rejectPromiseWithBlock:(RCTPromiseRejectBlock)reject error:(NSError *)error {
319
+ reject([NSString stringWithFormat: @"%ld", (long)error.code], error.localizedDescription, error);
320
+ }
321
+
322
+ - (void (^)(NSDictionary *, RCErrorContainer *))getResponseCompletionBlockWithResolve:(RCTPromiseResolveBlock)resolve
323
+ reject:(RCTPromiseRejectBlock)reject {
324
+ return ^(NSDictionary *_Nullable responseDictionary, RCErrorContainer *_Nullable error) {
325
+ if (error) {
326
+ reject([NSString stringWithFormat:@"%ld", (long) error.code], error.message, error.error);
327
+ } else if (responseDictionary) {
328
+ resolve([NSDictionary dictionaryWithDictionary:responseDictionary]);
329
+ } else {
330
+ resolve(nil);
331
+ }
332
+ };
333
+ }
334
+
335
+ - (NSString *)platformFlavor {
336
+ return @"react-native";
337
+ }
338
+
339
+ - (NSString *)platformFlavorVersion {
340
+ return @"5.0.0-beta.2";
341
+ }
342
+
343
+ @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.6.1",
4
+ "version": "5.0.0-beta.3",
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": {
@@ -72,12 +70,13 @@
72
70
  "ts-jest": "^24.1.0",
73
71
  "tslint": "^5.20.0",
74
72
  "tslint-config-prettier": "^1.18.0",
73
+ "typedoc": "^0.20.37",
75
74
  "typescript": "^3.8.3"
76
75
  },
77
76
  "jest": {
78
77
  "preset": "react-native",
79
78
  "modulePathIgnorePatterns": [
80
- "<rootDir>/examples/purchaseTester/node_modules",
79
+ "<rootDir>/examples/purchaseTesterTypescript/node_modules",
81
80
  "<rootDir>/lib/"
82
81
  ],
83
82
  "moduleFileExtensions": [
File without changes
@@ -0,0 +1,9 @@
1
+ <!-- This file is used to redirect visitors to the latest version of the docs -->
2
+ <!DOCTYPE html>
3
+ <html>
4
+ <head>
5
+ <meta http-equiv="refresh" content="0; url=https://revenuecat.github.io/react-native-purchases-docs/5.0.0-beta.3/" />
6
+ </head>
7
+ <body>
8
+ </body>
9
+ </html>
@@ -0,0 +1,9 @@
1
+ <!-- This file is used to redirect visitors to the latest version of the docs -->
2
+ <!DOCTYPE html>
3
+ <html>
4
+ <head>
5
+ <meta http-equiv="refresh" content="0; url=https://revenuecat.github.io/react-native-purchases-docs/5.0.0-beta.2/" />
6
+ </head>
7
+ <body>
8
+ </body>
9
+ </html>