react-native-incognia 6.26.0 → 7.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.
Files changed (37) hide show
  1. package/android/.gradle/9.0-milestone-1/checksums/checksums.lock +0 -0
  2. package/android/.gradle/9.0-milestone-1/fileHashes/fileHashes.lock +0 -0
  3. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  4. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  5. package/android/.gradle/config.properties +2 -0
  6. package/android/.idea/AndroidProjectSystem.xml +6 -0
  7. package/android/.idea/android.iml +9 -0
  8. package/android/.idea/caches/deviceStreaming.xml +848 -0
  9. package/android/.idea/gradle.xml +13 -0
  10. package/android/.idea/migrations.xml +10 -0
  11. package/android/.idea/misc.xml +9 -0
  12. package/android/.idea/modules.xml +8 -0
  13. package/android/.idea/runConfigurations.xml +17 -0
  14. package/android/.idea/vcs.xml +6 -0
  15. package/android/build.gradle +4 -4
  16. package/android/local.properties +8 -0
  17. package/android/src/main/java/com/incognia/reactnative/IncogniaModule.java +292 -279
  18. package/ios/ICGIncogniaModule.m +26 -271
  19. package/ios/Incognia.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  20. package/ios/Incognia.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  21. package/ios/Incognia.xcodeproj/xcuserdata/mateus.loureiro.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  22. package/lib/commonjs/index.js +208 -43
  23. package/lib/commonjs/index.js.map +1 -1
  24. package/lib/module/index.js +203 -41
  25. package/lib/module/index.js.map +1 -1
  26. package/lib/typescript/index.d.ts +117 -72
  27. package/lib/typescript/index.d.ts.map +1 -1
  28. package/package.json +3 -2
  29. package/react-native-incognia.podspec +3 -3
  30. package/src/index.tsx +334 -105
  31. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  32. package/android/.gradle/8.9/checksums/md5-checksums.bin +0 -0
  33. package/android/.gradle/8.9/checksums/sha1-checksums.bin +0 -0
  34. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  35. package/android/.gradle/8.9/gc.properties +0 -0
  36. /package/android/.gradle/{8.9 → 9.0-milestone-1}/fileChanges/last-build.bin +0 -0
  37. /package/android/.gradle/{8.9/dependencies-accessors → 9.0-milestone-1}/gc.properties +0 -0
@@ -1,37 +1,36 @@
1
1
  package com.incognia.reactnative;
2
2
 
3
3
  import android.app.Application;
4
- import android.location.Address;
5
4
  import android.util.Log;
6
5
 
7
6
  import androidx.annotation.NonNull;
8
7
 
9
- import com.facebook.react.bridge.Arguments;
10
8
  import com.facebook.react.bridge.Promise;
11
9
  import com.facebook.react.bridge.ReactApplicationContext;
12
10
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
13
11
  import com.facebook.react.bridge.ReactMethod;
14
12
  import com.facebook.react.bridge.ReadableArray;
15
13
  import com.facebook.react.bridge.ReadableMap;
16
- import com.facebook.react.bridge.WritableMap;
17
14
  import com.facebook.react.module.annotations.ReactModule;
18
- import com.incognia.ConsentDialogOptions;
19
- import com.incognia.ConsentListener;
20
- import com.incognia.ConsentResult;
21
- import com.incognia.ConsentTypes;
15
+ import com.incognia.CardInfo;
16
+ import com.incognia.CustomEvent;
17
+ import com.incognia.EventAddress;
18
+ import com.incognia.EventLocation;
22
19
  import com.incognia.EventProperties;
23
20
  import com.incognia.Incognia;
24
- import com.incognia.IncogniaListener;
25
21
  import com.incognia.IncogniaOptions;
26
- import com.incognia.IncogniaTrial;
27
- import com.incognia.Result;
28
- import com.incognia.TransactionAddress;
29
-
30
- import java.util.HashMap;
31
- import java.util.HashSet;
22
+ import com.incognia.LoginEvent;
23
+ import com.incognia.OnboardingEvent;
24
+ import com.incognia.PaymentAddress;
25
+ import com.incognia.PaymentCoupon;
26
+ import com.incognia.PaymentEvent;
27
+ import com.incognia.PaymentMethod;
28
+ import com.incognia.PaymentValue;
29
+
30
+ import java.util.ArrayList;
31
+ import java.util.List;
32
32
  import java.util.Locale;
33
33
  import java.util.Map;
34
- import java.util.Set;
35
34
 
36
35
  @SuppressWarnings({"unused",
37
36
  "Convert2Lambda"})
@@ -39,47 +38,65 @@ import java.util.Set;
39
38
  public class IncogniaModule extends ReactContextBaseJavaModule {
40
39
  public static final String NAME = "IncogniaModule";
41
40
 
42
- private static final String CONSENT_DIALOG_TITLE = "dialogTitle";
43
- private static final String CONSENT_DIALOG_MESSAGE = "dialogMessage";
44
- private static final String CONSENT_DIALOG_ACCEPT_TEXT = "dialogAcceptText";
45
- private static final String CONSENT_DIALOG_DENY_TEXT = "dialogDenyText";
46
- private static final String CONSENT_DIALOG_TYPES = "consentTypes";
41
+ private ReactApplicationContext reactContext;
42
+
43
+ private static final String OPTIONS_APP_ID_KEY = "appId";
44
+ private static final String OPTIONS_LOG_ENABLED_KEY = "logEnabled";
45
+ private static final String OPTIONS_LOCATION_ENABLED_KEY = "locationEnabled";
46
+ private static final String OPTIONS_INSTALLED_APPS_COLLECTION_ENABLED_KEY = "installedAppsCollectionEnabled";
47
47
 
48
- private static final String EVENT_NAME = "eventName";
49
- private static final String EVENT_PROPERTIES = "eventProperties";
48
+ private static final String EVENT_ACCOUNT_ID = "accountId";
49
+ private static final String EVENT_EXTERNAL_ID = "externalId";
50
+ private static final String EVENT_ADDRESS = "address";
51
+ private static final String EVENT_LOCATION = "location";
52
+ private static final String EVENT_TAG = "tag";
53
+ private static final String EVENT_PROPERTIES = "properties";
54
+ private static final String EVENT_STATUS = "status";
55
+ private static final String EVENT_STORE_ID = "storeId";
50
56
 
51
57
  private static final String ADDRESS_LOCALE_KEY = "locale";
52
- private static final String ADDRESS_COUNTRY_NAME_KEY = "countryName";
53
58
  private static final String ADDRESS_COUNTRY_CODE_KEY = "countryCode";
54
- private static final String ADDRESS_ADMIN_AREA_KEY = "adminArea";
55
- private static final String ADDRESS_SUB_ADMIN_AREA_KEY = "subAdminArea";
56
- private static final String ADDRESS_LOCALITY_KEY = "locality";
57
- private static final String ADDRESS_SUB_LOCALITY_KEY = "subLocality";
58
- private static final String ADDRESS_THOROUGHFARE_KEY = "thoroughfare";
59
- private static final String ADDRESS_SUB_THOROUGHFARE_KEY = "subThoroughfare";
59
+ private static final String ADDRESS_COUNTRY_NAME_KEY = "countryName";
60
+ private static final String ADDRESS_STATE_KEY = "state";
61
+ private static final String ADDRESS_CITY_KEY = "city";
62
+ private static final String ADDRESS_NEIGHBORHOOD_KEY = "neighborhood";
63
+ private static final String ADDRESS_NUMBER_KEY = "number";
64
+ private static final String ADDRESS_STREET_KEY = "street";
60
65
  private static final String ADDRESS_POSTAL_CODE_KEY = "postalCode";
66
+ private static final String ADDRESS_LINE_KEY = "addressLine";
61
67
  private static final String ADDRESS_LATITUDE_KEY = "latitude";
62
68
  private static final String ADDRESS_LONGITUDE_KEY = "longitude";
63
- private static final String ADDRESS_LINE = "addressLine";
64
69
 
65
- private static final String SIGNUP_ID = "signupId";
66
- private static final String SIGNUP_ADDRESS = "signupAddress";
67
- private static final String SIGNUP_PROPERTIES = "properties";
68
-
69
- private static final String LOGIN_ID = "loginId";
70
- private static final String LOGIN_ACCOUNT_ID = "accountId";
71
- private static final String LOGIN_PROPERTIES = "properties";
72
-
73
- private static final String TRANSACTION_ID = "transactionId";
74
- private static final String TRANSACTION_ADDRESSES = "transactionAddresses";
75
- private static final String TRANSACTION_PROPERTIES = "properties";
76
- private static final String TRANSACTION_ADDRESS_TYPE = "type";
77
-
78
- private static final String OPTIONS_APP_ID_KEY = "appId";
79
- private static final String OPTIONS_LOG_ENABLED_KEY = "logEnabled";
80
- private static final String OPTIONS_LOCATION_ENABLED_KEY = "locationEnabled";
81
- private static final String OPTIONS_INSTALLED_APPS_COLLECTION_ENABLED_KEY = "installedAppsCollectionEnabled";
82
- private static final String OPTIONS_BACKGROUND_WAKEUP_ENABLED_KEY = "backgroundWakeupEnabled";
70
+ private static final String LOCATION_LATITUDE_KEY = "latitude";
71
+ private static final String LOCATION_LONGITUDE_KEY = "longitude";
72
+ private static final String LOCATION_TIMESTAMP_KEY = "timestamp";
73
+
74
+ private static final String PAYMENT_ADDRESSES = "addresses";
75
+ private static final String PAYMENT_ADDRESS_TYPE = "type";
76
+
77
+ private static final String PAYMENT_VALUE = "paymentValue";
78
+ private static final String PAYMENT_VALUE_AMOUNT = "amount";
79
+ private static final String PAYMENT_VALUE_CURRENCY = "currency";
80
+ private static final String PAYMENT_VALUE_INSTALLMENTS = "installments";
81
+ private static final String PAYMENT_VALUE_DISCOUNT_AMOUNT = "discountAmount";
82
+
83
+ private static final String PAYMENT_COUPON = "paymentCoupon";
84
+ private static final String PAYMENT_COUPON_TYPE = "type";
85
+ private static final String PAYMENT_COUPON_VALUE = "value";
86
+ private static final String PAYMENT_COUPON_MAX_DISCOUNT = "maxDiscount";
87
+ private static final String PAYMENT_COUPON_ID = "id";
88
+ private static final String PAYMENT_COUPON_NAME = "name";
89
+
90
+ private static final String PAYMENT_METHODS = "paymentMethods";
91
+ private static final String PAYMENT_METHOD_TYPE = "type";
92
+ private static final String PAYMENT_METHOD_IDENTIFIER = "identifier";
93
+ private static final String PAYMENT_METHOD_BRAND = "brand";
94
+ private static final String PAYMENT_METHOD_CREDIT_CARD_INFO = "creditCardInfo";
95
+ private static final String PAYMENT_METHOD_DEBIT_CARD_INFO = "debitCardInfo";
96
+ private static final String PAYMENT_METHOD_CARD_INFO_BIN = "bin";
97
+ private static final String PAYMENT_METHOD_CARD_INFO_LAST_FOUR_DIGITS = "lastFourDigits";
98
+ private static final String PAYMENT_METHOD_CARD_INFO_EXPIRY_MONTH = "expiryMonth";
99
+ private static final String PAYMENT_METHOD_CARD_INFO_EXPIRY_YEAR = "expiryYear";
83
100
 
84
101
  public IncogniaModule(ReactApplicationContext reactContext) {
85
102
  super(reactContext);
@@ -107,19 +124,15 @@ public class IncogniaModule extends ReactContextBaseJavaModule {
107
124
  Application application = (Application) getReactApplicationContext().getApplicationContext();
108
125
 
109
126
  String appId = optionsParameters.hasKey(OPTIONS_APP_ID_KEY) ? optionsParameters.getString(OPTIONS_APP_ID_KEY) : null;
110
- boolean logEnabled = optionsParameters.hasKey(OPTIONS_LOG_ENABLED_KEY) && optionsParameters.getBoolean(OPTIONS_LOG_ENABLED_KEY);
111
- boolean locationEnabled = !optionsParameters.hasKey(OPTIONS_LOCATION_ENABLED_KEY) || optionsParameters.getBoolean(OPTIONS_LOCATION_ENABLED_KEY);
112
- boolean installedAppsCollectionEnabled = optionsParameters.hasKey(OPTIONS_INSTALLED_APPS_COLLECTION_ENABLED_KEY) &&
113
- optionsParameters.getBoolean(OPTIONS_INSTALLED_APPS_COLLECTION_ENABLED_KEY);
114
- boolean backgroundWakeupEnabled = optionsParameters.hasKey(OPTIONS_BACKGROUND_WAKEUP_ENABLED_KEY) && optionsParameters.getBoolean(
115
- OPTIONS_BACKGROUND_WAKEUP_ENABLED_KEY);
127
+ boolean logEnabled = optionsParameters.hasKey(OPTIONS_LOG_ENABLED_KEY) ? optionsParameters.getBoolean(OPTIONS_LOG_ENABLED_KEY) : false;
128
+ boolean locationEnabled = optionsParameters.hasKey(OPTIONS_LOCATION_ENABLED_KEY) ? optionsParameters.getBoolean(OPTIONS_LOCATION_ENABLED_KEY) : true;
129
+ boolean installedAppsCollectionEnabled = optionsParameters.hasKey(OPTIONS_INSTALLED_APPS_COLLECTION_ENABLED_KEY) ? optionsParameters.getBoolean(OPTIONS_INSTALLED_APPS_COLLECTION_ENABLED_KEY) : false;
116
130
 
117
131
  IncogniaOptions options = new IncogniaOptions.Builder()
118
132
  .appId(appId)
119
133
  .logEnabled(logEnabled)
120
- .visitsEnabledByDefault(locationEnabled)
134
+ .locationEnabled(locationEnabled)
121
135
  .installedAppsCollectionEnabled(installedAppsCollectionEnabled)
122
- .backgroundWakeupEnabled(backgroundWakeupEnabled)
123
136
  .build();
124
137
 
125
138
  Incognia.init(application, options);
@@ -138,194 +151,110 @@ public class IncogniaModule extends ReactContextBaseJavaModule {
138
151
  Incognia.clearAccountId();
139
152
  }
140
153
 
141
- @ReactMethod
142
- public void allowConsentTypes(final ReadableArray consentTypesArray) {
143
- Set<String> consentTypes = convertStringReadableArrayToSet(consentTypesArray);
144
- Incognia.allowConsentTypes(consentTypes);
145
- }
146
-
147
- @ReactMethod
148
- public void denyConsentTypes(final ReadableArray consentTypesArray) {
149
- Set<String> consentTypes = convertStringReadableArrayToSet(consentTypesArray);
150
- Incognia.denyConsentTypes(consentTypes);
151
- }
152
-
153
154
  @ReactMethod
154
155
  public void setLocationEnabled(final boolean enabled) {
155
156
  Incognia.setLocationEnabled(enabled);
156
157
  }
157
158
 
158
- @ReactMethod
159
- public void fetchInstallationId(final Promise promise) {
160
- Incognia.fetchInstallationId(new IncogniaListener<String>() {
161
- @Override
162
- public void onResult(Result<String> result) {
163
- if (result.isSuccessful()) {
164
- String installationId = result.getResult();
165
- promise.resolve(installationId);
166
- } else {
167
- promise.reject(new Exception("Error while getting installation id."));
168
- }
169
- }
170
- });
171
- }
172
-
173
159
  @ReactMethod
174
160
  public void generateRequestToken(final Promise promise) {
175
- Incognia.generateRequestToken(new IncogniaListener<String>() {
176
- @Override
177
- public void onResult(Result<String> result) {
178
- if (result.isSuccessful()) {
179
- String requestToken = result.getResult();
180
- promise.resolve(requestToken);
181
- } else {
182
- promise.reject(new Exception("Error while generating a request token."));
183
- }
161
+ Incognia.generateRequestToken( requestToken -> {
162
+ if (requestToken != null) {
163
+ promise.resolve(requestToken);
164
+ } else {
165
+ promise.reject(new Exception("Error while generating a request token."));
184
166
  }
185
167
  });
186
168
  }
187
169
 
188
170
  @ReactMethod
189
- public void generateUniqueRequestToken(final Promise promise) {
190
- Incognia.generateUniqueRequestToken(new IncogniaListener<String>() {
191
- @Override
192
- public void onResult(Result<String> result) {
193
- if (result.isSuccessful()) {
194
- String requestToken = result.getResult();
195
- promise.resolve(requestToken);
196
- } else {
197
- promise.reject(new Exception("Error while generating a unique request token."));
198
- }
199
- }
200
- });
201
- }
202
-
203
- @ReactMethod
204
- public void requestPrivacyConsent(final ReadableMap consentDialogOptionsMap, final Promise promise) {
205
- ConsentDialogOptions.Builder consentDialogOptions = new ConsentDialogOptions.Builder(getCurrentActivity());
206
-
207
- String dialogTitle = consentDialogOptionsMap.hasKey(CONSENT_DIALOG_TITLE) ? consentDialogOptionsMap.getString(CONSENT_DIALOG_TITLE) : null;
208
- if (dialogTitle != null) {
209
- consentDialogOptions.title(dialogTitle);
210
- }
211
-
212
- String dialogMessage = consentDialogOptionsMap.hasKey(CONSENT_DIALOG_MESSAGE) ? consentDialogOptionsMap.getString(CONSENT_DIALOG_MESSAGE) : null;
213
- if (dialogMessage != null) {
214
- consentDialogOptions.message(dialogMessage);
215
- }
216
-
217
- String dialogAccept = consentDialogOptionsMap.hasKey(CONSENT_DIALOG_ACCEPT_TEXT) ? consentDialogOptionsMap.getString(CONSENT_DIALOG_ACCEPT_TEXT) : null;
218
- if (dialogAccept != null) {
219
- consentDialogOptions.acceptText(dialogAccept);
220
- }
221
-
222
- String dialogDeny = consentDialogOptionsMap.hasKey(CONSENT_DIALOG_DENY_TEXT) ? consentDialogOptionsMap.getString(CONSENT_DIALOG_DENY_TEXT) : null;
223
- if (dialogDeny != null) {
224
- consentDialogOptions.denyText(dialogDeny);
225
- }
226
-
227
- ReadableArray consentTypesArray = consentDialogOptionsMap.hasKey(CONSENT_DIALOG_TYPES) ? consentDialogOptionsMap.getArray(CONSENT_DIALOG_TYPES) : null;
228
- if (consentTypesArray != null) {
229
- consentDialogOptions.consentTypes(convertStringReadableArrayToSet(consentTypesArray));
230
- }
231
-
232
- Incognia.requestPrivacyConsent(consentDialogOptions.build(), new ConsentListener() {
233
- @Override
234
- public void onConsentResult(final ConsentResult consentResult) {
235
- boolean hasFinished = consentResult.hasFinished();
236
- boolean isWaitingConsent = consentResult.isWaitingConsent();
237
- boolean areAllConsentTypesGiven = consentResult.areAllConsentTypesGiven();
238
- WritableMap result = Arguments.createMap();
239
- result.putBoolean("hasFinished", hasFinished);
240
- result.putBoolean("isWaitingConsent", isWaitingConsent);
241
- result.putBoolean("areAllConsentTypesGiven", areAllConsentTypesGiven);
242
- promise.resolve(result);
243
- }
244
- });
245
- }
246
-
247
- @ReactMethod
248
- public void checkConsent(final ReadableArray consentTypesArray, final Promise promise) {
249
- Set<String> consentTypes = convertStringReadableArrayToSet(consentTypesArray);
250
- Incognia.checkConsent(new ConsentListener() {
251
- @Override
252
- public void onConsentResult(final ConsentResult consentResult) {
253
- boolean hasFinished = consentResult.hasFinished();
254
- boolean isWaitingConsent = consentResult.isWaitingConsent();
255
- boolean areAllConsentTypesGiven = consentResult.areAllConsentTypesGiven();
256
- WritableMap result = Arguments.createMap();
257
- result.putBoolean("hasFinished", hasFinished);
258
- result.putBoolean("isWaitingConsent", isWaitingConsent);
259
- result.putBoolean("areAllConsentTypesGiven", areAllConsentTypesGiven);
260
- promise.resolve(result);
261
- }
262
- }, consentTypes);
263
- }
264
-
265
- @ReactMethod
266
- public void trackEvent(final ReadableMap parameters) {
267
- String eventName = parameters.hasKey(EVENT_NAME) ? parameters.getString(EVENT_NAME) : null;
171
+ public void sendCustomEvent(final ReadableMap parameters) {
172
+ String eventAccountId = parameters.hasKey(EVENT_ACCOUNT_ID) ? parameters.getString(EVENT_ACCOUNT_ID) : null;
173
+ String eventExternalId = parameters.hasKey(EVENT_EXTERNAL_ID) ? parameters.getString(EVENT_EXTERNAL_ID) : null;
174
+ String eventTag = parameters.hasKey(EVENT_TAG) ? parameters.getString(EVENT_TAG) : null;
175
+ String eventStatus = parameters.hasKey(EVENT_STATUS) ? parameters.getString(EVENT_STATUS) : null;
268
176
  EventProperties eventProperties = parameters.hasKey(EVENT_PROPERTIES) ? convertToEventProperties(parameters.getMap(EVENT_PROPERTIES)) : null;
269
- Incognia.trackEvent(eventName, eventProperties);
177
+ EventAddress eventAddress = parameters.hasKey(EVENT_ADDRESS) ? convertToEventAddress(parameters.getMap(EVENT_ADDRESS)) : null;
178
+
179
+ CustomEvent customEvent = new CustomEvent.Builder()
180
+ .accountId(eventAccountId)
181
+ .externalId(eventExternalId)
182
+ .address(eventAddress)
183
+ .tag(eventTag)
184
+ .properties(eventProperties)
185
+ .status(eventStatus)
186
+ .build();
187
+ Incognia.sendCustomEvent(customEvent);
270
188
  }
271
189
 
272
190
  @ReactMethod
273
- public void trackLocalizedEvent(final ReadableMap parameters) {
274
- String eventName = parameters.hasKey(EVENT_NAME) ? parameters.getString(EVENT_NAME) : null;
191
+ public void sendOnboardingEvent(ReadableMap parameters) {
192
+ String eventAccountId = parameters.hasKey(EVENT_ACCOUNT_ID) ? parameters.getString(EVENT_ACCOUNT_ID) : null;
193
+ String eventExternalId = parameters.hasKey(EVENT_EXTERNAL_ID) ? parameters.getString(EVENT_EXTERNAL_ID) : null;
194
+ String eventTag = parameters.hasKey(EVENT_TAG) ? parameters.getString(EVENT_TAG) : null;
195
+ String eventStatus = parameters.hasKey(EVENT_STATUS) ? parameters.getString(EVENT_STATUS) : null;
275
196
  EventProperties eventProperties = parameters.hasKey(EVENT_PROPERTIES) ? convertToEventProperties(parameters.getMap(EVENT_PROPERTIES)) : null;
276
- Incognia.trackLocalizedEvent(eventName, eventProperties);
277
- }
278
-
279
- @ReactMethod
280
- public void trackSignupSent(ReadableMap parameters) {
281
- String signUpId = parameters.hasKey(SIGNUP_ID) ? parameters.getString(SIGNUP_ID) : null;
282
- Address address = parameters.hasKey(SIGNUP_ADDRESS) ? convertToAddress(parameters.getMap(SIGNUP_ADDRESS)) : null;
283
- EventProperties eventProperties = parameters.hasKey(SIGNUP_PROPERTIES) ? convertToEventProperties(parameters.getMap(SIGNUP_PROPERTIES)) : null;
284
-
285
- IncogniaTrial.trackSignupSent(signUpId, eventProperties, address);
197
+ EventAddress eventAddress = parameters.hasKey(EVENT_ADDRESS) ? convertToEventAddress(parameters.getMap(EVENT_ADDRESS)) : null;
198
+
199
+ OnboardingEvent onboardingEvent = new OnboardingEvent.Builder()
200
+ .accountId(eventAccountId)
201
+ .externalId(eventExternalId)
202
+ .address(eventAddress)
203
+ .tag(eventTag)
204
+ .properties(eventProperties)
205
+ .status(eventStatus)
206
+ .build();
207
+ Incognia.sendOnboardingEvent(onboardingEvent);
286
208
  }
287
209
 
288
- @SuppressWarnings("ConstantConditions")
289
210
  @ReactMethod
290
- public void trackLoginSucceeded(ReadableMap parameters) {
291
- String accountId = parameters.hasKey(LOGIN_ACCOUNT_ID) ? parameters.getString(LOGIN_ACCOUNT_ID) : null;
292
- String loginId = parameters.hasKey(LOGIN_ID) ? parameters.getString(LOGIN_ID) : null;
293
- EventProperties eventProperties = parameters.hasKey(LOGIN_PROPERTIES) ? convertToEventProperties(parameters.getMap(LOGIN_PROPERTIES)) : null;
294
-
295
- IncogniaTrial.trackLoginSucceeded(accountId, loginId, eventProperties);
296
- }
297
-
298
- @ReactMethod
299
- public void trackPaymentSent(ReadableMap parameters) {
300
- String transactionId = parameters.hasKey(TRANSACTION_ID) ? parameters.getString(TRANSACTION_ID) : null;
301
- Set<TransactionAddress> transactionAddresses = parameters.hasKey(TRANSACTION_ADDRESSES) ? convertTransactionAddressReadableArrayToSet(parameters.getArray(TRANSACTION_ADDRESSES)) : null;
302
- EventProperties eventProperties = parameters.hasKey(TRANSACTION_PROPERTIES) ? convertToEventProperties(parameters.getMap(TRANSACTION_PROPERTIES)) : null;
303
-
304
- IncogniaTrial.trackPaymentSent(transactionId, eventProperties, transactionAddresses);
305
- }
306
-
307
- @ReactMethod
308
- public void notifyAppInForeground() {
309
- Incognia.notifyAppInForeground();
211
+ public void sendLoginEvent(ReadableMap parameters) {
212
+ String eventAccountId = parameters.hasKey(EVENT_ACCOUNT_ID) ? parameters.getString(EVENT_ACCOUNT_ID) : null;
213
+ String eventExternalId = parameters.hasKey(EVENT_EXTERNAL_ID) ? parameters.getString(EVENT_EXTERNAL_ID) : null;
214
+ String eventTag = parameters.hasKey(EVENT_TAG) ? parameters.getString(EVENT_TAG) : null;
215
+ String eventStatus = parameters.hasKey(EVENT_STATUS) ? parameters.getString(EVENT_STATUS) : null;
216
+ EventProperties eventProperties = parameters.hasKey(EVENT_PROPERTIES) ? convertToEventProperties(parameters.getMap(EVENT_PROPERTIES)) : null;
217
+ EventLocation eventLocation = parameters.hasKey(EVENT_LOCATION) ? convertToEventLocation(parameters.getMap(EVENT_LOCATION)) : null;
218
+
219
+ LoginEvent loginEvent = new LoginEvent.Builder()
220
+ .accountId(eventAccountId)
221
+ .externalId(eventExternalId)
222
+ .location(eventLocation)
223
+ .tag(eventTag)
224
+ .properties(eventProperties)
225
+ .status(eventStatus)
226
+ .build();
227
+ Incognia.sendLoginEvent(loginEvent);
310
228
  }
311
229
 
312
230
  @ReactMethod
313
- public void refreshLocation() {
314
- Incognia.refreshLocation();
315
- }
316
-
317
- @Override
318
- public Map<String, Object> getConstants() {
319
- final Map<String, Object> constants = new HashMap<>();
320
- constants.put("CONSENT_TYPE_ADDRESS_VALIDATION", ConsentTypes.ADDRESS_VALIDATION);
321
- constants.put("CONSENT_TYPE_ENGAGE", ConsentTypes.PUSH);
322
- constants.put("CONSENT_TYPE_EVENTS", ConsentTypes.EVENTS);
323
- constants.put("CONSENT_TYPE_LOCATION", ConsentTypes.LOCATION);
324
- constants.put("CONSENT_TYPE_CONTEXT_PROVIDER", ConsentTypes.CONTEXT_PROVIDER);
325
- constants.put("CONSENT_TYPES_ALL", ConsentTypes.ALL.toArray());
326
- constants.put("CONSENT_TYPES_NONE", new String[0]);
327
-
328
- return constants;
231
+ public void sendPaymentEvent(ReadableMap parameters) {
232
+ String eventAccountId = parameters.hasKey(EVENT_ACCOUNT_ID) ? parameters.getString(EVENT_ACCOUNT_ID) : null;
233
+ String eventExternalId = parameters.hasKey(EVENT_EXTERNAL_ID) ? parameters.getString(EVENT_EXTERNAL_ID) : null;
234
+ String eventTag = parameters.hasKey(EVENT_TAG) ? parameters.getString(EVENT_TAG) : null;
235
+ String eventStatus = parameters.hasKey(EVENT_STATUS) ? parameters.getString(EVENT_STATUS) : null;
236
+ String eventStoreId = parameters.hasKey(EVENT_STORE_ID) ? parameters.getString(EVENT_STORE_ID) : null;
237
+ EventProperties eventProperties = parameters.hasKey(EVENT_PROPERTIES) ? convertToEventProperties(parameters.getMap(EVENT_PROPERTIES)) : null;
238
+ EventLocation eventLocation = parameters.hasKey(EVENT_LOCATION) ? convertToEventLocation(parameters.getMap(EVENT_LOCATION)) : null;
239
+ List<PaymentAddress> eventAddresses = parameters.hasKey(PAYMENT_ADDRESSES) ? convertPaymentAddressesReadableArrayToList(parameters.getArray(PAYMENT_ADDRESSES)) : null;
240
+ PaymentValue eventPaymentValue = parameters.hasKey(PAYMENT_VALUE) ? convertToPaymentValue(parameters.getMap(PAYMENT_VALUE)) : null;
241
+ PaymentCoupon eventPaymentCoupon = parameters.hasKey(PAYMENT_COUPON) ? convertToPaymentCoupon(parameters.getMap(PAYMENT_COUPON)) : null;
242
+ List<PaymentMethod> eventPaymentMethods = parameters.hasKey(PAYMENT_METHODS) ? convertPaymentMethodsReadableArrayToList(parameters.getArray(PAYMENT_METHODS)) : null;
243
+
244
+ PaymentEvent paymentEvent = new PaymentEvent.Builder()
245
+ .accountId(eventAccountId)
246
+ .externalId(eventExternalId)
247
+ .location(eventLocation)
248
+ .addresses(eventAddresses)
249
+ .paymentValue(eventPaymentValue)
250
+ .paymentCoupon(eventPaymentCoupon)
251
+ .paymentMethods(eventPaymentMethods)
252
+ .storeId(eventStoreId)
253
+ .tag(eventTag)
254
+ .properties(eventProperties)
255
+ .status(eventStatus)
256
+ .build();
257
+ Incognia.sendPaymentEvent(paymentEvent);
329
258
  }
330
259
 
331
260
  private static EventProperties convertToEventProperties(ReadableMap readableMap) {
@@ -334,106 +263,190 @@ public class IncogniaModule extends ReactContextBaseJavaModule {
334
263
  }
335
264
 
336
265
  Map<String, Object> map = readableMap.toHashMap();
337
- EventProperties eventProperties = EventProperties.newProperties();
266
+ EventProperties eventProperties = new EventProperties();
338
267
  for (Map.Entry<String, Object> entry : map.entrySet()) {
339
268
  if (entry.getValue() instanceof String) {
340
- eventProperties.put(entry.getKey(), (String) entry.getValue());
269
+ eventProperties.set(entry.getKey(), (String) entry.getValue());
341
270
  } else if (entry.getValue() instanceof Integer) {
342
- eventProperties.put(entry.getKey(), (Integer) entry.getValue());
271
+ eventProperties.set(entry.getKey(), (Integer) entry.getValue());
343
272
  } else if (entry.getValue() instanceof Float) {
344
- eventProperties.put(entry.getKey(), (Float) entry.getValue());
273
+ eventProperties.set(entry.getKey(), (Float) entry.getValue());
345
274
  } else if (entry.getValue() instanceof Double) {
346
- eventProperties.put(entry.getKey(), (Double) entry.getValue());
275
+ eventProperties.set(entry.getKey(), (Double) entry.getValue());
347
276
  } else if (entry.getValue() instanceof Boolean) {
348
- eventProperties.put(entry.getKey(), (Boolean) entry.getValue());
277
+ eventProperties.set(entry.getKey(), (Boolean) entry.getValue());
349
278
  }
350
279
  }
351
280
  return eventProperties;
352
281
  }
353
282
 
354
- private static Set<String> convertStringReadableArrayToSet(ReadableArray array) {
355
- if (array == null) {
283
+ private static EventLocation convertToEventLocation(ReadableMap map) {
284
+ if (map == null) {
356
285
  return null;
357
286
  }
358
- Set<String> set = new HashSet<>();
359
- for (int i = 0; i < array.size(); i++) {
360
- set.add(array.getString(i));
361
- }
362
- return set;
287
+
288
+ Double latitude = map.hasKey(LOCATION_LATITUDE_KEY) ? map.getDouble(LOCATION_LATITUDE_KEY) : null;
289
+ Double longitude = map.hasKey(LOCATION_LONGITUDE_KEY) ? map.getDouble(LOCATION_LONGITUDE_KEY) : null;
290
+ Long timestamp = map.hasKey(LOCATION_TIMESTAMP_KEY) ? (long) map.getDouble(LOCATION_TIMESTAMP_KEY) : null;
291
+
292
+ return new EventLocation(latitude, longitude, timestamp);
363
293
  }
364
294
 
365
- private static Address convertToAddress(ReadableMap map) {
295
+ private static PaymentValue convertToPaymentValue(ReadableMap map) {
366
296
  if (map == null) {
367
297
  return null;
368
298
  }
369
299
 
370
- Locale locale = map.hasKey(ADDRESS_LOCALE_KEY) ? localeFromString(map.getString(ADDRESS_LOCALE_KEY)) : null;
371
- Address address = new Address(locale != null ? locale : new Locale("en", "US"));
300
+ Double amount = map.hasKey(PAYMENT_VALUE_AMOUNT) ? map.getDouble(PAYMENT_VALUE_AMOUNT) : null;
301
+ String currency = map.hasKey(PAYMENT_VALUE_CURRENCY) ? map.getString(PAYMENT_VALUE_CURRENCY) : null;
302
+ Integer installments = map.hasKey(PAYMENT_VALUE_INSTALLMENTS) ? (int) map.getDouble(PAYMENT_VALUE_INSTALLMENTS) : null;
303
+ Double discountAmount = map.hasKey(PAYMENT_VALUE_DISCOUNT_AMOUNT) ? map.getDouble(PAYMENT_VALUE_DISCOUNT_AMOUNT) : null;
372
304
 
373
- if (map.hasKey(ADDRESS_COUNTRY_NAME_KEY)) {
374
- address.setCountryName(map.getString(ADDRESS_COUNTRY_NAME_KEY));
375
- }
376
- if (map.hasKey(ADDRESS_COUNTRY_CODE_KEY)) {
377
- address.setCountryCode(map.getString(ADDRESS_COUNTRY_CODE_KEY));
378
- }
379
- if (map.hasKey(ADDRESS_ADMIN_AREA_KEY)) {
380
- address.setAdminArea(map.getString(ADDRESS_ADMIN_AREA_KEY));
381
- }
382
- if (map.hasKey(ADDRESS_SUB_ADMIN_AREA_KEY)) {
383
- address.setSubAdminArea(map.getString(ADDRESS_SUB_ADMIN_AREA_KEY));
384
- }
385
- if (map.hasKey(ADDRESS_LOCALITY_KEY)) {
386
- address.setLocality(map.getString(ADDRESS_LOCALITY_KEY));
387
- }
388
- if (map.hasKey(ADDRESS_SUB_LOCALITY_KEY)) {
389
- address.setSubLocality(map.getString(ADDRESS_SUB_LOCALITY_KEY));
390
- }
391
- if (map.hasKey(ADDRESS_THOROUGHFARE_KEY)) {
392
- address.setThoroughfare(map.getString(ADDRESS_THOROUGHFARE_KEY));
393
- }
394
- if (map.hasKey(ADDRESS_SUB_THOROUGHFARE_KEY)) {
395
- address.setSubThoroughfare(map.getString(ADDRESS_SUB_THOROUGHFARE_KEY));
305
+ return new PaymentValue.Builder(amount)
306
+ .currency(currency)
307
+ .installments(installments)
308
+ .discountAmount(discountAmount)
309
+ .build();
310
+ }
311
+
312
+ private static PaymentCoupon convertToPaymentCoupon(ReadableMap map) {
313
+ if (map == null) {
314
+ return null;
396
315
  }
397
- if (map.hasKey(ADDRESS_POSTAL_CODE_KEY)) {
398
- address.setPostalCode(map.getString(ADDRESS_POSTAL_CODE_KEY));
316
+
317
+ String type = map.hasKey(PAYMENT_COUPON_TYPE) ? map.getString(PAYMENT_COUPON_TYPE) : null;
318
+ Double value = map.hasKey(PAYMENT_COUPON_VALUE) ? map.getDouble(PAYMENT_COUPON_VALUE) : null;
319
+ Double maxDiscount = map.hasKey(PAYMENT_COUPON_MAX_DISCOUNT) ? map.getDouble(PAYMENT_COUPON_MAX_DISCOUNT) : null;
320
+ String id = map.hasKey(PAYMENT_COUPON_ID) ? map.getString(PAYMENT_COUPON_ID) : null;
321
+ String name = map.hasKey(PAYMENT_COUPON_NAME) ? map.getString(PAYMENT_COUPON_NAME) : null;
322
+
323
+ return new PaymentCoupon.Builder()
324
+ .type(type)
325
+ .value(value)
326
+ .maxDiscount(maxDiscount)
327
+ .id(id)
328
+ .name(name)
329
+ .build();
330
+ }
331
+
332
+ private static List<PaymentMethod> convertPaymentMethodsReadableArrayToList(final ReadableArray array) {
333
+ if (array == null) {
334
+ return null;
399
335
  }
400
- if (map.hasKey(ADDRESS_LINE)) {
401
- address.setAddressLine(0, map.getString(ADDRESS_LINE));
336
+
337
+ List<PaymentMethod> list = new ArrayList<>();
338
+ for (int i = 0; i < array.size(); i++) {
339
+ PaymentMethod paymentMethod = convertMapToPaymentMethod(array.getMap(i));
340
+ if (paymentMethod != null) {
341
+ list.add(paymentMethod);
342
+ }
402
343
  }
403
- if (map.hasKey(ADDRESS_LATITUDE_KEY)) {
404
- address.setLatitude(map.getDouble(ADDRESS_LATITUDE_KEY));
344
+ return list;
345
+ }
346
+
347
+ @SuppressWarnings("ConstantConditions")
348
+ private static PaymentMethod convertMapToPaymentMethod(ReadableMap map) {
349
+ if (map == null) {
350
+ return null;
405
351
  }
406
- if (map.hasKey(ADDRESS_LONGITUDE_KEY)) {
407
- address.setLongitude(map.getDouble(ADDRESS_LONGITUDE_KEY));
352
+
353
+ String type = map.hasKey(PAYMENT_METHOD_TYPE) ? map.getString(PAYMENT_METHOD_TYPE) : null;
354
+ String identifier = map.hasKey(PAYMENT_METHOD_IDENTIFIER) ? map.getString(PAYMENT_METHOD_IDENTIFIER) : null;
355
+ String brand = map.hasKey(PAYMENT_METHOD_BRAND) ? map.getString(PAYMENT_METHOD_BRAND) : null;
356
+ CardInfo creditCardInfo = map.hasKey(PAYMENT_METHOD_CREDIT_CARD_INFO) ? convertMapToCardInfo(map.getMap(PAYMENT_METHOD_CREDIT_CARD_INFO)) : null;
357
+ CardInfo debitCardInfo = map.hasKey(PAYMENT_METHOD_DEBIT_CARD_INFO) ? convertMapToCardInfo(map.getMap(PAYMENT_METHOD_DEBIT_CARD_INFO)) : null;
358
+
359
+ return new PaymentMethod.Builder()
360
+ .type(type)
361
+ .identifier(identifier)
362
+ .brand(brand)
363
+ .creditCardInfo(creditCardInfo)
364
+ .debitCardInfo(debitCardInfo)
365
+ .build();
366
+ }
367
+
368
+ @SuppressWarnings("ConstantConditions")
369
+ private static CardInfo convertMapToCardInfo(ReadableMap map) {
370
+ if (map == null) {
371
+ return null;
408
372
  }
409
373
 
410
- return address;
374
+ String bin = map.hasKey(PAYMENT_METHOD_CARD_INFO_BIN) ? map.getString(PAYMENT_METHOD_CARD_INFO_BIN) : null;
375
+ String lastFourDigits = map.hasKey(PAYMENT_METHOD_CARD_INFO_LAST_FOUR_DIGITS) ? map.getString(PAYMENT_METHOD_CARD_INFO_LAST_FOUR_DIGITS) : null;
376
+ String expiryMonth = map.hasKey(PAYMENT_METHOD_CARD_INFO_EXPIRY_MONTH) ? map.getString(PAYMENT_METHOD_CARD_INFO_EXPIRY_MONTH) : null;
377
+ String expiryYear = map.hasKey(PAYMENT_METHOD_CARD_INFO_EXPIRY_YEAR) ? map.getString(PAYMENT_METHOD_CARD_INFO_EXPIRY_YEAR) : null;
378
+
379
+ return new CardInfo.Builder()
380
+ .bin(bin)
381
+ .lastFourDigits(lastFourDigits)
382
+ .expiryMonth(expiryMonth)
383
+ .expiryYear(expiryYear)
384
+ .build();
411
385
  }
412
386
 
413
- private static Set<TransactionAddress> convertTransactionAddressReadableArrayToSet(final ReadableArray array) {
387
+ private static List<PaymentAddress> convertPaymentAddressesReadableArrayToList(final ReadableArray array) {
414
388
  if (array == null) {
415
389
  return null;
416
390
  }
417
391
 
418
- Set<TransactionAddress> set = new HashSet<>();
392
+ List<PaymentAddress> list = new ArrayList<>();
419
393
  for (int i = 0; i < array.size(); i++) {
420
- TransactionAddress transactionAddress = convertMapToTransactionAddress(array.getMap(i));
421
- if (transactionAddress != null) {
422
- set.add(transactionAddress);
394
+ PaymentAddress paymentAddress = convertMapToPaymentAddress(array.getMap(i));
395
+ if (paymentAddress != null) {
396
+ list.add(paymentAddress);
423
397
  }
424
398
  }
425
- return set;
399
+ return list;
426
400
  }
427
401
 
428
402
  @SuppressWarnings("ConstantConditions")
429
- private static TransactionAddress convertMapToTransactionAddress(ReadableMap map) {
403
+ private static PaymentAddress convertMapToPaymentAddress(ReadableMap map) {
404
+ if (map == null) {
405
+ return null;
406
+ }
407
+
408
+ EventAddress eventAddress = convertToEventAddress(map);
409
+ String addressType = map.hasKey(PAYMENT_ADDRESS_TYPE) ? map.getString(PAYMENT_ADDRESS_TYPE) : null;
410
+
411
+ return new PaymentAddress(addressType, eventAddress);
412
+ }
413
+
414
+ private static EventAddress convertToEventAddress(ReadableMap map) {
430
415
  if (map == null) {
431
416
  return null;
432
417
  }
433
418
 
434
- Address address = convertToAddress(map);
435
- String addressType = map.hasKey(TRANSACTION_ADDRESS_TYPE) ? map.getString(TRANSACTION_ADDRESS_TYPE) : null;
436
- return new TransactionAddress(addressType, address);
419
+ String countryCode = map.hasKey(ADDRESS_COUNTRY_CODE_KEY) ? map.getString(ADDRESS_COUNTRY_CODE_KEY) : null;
420
+ String countryName = map.hasKey(ADDRESS_COUNTRY_NAME_KEY) ? map.getString(ADDRESS_COUNTRY_NAME_KEY) : null;
421
+ String state = map.hasKey(ADDRESS_STATE_KEY) ? map.getString(ADDRESS_STATE_KEY) : null;
422
+ String city = map.hasKey(ADDRESS_CITY_KEY) ? map.getString(ADDRESS_CITY_KEY) : null;
423
+ String neighborhood = map.hasKey(ADDRESS_NEIGHBORHOOD_KEY) ? map.getString(ADDRESS_NEIGHBORHOOD_KEY) : null;
424
+ String number = map.hasKey(ADDRESS_NUMBER_KEY) ? map.getString(ADDRESS_NUMBER_KEY) : null;
425
+ String street = map.hasKey(ADDRESS_STREET_KEY) ? map.getString(ADDRESS_STREET_KEY) : null;
426
+ String postalCode = map.hasKey(ADDRESS_POSTAL_CODE_KEY) ? map.getString(ADDRESS_POSTAL_CODE_KEY) : null;
427
+ String addressLine = map.hasKey(ADDRESS_LINE_KEY) ? map.getString(ADDRESS_LINE_KEY) : null;
428
+ Double latitude = map.hasKey(ADDRESS_LATITUDE_KEY) ? map.getDouble(ADDRESS_LATITUDE_KEY) : null;
429
+ Double longitude = map.hasKey(ADDRESS_LONGITUDE_KEY) ? map.getDouble(ADDRESS_LONGITUDE_KEY) : null;
430
+
431
+ Locale locale = map.hasKey(ADDRESS_LOCALE_KEY) ? localeFromString(map.getString(ADDRESS_LOCALE_KEY)) : null;
432
+ if(locale == null && (street != null || addressLine != null)) {
433
+ locale = Locale.getDefault();
434
+ }
435
+
436
+ return new EventAddress.Builder()
437
+ .locale(locale)
438
+ .countryCode(countryCode)
439
+ .countryName(countryName)
440
+ .state(state)
441
+ .city(city)
442
+ .neighborhood(neighborhood)
443
+ .number(number)
444
+ .street(street)
445
+ .postalCode(postalCode)
446
+ .addressLine(addressLine)
447
+ .latitude(latitude)
448
+ .longitude(longitude)
449
+ .build();
437
450
  }
438
451
 
439
452
  private static Locale localeFromString(String locale) {