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,379 @@
1
+ package com.revenuecat.purchases.react;
2
+
3
+ import android.util.Log;
4
+
5
+ import androidx.annotation.NonNull;
6
+ import androidx.annotation.Nullable;
7
+
8
+ import com.facebook.react.bridge.Arguments;
9
+ import com.facebook.react.bridge.Promise;
10
+ import com.facebook.react.bridge.ReactApplicationContext;
11
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
12
+ import com.facebook.react.bridge.ReactMethod;
13
+ import com.facebook.react.bridge.ReadableArray;
14
+ import com.facebook.react.bridge.ReadableMap;
15
+ import com.facebook.react.bridge.WritableArray;
16
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
17
+ import com.revenuecat.purchases.CustomerInfo;
18
+ import com.revenuecat.purchases.Purchases;
19
+ import com.revenuecat.purchases.Store;
20
+ import com.revenuecat.purchases.common.PlatformInfo;
21
+ import com.revenuecat.purchases.hybridcommon.CommonKt;
22
+ import com.revenuecat.purchases.hybridcommon.ErrorContainer;
23
+ import com.revenuecat.purchases.hybridcommon.OnResult;
24
+ import com.revenuecat.purchases.hybridcommon.OnResultAny;
25
+ import com.revenuecat.purchases.hybridcommon.OnResultList;
26
+ import com.revenuecat.purchases.hybridcommon.SubscriberAttributesKt;
27
+ import com.revenuecat.purchases.hybridcommon.mappers.CustomerInfoMapperKt;
28
+ import com.revenuecat.purchases.interfaces.UpdatedCustomerInfoListener;
29
+
30
+ import org.jetbrains.annotations.NotNull;
31
+ import org.json.JSONException;
32
+
33
+ import java.util.ArrayList;
34
+ import java.util.HashMap;
35
+ import java.util.List;
36
+ import java.util.Map;
37
+
38
+ import kotlin.UninitializedPropertyAccessException;
39
+
40
+ import static com.revenuecat.purchases.react.RNPurchasesConverters.convertMapToWriteableMap;
41
+
42
+ public class RNPurchasesModule extends ReactContextBaseJavaModule implements UpdatedCustomerInfoListener {
43
+
44
+ private static final String CUSTOMER_INFO_UPDATED = "Purchases-CustomerInfoUpdated";
45
+ public static final String PLATFORM_NAME = "react-native";
46
+ public static final String PLUGIN_VERSION = "4.6.0";
47
+
48
+ private final ReactApplicationContext reactContext;
49
+
50
+ @SuppressWarnings("WeakerAccess")
51
+ public RNPurchasesModule(ReactApplicationContext reactContext) {
52
+ super(reactContext);
53
+ this.reactContext = reactContext;
54
+ }
55
+
56
+ @NonNull
57
+ @Override
58
+ public String getName() {
59
+ return "RNPurchases";
60
+ }
61
+
62
+ public void onCatalystInstanceDestroy() {
63
+ try {
64
+ Purchases.getSharedInstance().close();
65
+ } catch (UninitializedPropertyAccessException e) {
66
+ // there's no instance so all good
67
+ }
68
+ }
69
+
70
+ @ReactMethod
71
+ public void addListener(String eventName) {
72
+ // Keep: Required for RN built in Event Emitter Calls.
73
+ }
74
+
75
+ @ReactMethod
76
+ public void removeListeners(Integer count) {
77
+ // Keep: Required for RN built in Event Emitter Calls.
78
+ }
79
+
80
+ @ReactMethod
81
+ public void setupPurchases(String apiKey, @Nullable String appUserID,
82
+ boolean observerMode, @Nullable String userDefaultsSuiteName,
83
+ @Nullable Boolean usesStoreKit2IfAvailable, boolean useAmazon) {
84
+ PlatformInfo platformInfo = new PlatformInfo(PLATFORM_NAME, PLUGIN_VERSION);
85
+ Store store = Store.PLAY_STORE;
86
+ if (useAmazon) {
87
+ store = Store.AMAZON;
88
+ }
89
+ CommonKt.configure(reactContext, apiKey, appUserID, observerMode, platformInfo, store);
90
+ Purchases.getSharedInstance().setUpdatedPurchaserInfoListener(this);
91
+ }
92
+
93
+ @ReactMethod
94
+ public void setAllowSharingStoreAccount(boolean allowSharingStoreAccount) {
95
+ CommonKt.setAllowSharingAppStoreAccount(allowSharingStoreAccount);
96
+ }
97
+
98
+ @ReactMethod
99
+ public void getOfferings(final Promise promise) {
100
+ CommonKt.getOfferings(getOnResult(promise));
101
+ }
102
+
103
+ @ReactMethod
104
+ public void getProductInfo(ReadableArray productIDs, String type, final Promise promise) {
105
+ ArrayList<String> productIDList = new ArrayList<>();
106
+ for (int i = 0; i < productIDs.size(); i++) {
107
+ productIDList.add(productIDs.getString(i));
108
+ }
109
+ CommonKt.getProductInfo(productIDList, type, new OnResultList() {
110
+ @Override
111
+ public void onReceived(List<Map<String, ?>> map) {
112
+ WritableArray writableArray = Arguments.createArray();
113
+ for (Map<String, ?> detail : map) {
114
+ writableArray.pushMap(convertMapToWriteableMap(detail));
115
+ }
116
+ promise.resolve(writableArray);
117
+ }
118
+
119
+ @Override
120
+ public void onError(ErrorContainer errorContainer) {
121
+ promise.reject(errorContainer.getCode() + "", errorContainer.getMessage(),
122
+ convertMapToWriteableMap(errorContainer.getInfo()));
123
+ }
124
+ });
125
+ }
126
+
127
+ @ReactMethod
128
+ public void purchaseProduct(final String productIdentifier,
129
+ @Nullable final ReadableMap upgradeInfo,
130
+ final String type,
131
+ @Nullable final String discountTimestamp,
132
+ final Promise promise) {
133
+ CommonKt.purchaseProduct(
134
+ getCurrentActivity(),
135
+ productIdentifier,
136
+ upgradeInfo != null && upgradeInfo.hasKey("oldSKU") ? upgradeInfo.getString("oldSKU") : null,
137
+ upgradeInfo != null && upgradeInfo.hasKey("prorationMode") ? upgradeInfo.getInt("prorationMode") : null,
138
+ type,
139
+ getOnResult(promise));
140
+ }
141
+
142
+ @ReactMethod
143
+ public void purchasePackage(final String packageIdentifier,
144
+ final String offeringIdentifier,
145
+ @Nullable final ReadableMap upgradeInfo,
146
+ @Nullable final String discountTimestamp,
147
+ final Promise promise) {
148
+ CommonKt.purchasePackage(
149
+ getCurrentActivity(),
150
+ packageIdentifier,
151
+ offeringIdentifier,
152
+ upgradeInfo != null && upgradeInfo.hasKey("oldSKU") ? upgradeInfo.getString("oldSKU") : null,
153
+ upgradeInfo != null && upgradeInfo.hasKey("prorationMode") ? upgradeInfo.getInt("prorationMode") : null,
154
+ getOnResult(promise));
155
+ }
156
+
157
+ @ReactMethod
158
+ public void getAppUserID(final Promise promise) {
159
+ promise.resolve(CommonKt.getAppUserID());
160
+ }
161
+
162
+ @ReactMethod
163
+ public void restorePurchases(final Promise promise) {
164
+ CommonKt.restorePurchases(getOnResult(promise));
165
+ }
166
+
167
+ @ReactMethod
168
+ public void logOut(final Promise promise) {
169
+ CommonKt.logOut(getOnResult(promise));
170
+ }
171
+
172
+ @ReactMethod
173
+ public void logIn(String appUserID, final Promise promise) {
174
+ CommonKt.logIn(appUserID, getOnResult(promise));
175
+ }
176
+
177
+ @ReactMethod
178
+ public void setDebugLogsEnabled(boolean enabled) {
179
+ CommonKt.setDebugLogsEnabled(enabled);
180
+ }
181
+
182
+ @ReactMethod
183
+ public void getCustomerInfo(final Promise promise) {
184
+ CommonKt.getCustomerInfo(getOnResult(promise));
185
+ }
186
+
187
+ @ReactMethod
188
+ public void setFinishTransactions(boolean enabled) {
189
+ CommonKt.setFinishTransactions(enabled);
190
+ }
191
+
192
+ @ReactMethod
193
+ public void syncPurchases() {
194
+ CommonKt.syncPurchases();
195
+ }
196
+
197
+ @ReactMethod
198
+ public void isAnonymous(final Promise promise) {
199
+ promise.resolve(CommonKt.isAnonymous());
200
+ }
201
+
202
+ @ReactMethod
203
+ public void checkTrialOrIntroductoryPriceEligibility(ReadableArray productIDs, final Promise promise) {
204
+ ArrayList<String> productIDList = new ArrayList<>();
205
+ for (int i = 0; i < productIDs.size(); i++) {
206
+ productIDList.add(productIDs.getString(i));
207
+ }
208
+ promise.resolve(convertMapToWriteableMap(CommonKt.checkTrialOrIntroductoryPriceEligibility(productIDList)));
209
+ }
210
+
211
+ @Override
212
+ public void onReceived(@NonNull CustomerInfo customerInfo) {
213
+ reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
214
+ .emit(RNPurchasesModule.CUSTOMER_INFO_UPDATED,
215
+ convertMapToWriteableMap(CustomerInfoMapperKt.map(customerInfo)));
216
+ }
217
+
218
+ @ReactMethod
219
+ public void invalidateCustomerInfoCache() {
220
+ CommonKt.invalidateCustomerInfoCache();
221
+ }
222
+
223
+ @ReactMethod
224
+ public void setProxyURLString(String proxyURLString) {
225
+ CommonKt.setProxyURLString(proxyURLString);
226
+ }
227
+
228
+ @ReactMethod
229
+ public void isConfigured(Promise promise) {
230
+ promise.resolve(Purchases.isConfigured());
231
+ }
232
+
233
+ //================================================================================
234
+ // Subscriber Attributes
235
+ //================================================================================
236
+
237
+ @ReactMethod
238
+ public void setAttributes(ReadableMap attributes) {
239
+ HashMap attributesHashMap = attributes.toHashMap();
240
+ SubscriberAttributesKt.setAttributes(attributesHashMap);
241
+ }
242
+
243
+ @ReactMethod
244
+ public void setEmail(String email) {
245
+ SubscriberAttributesKt.setEmail(email);
246
+ }
247
+
248
+ @ReactMethod
249
+ public void setPhoneNumber(String phoneNumber) {
250
+ SubscriberAttributesKt.setPhoneNumber(phoneNumber);
251
+ }
252
+
253
+ @ReactMethod
254
+ public void setDisplayName(String displayName) {
255
+ SubscriberAttributesKt.setDisplayName(displayName);
256
+ }
257
+
258
+ @ReactMethod
259
+ public void setPushToken(String pushToken) {
260
+ SubscriberAttributesKt.setPushToken(pushToken);
261
+ }
262
+
263
+ // region Attribution IDs
264
+
265
+ @ReactMethod
266
+ public void collectDeviceIdentifiers() {
267
+ SubscriberAttributesKt.collectDeviceIdentifiers();
268
+ }
269
+
270
+ @ReactMethod
271
+ public void setAdjustID(String adjustID) {
272
+ SubscriberAttributesKt.setAdjustID(adjustID);
273
+ }
274
+
275
+ @ReactMethod
276
+ public void setAppsflyerID(String appsflyerID) {
277
+ SubscriberAttributesKt.setAppsflyerID(appsflyerID);
278
+ }
279
+
280
+ @ReactMethod
281
+ public void setFBAnonymousID(String fbAnonymousID) {
282
+ SubscriberAttributesKt.setFBAnonymousID(fbAnonymousID);
283
+ }
284
+
285
+ @ReactMethod
286
+ public void setMparticleID(String mparticleID) {
287
+ SubscriberAttributesKt.setMparticleID(mparticleID);
288
+ }
289
+
290
+ @ReactMethod
291
+ public void setOnesignalID(String onesignalID) {
292
+ SubscriberAttributesKt.setOnesignalID(onesignalID);
293
+ }
294
+
295
+ @ReactMethod
296
+ public void setAirshipChannelID(String airshipChannelID) {
297
+ SubscriberAttributesKt.setAirshipChannelID(airshipChannelID);
298
+ }
299
+
300
+ // endregion
301
+
302
+ // region Campaign parameters
303
+
304
+ @ReactMethod
305
+ public void setMediaSource(String mediaSource) {
306
+ SubscriberAttributesKt.setMediaSource(mediaSource);
307
+ }
308
+
309
+ @ReactMethod
310
+ public void setCampaign(String campaign) {
311
+ SubscriberAttributesKt.setCampaign(campaign);
312
+ }
313
+
314
+ @ReactMethod
315
+ public void setAdGroup(String adGroup) {
316
+ SubscriberAttributesKt.setAdGroup(adGroup);
317
+ }
318
+
319
+ @ReactMethod
320
+ public void setAd(String ad) {
321
+ SubscriberAttributesKt.setAd(ad);
322
+ }
323
+
324
+ @ReactMethod
325
+ public void setKeyword(String keyword) {
326
+ SubscriberAttributesKt.setKeyword(keyword);
327
+ }
328
+
329
+ @ReactMethod
330
+ public void setCreative(String creative) {
331
+ SubscriberAttributesKt.setCreative(creative);
332
+ }
333
+
334
+ @ReactMethod
335
+ public void canMakePayments(ReadableArray features, final Promise promise) {
336
+ ArrayList<Integer> featureList = new ArrayList<>();
337
+
338
+ if (features != null) {
339
+ for (int i = 0; i < features.size(); i++) {
340
+ featureList.add(features.getInt(i));
341
+ }
342
+ }
343
+ CommonKt.canMakePayments(reactContext, featureList, new OnResultAny<Boolean>() {
344
+ @Override
345
+ public void onError(@Nullable ErrorContainer errorContainer) {
346
+ promise.reject(errorContainer.getCode() + "", errorContainer.getMessage(),
347
+ convertMapToWriteableMap(errorContainer.getInfo()));
348
+ }
349
+
350
+ @Override
351
+ public void onReceived(Boolean result) {
352
+ promise.resolve(result);
353
+ }
354
+ });
355
+ }
356
+
357
+ // endregion
358
+
359
+ //================================================================================
360
+ // Private methods
361
+ //================================================================================
362
+
363
+ @NotNull
364
+ private OnResult getOnResult(final Promise promise) {
365
+ return new OnResult() {
366
+ @Override
367
+ public void onReceived(Map<String, ?> map) {
368
+ promise.resolve(convertMapToWriteableMap(map));
369
+ }
370
+
371
+ @Override
372
+ public void onError(ErrorContainer errorContainer) {
373
+ promise.reject(errorContainer.getCode() + "", errorContainer.getMessage(),
374
+ convertMapToWriteableMap(errorContainer.getInfo()));
375
+ }
376
+ };
377
+ }
378
+
379
+ }
@@ -12,7 +12,6 @@ export interface PurchasesEntitlementInfo {
12
12
  readonly isActive: boolean;
13
13
  /**
14
14
  * True if the underlying subscription is set to renew at the end of the billing period (expirationDate).
15
- * Will always be True if entitlement is for lifetime access.
16
15
  */
17
16
  readonly willRenew: boolean;
18
17
  /**
@@ -74,9 +73,9 @@ export interface PurchasesEntitlementInfos {
74
73
  [key: string]: PurchasesEntitlementInfo;
75
74
  };
76
75
  }
77
- export interface PurchaserInfo {
76
+ export interface CustomerInfo {
78
77
  /**
79
- * Entitlements attached to this purchaser info
78
+ * Entitlements attached to this customer info
80
79
  */
81
80
  readonly entitlements: PurchasesEntitlementInfos;
82
81
  /**
@@ -137,13 +136,13 @@ export interface PurchaserInfo {
137
136
  * If there are multiple for different platforms, it will point to the device store.
138
137
  */
139
138
  readonly managementURL: string | null;
140
- readonly nonSubscriptionTransactions: PurchasesTransaction[];
139
+ readonly nonSubscriptionTransactions: PurchasesStoreTransaction[];
141
140
  }
142
141
  /**
143
142
  * List of all non subscription transactions. Use this to fetch the history of
144
143
  * non-subscription purchases
145
144
  */
146
- export interface PurchasesTransaction {
145
+ export interface PurchasesStoreTransaction {
147
146
  /**
148
147
  * RevenueCat Id associated to the transaction.
149
148
  */
File without changes
package/dist/errors.d.ts CHANGED
@@ -34,6 +34,9 @@ export interface PurchasesError {
34
34
  export interface ErrorInfo {
35
35
  readableErrorCode: string;
36
36
  }
37
+ /**
38
+ * @internal
39
+ */
37
40
  export declare class UninitializedPurchasesError extends Error {
38
41
  constructor();
39
42
  }
package/dist/errors.js CHANGED
@@ -41,6 +41,9 @@ var PURCHASES_ERROR_CODE;
41
41
  PURCHASES_ERROR_CODE["INVALID_SUBSCRIBER_ATTRIBUTES_ERROR"] = "21";
42
42
  PURCHASES_ERROR_CODE["LOG_OUT_ANONYMOUS_USER_ERROR"] = "22";
43
43
  })(PURCHASES_ERROR_CODE = exports.PURCHASES_ERROR_CODE || (exports.PURCHASES_ERROR_CODE = {}));
44
+ /**
45
+ * @internal
46
+ */
44
47
  var UninitializedPurchasesError = /** @class */ (function (_super) {
45
48
  __extends(UninitializedPurchasesError, _super);
46
49
  function UninitializedPurchasesError() {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import Purchases from './purchases';
2
2
  export default Purchases;
3
3
  export * from './errors';
4
- export * from './purchaserInfo';
4
+ export * from './customerInfo';
5
5
  export * from './purchases';
6
6
  export * from './offerings';
package/dist/index.js CHANGED
@@ -16,6 +16,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
16
16
  var purchases_1 = __importDefault(require("./purchases"));
17
17
  exports.default = purchases_1.default;
18
18
  __exportStar(require("./errors"), exports);
19
- __exportStar(require("./purchaserInfo"), exports);
19
+ __exportStar(require("./customerInfo"), exports);
20
20
  __exportStar(require("./purchases"), exports);
21
21
  __exportStar(require("./offerings"), exports);
@@ -48,9 +48,13 @@ export declare enum INTRO_ELIGIBILITY_STATUS {
48
48
  /**
49
49
  * The user is eligible for a free trial or intro pricing for this product.
50
50
  */
51
- INTRO_ELIGIBILITY_STATUS_ELIGIBLE = 2
51
+ INTRO_ELIGIBILITY_STATUS_ELIGIBLE = 2,
52
+ /**
53
+ * There is no free trial or intro pricing for this product.
54
+ */
55
+ INTRO_ELIGIBILITY_STATUS_NO_INTRO_OFFER_EXISTS = 3
52
56
  }
53
- export interface PurchasesProduct {
57
+ export interface PurchasesStoreProduct {
54
58
  /**
55
59
  * Product Id.
56
60
  */
@@ -70,47 +74,11 @@ export interface PurchasesProduct {
70
74
  /**
71
75
  * Formatted price of the item, including its currency sign.
72
76
  */
73
- readonly price_string: string;
77
+ readonly priceString: string;
74
78
  /**
75
79
  * Currency code for price and original price.
76
80
  */
77
- readonly currency_code: string;
78
- /**
79
- * @deprecated, use introPrice instead.
80
- *
81
- * Introductory price of a subscription in the local currency.
82
- */
83
- readonly intro_price: number | null;
84
- /**
85
- * @deprecated, use introPrice instead.
86
- *
87
- * Formatted introductory price of a subscription, including its currency sign, such as €3.99.
88
- */
89
- readonly intro_price_string: string | null;
90
- /**
91
- * @deprecated, use introPrice instead.
92
- *
93
- * Billing period of the introductory price, specified in ISO 8601 format.
94
- */
95
- readonly intro_price_period: string | null;
96
- /**
97
- * @deprecated, use introPrice instead.
98
- *
99
- * Number of subscription billing periods for which the user will be given the introductory price, such as 3.
100
- */
101
- readonly intro_price_cycles: number | null;
102
- /**
103
- * @deprecated, use introPrice instead.
104
- *
105
- * Unit for the billing period of the introductory price, can be DAY, WEEK, MONTH or YEAR.
106
- */
107
- readonly intro_price_period_unit: string | null;
108
- /**
109
- * @deprecated, use introPrice instead.
110
- *
111
- * Number of units for the billing period of the introductory price.
112
- */
113
- readonly intro_price_period_number_of_units: number | null;
81
+ readonly currencyCode: string;
114
82
  /**
115
83
  * Introductory price.
116
84
  */
@@ -118,9 +86,9 @@ export interface PurchasesProduct {
118
86
  /**
119
87
  * Collection of discount offers for a product. Null for Android.
120
88
  */
121
- readonly discounts: PurchasesDiscount[] | null;
89
+ readonly discounts: PurchasesStoreProductDiscount[] | null;
122
90
  }
123
- export interface PurchasesDiscount {
91
+ export interface PurchasesStoreProductDiscount {
124
92
  /**
125
93
  * Identifier of the discount.
126
94
  */
@@ -192,7 +160,7 @@ export interface PurchasesPackage {
192
160
  /**
193
161
  * Product assigned to this package.
194
162
  */
195
- readonly product: PurchasesProduct;
163
+ readonly product: PurchasesStoreProduct;
196
164
  /**
197
165
  * Offering this package belongs to.
198
166
  */
@@ -286,7 +254,7 @@ export interface IntroEligibility {
286
254
  */
287
255
  readonly description: string;
288
256
  }
289
- export interface PurchasesPaymentDiscount {
257
+ export interface PurchasesPromotionalOffer {
290
258
  readonly identifier: string;
291
259
  readonly keyIdentifier: string;
292
260
  readonly nonce: string;
package/dist/offerings.js CHANGED
@@ -54,6 +54,10 @@ var INTRO_ELIGIBILITY_STATUS;
54
54
  * The user is eligible for a free trial or intro pricing for this product.
55
55
  */
56
56
  INTRO_ELIGIBILITY_STATUS[INTRO_ELIGIBILITY_STATUS["INTRO_ELIGIBILITY_STATUS_ELIGIBLE"] = 2] = "INTRO_ELIGIBILITY_STATUS_ELIGIBLE";
57
+ /**
58
+ * There is no free trial or intro pricing for this product.
59
+ */
60
+ INTRO_ELIGIBILITY_STATUS[INTRO_ELIGIBILITY_STATUS["INTRO_ELIGIBILITY_STATUS_NO_INTRO_OFFER_EXISTS"] = 3] = "INTRO_ELIGIBILITY_STATUS_NO_INTRO_OFFER_EXISTS";
57
61
  })(INTRO_ELIGIBILITY_STATUS = exports.INTRO_ELIGIBILITY_STATUS || (exports.INTRO_ELIGIBILITY_STATUS = {}));
58
62
  var PRORATION_MODE;
59
63
  (function (PRORATION_MODE) {