react-native-purchases 5.0.0-beta.5 → 5.0.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.
- package/README.md +1 -1
- package/RNPurchases.podspec +1 -1
- package/android/build.gradle +2 -2
- package/dist/customerInfo.d.ts +3 -3
- package/dist/purchases.d.ts +43 -43
- package/dist/purchases.js +43 -43
- package/ios/RNPurchases.m +10 -2
- package/package.json +1 -1
- package/scripts/docs/index.html +1 -1
- package/android/build.gradle.bck +0 -126
- package/android/src/main/java/com/revenuecat/purchases/react/RNPurchasesModule.java.bck +0 -379
- package/ios/RNPurchases.m.bck +0 -352
- package/scripts/build.js.bck +0 -19
- package/scripts/docs/index.html.bck +0 -9
|
@@ -1,379 +0,0 @@
|
|
|
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().setUpdatedCustomerInfoListener(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
|
-
}
|