react-native-purchases 5.0.0-beta.4 → 5.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.
@@ -1,352 +0,0 @@
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_EXPORT_METHOD(enableAdServicesAttributionTokenCollection)
159
- {
160
- if (@available(iOS 14.3, macOS 11.1, macCatalyst 14.3, *)) {
161
- [RCCommonFunctionality enableAdServicesAttributionTokenCollection];
162
- } else {
163
- NSLog(@"[Purchases] Warning: tried to enable AdServices attribution token collection, but it's only available on iOS 14.3 or greater or macOS 11.1 or greater.");
164
- }
165
- }
166
-
167
- RCT_REMAP_METHOD(isAnonymous,
168
- isAnonymousWithResolve:(RCTPromiseResolveBlock)resolve
169
- reject:(RCTPromiseRejectBlock)reject) {
170
- resolve(@([RCCommonFunctionality isAnonymous]));
171
- }
172
-
173
- RCT_EXPORT_METHOD(makeDeferredPurchase:(nonnull NSNumber *)callbackID
174
- resolve:(RCTPromiseResolveBlock)resolve
175
- reject:(RCTPromiseRejectBlock)reject) {
176
- StartPurchaseBlock defermentBlock = [self.defermentBlocks objectAtIndex:[callbackID integerValue]];
177
- [RCCommonFunctionality makeDeferredPurchase:defermentBlock
178
- completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
179
- }
180
-
181
- RCT_EXPORT_METHOD(checkTrialOrIntroductoryPriceEligibility:(NSArray *)products
182
- resolve:(RCTPromiseResolveBlock)resolve
183
- reject:(RCTPromiseRejectBlock)reject) {
184
- [RCCommonFunctionality checkTrialOrIntroductoryPriceEligibility:products
185
- completionBlock:^(NSDictionary<NSString *,RCIntroEligibility *> * _Nonnull responseDictionary) {
186
- resolve([NSDictionary dictionaryWithDictionary:responseDictionary]);
187
- }];
188
- }
189
-
190
- RCT_EXPORT_METHOD(invalidateCustomerInfoCache) {
191
- [RCCommonFunctionality invalidateCustomerInfoCache];
192
- }
193
-
194
- RCT_REMAP_METHOD(getPromotionalOffer,
195
- getPromotionalOfferForProductIdentifier:(NSString *)productIdentifier
196
- discount:(NSString *)discount
197
- resolve:(RCTPromiseResolveBlock)resolve
198
- reject:(RCTPromiseRejectBlock)reject) {
199
- [RCCommonFunctionality promotionalOfferForProductIdentifier:productIdentifier
200
- discount:discount
201
- completionBlock:[self getResponseCompletionBlockWithResolve:resolve reject:reject]];
202
- }
203
-
204
- RCT_EXPORT_METHOD(presentCodeRedemptionSheet) {
205
- if (@available(iOS 14.0, *)) {
206
- [RCCommonFunctionality presentCodeRedemptionSheet];
207
- } else {
208
- NSLog(@"[Purchases] Warning: tried to present codeRedemptionSheet, but it's only available on iOS 14.0 or greater.");
209
- }
210
- }
211
-
212
- #pragma mark - Subscriber Attributes
213
-
214
- RCT_EXPORT_METHOD(setProxyURLString:(nullable NSString *)proxyURLString) {
215
- [RCCommonFunctionality setProxyURLString:proxyURLString];
216
- }
217
-
218
- RCT_EXPORT_METHOD(setAttributes:(NSDictionary *)attributes) {
219
- [RCCommonFunctionality setAttributes:attributes];
220
- }
221
-
222
- RCT_EXPORT_METHOD(setEmail:(NSString *)email) {
223
- [RCCommonFunctionality setEmail:email];
224
- }
225
-
226
- RCT_EXPORT_METHOD(setPhoneNumber:(NSString *)phoneNumber) {
227
- [RCCommonFunctionality setPhoneNumber:phoneNumber];
228
- }
229
-
230
- RCT_EXPORT_METHOD(setDisplayName:(NSString *)displayName) {
231
- [RCCommonFunctionality setDisplayName:displayName];
232
- }
233
-
234
- RCT_EXPORT_METHOD(setPushToken:(NSString *)pushToken) {
235
- [RCCommonFunctionality setPushToken:pushToken];
236
- }
237
-
238
- # pragma mark Attribution IDs
239
-
240
- RCT_EXPORT_METHOD(collectDeviceIdentifiers) {
241
- [RCCommonFunctionality collectDeviceIdentifiers];
242
- }
243
-
244
- RCT_EXPORT_METHOD(setAdjustID:(NSString *)adjustID) {
245
- [RCCommonFunctionality setAdjustID:adjustID];
246
- }
247
-
248
- RCT_EXPORT_METHOD(setAppsflyerID:(NSString *)appsflyerID) {
249
- [RCCommonFunctionality setAppsflyerID:appsflyerID];
250
- }
251
-
252
- RCT_EXPORT_METHOD(setFBAnonymousID:(NSString *)fbAnonymousID) {
253
- [RCCommonFunctionality setFBAnonymousID:fbAnonymousID];
254
- }
255
-
256
- RCT_EXPORT_METHOD(setMparticleID:(NSString *)mparticleID) {
257
- [RCCommonFunctionality setMparticleID:mparticleID];
258
- }
259
-
260
- RCT_EXPORT_METHOD(setOnesignalID:(NSString *)onesignalID) {
261
- [RCCommonFunctionality setOnesignalID:onesignalID];
262
- }
263
-
264
- RCT_EXPORT_METHOD(setAirshipChannelID:(NSString *)airshipChannelID) {
265
- [RCCommonFunctionality setAirshipChannelID:airshipChannelID];
266
- }
267
-
268
- # pragma mark Campaign parameters
269
-
270
- RCT_EXPORT_METHOD(setMediaSource:(NSString *)mediaSource) {
271
- [RCCommonFunctionality setMediaSource:mediaSource];
272
- }
273
-
274
- RCT_EXPORT_METHOD(setCampaign:(NSString *)campaign) {
275
- [RCCommonFunctionality setCampaign:campaign];
276
- }
277
-
278
- RCT_EXPORT_METHOD(setAdGroup:(NSString *)adGroup) {
279
- [RCCommonFunctionality setAdGroup:adGroup];
280
- }
281
-
282
- RCT_EXPORT_METHOD(setAd:(NSString *)ad) {
283
- [RCCommonFunctionality setAd:ad];
284
- }
285
-
286
- RCT_EXPORT_METHOD(setKeyword:(NSString *)keyword) {
287
- [RCCommonFunctionality setKeyword:keyword];
288
- }
289
-
290
- RCT_EXPORT_METHOD(setCreative:(NSString *)creative) {
291
- [RCCommonFunctionality setCreative:creative];
292
- }
293
-
294
- RCT_REMAP_METHOD(canMakePayments,
295
- canMakePaymentsWithFeatures:(NSArray<NSNumber *> *)features
296
- resolve:(RCTPromiseResolveBlock)resolve
297
- reject:(RCTPromiseRejectBlock)reject) {
298
- resolve(@([RCCommonFunctionality canMakePaymentsWithFeatures:features]));
299
- }
300
-
301
- RCT_REMAP_METHOD(isConfigured,
302
- isConfiguredWithResolve:(RCTPromiseResolveBlock)resolve
303
- reject:(RCTPromiseRejectBlock)reject) {
304
- resolve(@(RCPurchases.isConfigured));
305
- }
306
-
307
- #pragma mark -
308
- #pragma mark Delegate Methods
309
- - (void)purchases:(RCPurchases *)purchases didReceiveUpdatedCustomerInfo:(RCCustomerInfo *)customerInfo {
310
- [self sendEventWithName:RNPurchasesCustomerInfoUpdatedEvent body:customerInfo.dictionary];
311
- }
312
-
313
- - (void)purchases:(RCPurchases *)purchases
314
- readyForPromotedProduct:(RCStoreProduct *)product
315
- purchase:(void (^)(void (^ _Nonnull)(RCStoreTransaction * _Nullable, RCCustomerInfo * _Nullable, NSError * _Nullable, BOOL)))startPurchase {
316
- if (!self.defermentBlocks) {
317
- self.defermentBlocks = [NSMutableArray array];
318
- }
319
- [self.defermentBlocks addObject:startPurchase];
320
- NSInteger position = [self.defermentBlocks count] - 1;
321
- [self sendEventWithName:RNPurchasesShouldPurchasePromoProductEvent body:@{@"callbackID": @(position)}];
322
- }
323
-
324
- #pragma mark -
325
- #pragma mark Helper Methods
326
-
327
- - (void)rejectPromiseWithBlock:(RCTPromiseRejectBlock)reject error:(NSError *)error {
328
- reject([NSString stringWithFormat: @"%ld", (long)error.code], error.localizedDescription, error);
329
- }
330
-
331
- - (void (^)(NSDictionary *, RCErrorContainer *))getResponseCompletionBlockWithResolve:(RCTPromiseResolveBlock)resolve
332
- reject:(RCTPromiseRejectBlock)reject {
333
- return ^(NSDictionary *_Nullable responseDictionary, RCErrorContainer *_Nullable error) {
334
- if (error) {
335
- reject([NSString stringWithFormat:@"%ld", (long) error.code], error.message, error.error);
336
- } else if (responseDictionary) {
337
- resolve([NSDictionary dictionaryWithDictionary:responseDictionary]);
338
- } else {
339
- resolve(nil);
340
- }
341
- };
342
- }
343
-
344
- - (NSString *)platformFlavor {
345
- return @"react-native";
346
- }
347
-
348
- - (NSString *)platformFlavorVersion {
349
- return @"5.0.0-beta.3";
350
- }
351
-
352
- @end
@@ -1,9 +0,0 @@
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>