fidel-react-native 1.6.3 → 2.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.
- package/CHANGELOG.md +10 -0
- package/README.md +54 -55
- package/android/build.gradle +11 -8
- package/android/src/main/java/com/fidelreactlibrary/FidelModule.java +52 -44
- package/android/src/main/java/com/fidelreactlibrary/FidelPackage.java +64 -49
- package/android/src/main/java/com/fidelreactlibrary/adapters/CardVerificationConfigurationProperties.java +22 -0
- package/android/src/main/java/com/fidelreactlibrary/adapters/FidelCardSchemesAdapter.java +46 -29
- package/android/src/main/java/com/fidelreactlibrary/adapters/FidelCardVerificationChoiceAdapter.java +57 -0
- package/android/src/main/java/com/fidelreactlibrary/adapters/FidelCountryAdapter.java +47 -19
- package/android/src/main/java/com/fidelreactlibrary/adapters/FidelProgramTypeAdapter.java +46 -0
- package/android/src/main/java/com/fidelreactlibrary/adapters/FidelSetupAdapter.java +108 -6
- package/android/src/main/java/com/fidelreactlibrary/adapters/FidelSetupProperties.java +67 -0
- package/android/src/main/java/com/fidelreactlibrary/adapters/FidelVerificationConfigurationAdapter.java +35 -0
- package/android/src/main/java/com/fidelreactlibrary/adapters/ImageFromReadableMapAdapter.java +5 -1
- package/android/src/main/java/com/fidelreactlibrary/adapters/ResultsAdapter.java +288 -0
- package/android/src/main/java/com/fidelreactlibrary/adapters/abstraction/CardSchemesAdapter.java +6 -2
- package/android/src/main/java/com/fidelreactlibrary/adapters/abstraction/CardVerificationChoiceAdapter.java +11 -0
- package/android/src/main/java/com/fidelreactlibrary/adapters/abstraction/CountryAdapter.java +14 -3
- package/android/src/main/java/com/fidelreactlibrary/adapters/abstraction/DataAdapter.java +5 -0
- package/android/src/main/java/com/fidelreactlibrary/adapters/abstraction/ProgramTypeAdapter.java +11 -0
- package/android/src/main/java/com/fidelreactlibrary/adapters/abstraction/VerificationConfigurationAdapter.java +9 -0
- package/android/src/main/java/com/fidelreactlibrary/events/BridgeLibraryEvent.java +17 -0
- package/android/src/main/java/com/fidelreactlibrary/events/BridgeLibraryEventEmitter.java +24 -0
- package/android/src/main/java/com/fidelreactlibrary/events/CardVerificationChoiceObserver.java +29 -0
- package/android/src/main/java/com/fidelreactlibrary/events/CardVerificationStartedObserver.java +31 -0
- package/android/src/main/java/com/fidelreactlibrary/events/ResultsObserver.java +72 -0
- package/android/src/test/java/com/fidelreactlibrary/FidelModuleTests.java +50 -31
- package/android/src/test/java/com/fidelreactlibrary/FidelPackageTests.java +0 -1
- package/android/src/test/java/com/fidelreactlibrary/{FidelCardSchemesAdapterTests.java → adapters/FidelCardSchemesAdapterTests.java} +51 -47
- package/android/src/test/java/com/fidelreactlibrary/adapters/FidelCardVerificationChoiceAdapterTest.java +70 -0
- package/android/src/test/java/com/fidelreactlibrary/adapters/FidelCountryAdapterTests.java +157 -0
- package/android/src/test/java/com/fidelreactlibrary/adapters/FidelProgramTypeAdapterTests.java +54 -0
- package/android/src/test/java/com/fidelreactlibrary/adapters/FidelSetupAdapterTests.java +900 -0
- package/android/src/test/java/com/fidelreactlibrary/adapters/FidelVerificationConfigurationAdapterTest.java +51 -0
- package/android/src/test/java/com/fidelreactlibrary/adapters/ResultsAdapterTests.java +74 -0
- package/android/src/test/java/com/fidelreactlibrary/{ErrorEventEmitterTests.java → events/BridgeLibraryEventEmitterTests.java} +18 -7
- package/android/src/test/java/com/fidelreactlibrary/events/BridgeLibraryEventTests.java +17 -0
- package/android/src/test/java/com/fidelreactlibrary/events/CardVerificationStartedObserverTests.java +49 -0
- package/android/src/test/java/com/fidelreactlibrary/events/ResultsObserverTests.java +38 -0
- package/android/src/test/java/com/fidelreactlibrary/fakes/CardSchemeAdapterStub.java +17 -6
- package/android/src/test/java/com/fidelreactlibrary/fakes/ConstantsProviderStub.java +2 -2
- package/android/src/test/java/com/fidelreactlibrary/fakes/CountryAdapterStub.java +25 -10
- package/android/src/test/java/com/fidelreactlibrary/fakes/{DataConverterStub.java → DataAdapterStub.java} +3 -3
- package/android/src/test/java/com/fidelreactlibrary/fakes/ProgramTypeAdapterStub.java +31 -0
- package/android/src/test/java/com/fidelreactlibrary/fakes/ReactContextMock.java +1 -1
- package/android/src/test/java/com/fidelreactlibrary/fakes/ReadableArrayStub.java +82 -0
- package/android/src/test/java/com/fidelreactlibrary/fakes/ReadableMapStub.java +175 -40
- package/android/src/test/java/com/fidelreactlibrary/fakes/VerificationConfigurationAdapterStub.java +13 -0
- package/fidel-react-native.podspec +1 -1
- package/index.js +71 -19
- package/ios/Adapters/CardSchemesAdapter.swift +13 -0
- package/ios/Adapters/ConsentDetailsAdapter.swift +19 -0
- package/ios/Adapters/EnrollmentResultAdapter.swift +28 -0
- package/ios/Adapters/ErrorResultAdapter.swift +71 -0
- package/ios/{FLRNImageAdapter.h → Adapters/FLRNImageFromRNAdapter.h} +2 -3
- package/ios/Adapters/FidelSetupAdapter.swift +89 -0
- package/ios/Adapters/FidelVerificationConfigurationAdapter.swift +19 -0
- package/ios/Adapters/VerificationResultAdapter.swift +17 -0
- package/ios/CardVerificationConfigurationProperties.swift +14 -0
- package/ios/Constants/CardSchemeConstants.swift +38 -0
- package/ios/Constants/CardVerificationChoiceConstants.swift +24 -0
- package/ios/Constants/CountryConstants.swift +47 -0
- package/ios/Constants/EnrollmentErrorTypeConstants.swift +25 -0
- package/ios/Constants/ErrorTypeConstants.swift +37 -0
- package/ios/Constants/ExportedConstantsProvider.swift +42 -0
- package/ios/Constants/ProgramTypeConstants.swift +30 -0
- package/ios/Constants/ResultTypeConstants.swift +35 -0
- package/ios/Constants/VerificationErrorTypeConstants.swift +29 -0
- package/ios/Events/BridgeLibraryEvent.swift +14 -0
- package/ios/Events/CardVerificationChoiceSelectedObserver.swift +23 -0
- package/ios/Events/CardVerificationStartedObserver.swift +21 -0
- package/ios/Events/EventObserver.swift +13 -0
- package/ios/Events/JSResultProperties.swift +15 -0
- package/ios/Events/JSResultTypes.swift +14 -0
- package/ios/Events/ResultsObserver.swift +37 -0
- package/ios/FidelSetupProperties.swift +33 -0
- package/ios/NativeFidelBridge.m +11 -0
- package/ios/NativeFidelBridge.swift +93 -0
- package/package.json +1 -4
- package/android/src/main/java/com/fidelreactlibrary/adapters/FidelOptionsAdapter.java +0 -121
- package/android/src/main/java/com/fidelreactlibrary/adapters/WritableMapDataConverter.java +0 -94
- package/android/src/main/java/com/fidelreactlibrary/adapters/abstraction/DataConverter.java +0 -5
- package/android/src/main/java/com/fidelreactlibrary/events/CallbackActivityEventListener.java +0 -64
- package/android/src/main/java/com/fidelreactlibrary/events/CallbackInput.java +0 -7
- package/android/src/main/java/com/fidelreactlibrary/events/ErrorEventEmitter.java +0 -22
- package/android/src/test/java/com/fidelreactlibrary/CallbackActivityEventListenerTests.java +0 -133
- package/android/src/test/java/com/fidelreactlibrary/FidelCountryAdapterTests.java +0 -74
- package/android/src/test/java/com/fidelreactlibrary/FidelOptionsAdapterTests.java +0 -414
- package/android/src/test/java/com/fidelreactlibrary/FidelSetupAdapterTests.java +0 -65
- package/android/src/test/java/com/fidelreactlibrary/WritableMapDataConverterTests.java +0 -186
- package/android/src/test/java/com/fidelreactlibrary/fakes/CallbackInputSpy.java +0 -12
- package/android/src/test/java/com/fidelreactlibrary/fakes/CallbackSpy.java +0 -18
- package/android/src/test/java/com/fidelreactlibrary/fakes/IntentMock.java +0 -20
- package/ios/FLRNCardSchemesAdapter.h +0 -16
- package/ios/FLRNCardSchemesFromJSAdapter.h +0 -14
- package/ios/FLRNCardSchemesFromJSAdapter.m +0 -39
- package/ios/FLRNConstantsProvider.h +0 -15
- package/ios/FLRNImageFromRNAdapter.h +0 -14
- package/ios/FLRNObjectToDictionaryAdapter.h +0 -15
- package/ios/FLRNOptionsAdapter.h +0 -24
- package/ios/FLRNOptionsAdapter.m +0 -133
- package/ios/FLRNRuntimeObjectToDictionaryAdapter.h +0 -14
- package/ios/FLRNRuntimeObjectToDictionaryAdapter.m +0 -36
- package/ios/FLRNSDKOptions.h +0 -24
- package/ios/FLRNSDKSetupOptions.h +0 -14
- package/ios/FLRNSetupAdapter.h +0 -17
- package/ios/FLRNSetupAdapter.m +0 -50
- package/ios/Fidel.h +0 -20
- package/ios/Fidel.m +0 -79
- package/ios/RCTConvert+CardScheme.h +0 -33
- package/ios/RCTConvert+Options.h +0 -52
- package/ios/RCTConvert+Options.m +0 -21
- /package/ios/{FLRNImageFromRNAdapter.m → Adapters/FLRNImageFromRNAdapter.m} +0 -0
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
package com.fidelreactlibrary.adapters;
|
|
2
|
-
|
|
3
|
-
import android.graphics.Bitmap;
|
|
4
|
-
|
|
5
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
6
|
-
import com.fidel.sdk.Fidel;
|
|
7
|
-
import com.fidelreactlibrary.adapters.abstraction.CardSchemesAdapter;
|
|
8
|
-
import com.fidelreactlibrary.adapters.abstraction.ConstantsProvider;
|
|
9
|
-
import com.fidelreactlibrary.adapters.abstraction.CountryAdapter;
|
|
10
|
-
import com.fidelreactlibrary.adapters.abstraction.DataOutput;
|
|
11
|
-
import com.fidelreactlibrary.adapters.abstraction.DataProcessor;
|
|
12
|
-
|
|
13
|
-
import org.json.JSONObject;
|
|
14
|
-
|
|
15
|
-
import java.util.Arrays;
|
|
16
|
-
import java.util.Collections;
|
|
17
|
-
import java.util.List;
|
|
18
|
-
import java.util.Map;
|
|
19
|
-
|
|
20
|
-
import javax.annotation.Nonnull;
|
|
21
|
-
|
|
22
|
-
public final class FidelOptionsAdapter implements DataProcessor<ReadableMap>, DataOutput<Bitmap>, ConstantsProvider {
|
|
23
|
-
|
|
24
|
-
public static final String BANNER_IMAGE_KEY = "bannerImage";
|
|
25
|
-
public static final String AUTO_SCAN_KEY = "autoScan";
|
|
26
|
-
public static final String COMPANY_NAME_KEY = "companyName";
|
|
27
|
-
public static final String PROGRAM_NAME_KEY = "programName";
|
|
28
|
-
public static final String DELETE_INSTRUCTIONS_KEY = "deleteInstructions";
|
|
29
|
-
public static final String PRIVACY_URL_KEY = "privacyUrl";
|
|
30
|
-
public static final String TERMS_CONDITIONS_URL_KEY = "termsConditionsUrl";
|
|
31
|
-
public static final String META_DATA_KEY = "metaData";
|
|
32
|
-
public static final String ALLOWED_COUNTRIES_KEY = "allowedCountries";
|
|
33
|
-
public static final String DEFAULT_SELECTED_COUNTRY_KEY = "defaultSelectedCountry";
|
|
34
|
-
public static final String CARD_SCHEMES_KEY = "supportedCardSchemes";
|
|
35
|
-
public static final List<String> OPTION_KEYS = Collections.unmodifiableList(
|
|
36
|
-
Arrays.asList(
|
|
37
|
-
BANNER_IMAGE_KEY,
|
|
38
|
-
AUTO_SCAN_KEY,
|
|
39
|
-
COMPANY_NAME_KEY,
|
|
40
|
-
PROGRAM_NAME_KEY,
|
|
41
|
-
DELETE_INSTRUCTIONS_KEY,
|
|
42
|
-
PRIVACY_URL_KEY,
|
|
43
|
-
TERMS_CONDITIONS_URL_KEY,
|
|
44
|
-
META_DATA_KEY,
|
|
45
|
-
ALLOWED_COUNTRIES_KEY,
|
|
46
|
-
CARD_SCHEMES_KEY
|
|
47
|
-
));
|
|
48
|
-
|
|
49
|
-
private final DataProcessor<ReadableMap> imageAdapter;
|
|
50
|
-
private final CountryAdapter countryAdapter;
|
|
51
|
-
private final CardSchemesAdapter cardSchemesAdapter;
|
|
52
|
-
|
|
53
|
-
public FidelOptionsAdapter(DataProcessor<ReadableMap> imageAdapter,
|
|
54
|
-
CountryAdapter countryAdapter,
|
|
55
|
-
CardSchemesAdapter cardSchemesAdapter) {
|
|
56
|
-
this.imageAdapter = imageAdapter;
|
|
57
|
-
this.countryAdapter = countryAdapter;
|
|
58
|
-
this.cardSchemesAdapter = cardSchemesAdapter;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
@Override
|
|
62
|
-
public void process(ReadableMap data) {
|
|
63
|
-
if (valueIsValidFor(data, BANNER_IMAGE_KEY)) {
|
|
64
|
-
imageAdapter.process(data.getMap(BANNER_IMAGE_KEY));
|
|
65
|
-
}
|
|
66
|
-
if (valueIsValidFor(data, AUTO_SCAN_KEY)) {
|
|
67
|
-
Fidel.autoScan = data.getBoolean(AUTO_SCAN_KEY);
|
|
68
|
-
}
|
|
69
|
-
if (valueIsValidFor(data, COMPANY_NAME_KEY)) {
|
|
70
|
-
Fidel.companyName = data.getString(COMPANY_NAME_KEY);
|
|
71
|
-
}
|
|
72
|
-
if (valueIsValidFor(data, PROGRAM_NAME_KEY)) {
|
|
73
|
-
Fidel.programName = data.getString(PROGRAM_NAME_KEY);
|
|
74
|
-
}
|
|
75
|
-
if (valueIsValidFor(data, DELETE_INSTRUCTIONS_KEY)) {
|
|
76
|
-
Fidel.deleteInstructions = data.getString(DELETE_INSTRUCTIONS_KEY);
|
|
77
|
-
}
|
|
78
|
-
if (valueIsValidFor(data, PRIVACY_URL_KEY)) {
|
|
79
|
-
Fidel.privacyURL = data.getString(PRIVACY_URL_KEY);
|
|
80
|
-
}
|
|
81
|
-
if (valueIsValidFor(data, TERMS_CONDITIONS_URL_KEY)) {
|
|
82
|
-
Fidel.termsConditionsURL = data.getString(TERMS_CONDITIONS_URL_KEY);
|
|
83
|
-
}
|
|
84
|
-
if (valueIsValidFor(data, META_DATA_KEY)) {
|
|
85
|
-
ReadableMap metaDataMap = data.getMap(META_DATA_KEY);
|
|
86
|
-
if (metaDataMap != null) {
|
|
87
|
-
Fidel.metaData = getJSONWithMap(metaDataMap);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (valueIsValidFor(data, ALLOWED_COUNTRIES_KEY)) {
|
|
91
|
-
Fidel.allowedCountries = countryAdapter.parseAllowedCountries(data.getArray(ALLOWED_COUNTRIES_KEY));
|
|
92
|
-
}
|
|
93
|
-
if (valueIsValidFor(data, DEFAULT_SELECTED_COUNTRY_KEY)) {
|
|
94
|
-
Fidel.defaultSelectedCountry = countryAdapter.countryWithInteger(data.getInt(DEFAULT_SELECTED_COUNTRY_KEY));
|
|
95
|
-
}
|
|
96
|
-
if (data.hasKey(CARD_SCHEMES_KEY)) {
|
|
97
|
-
Fidel.supportedCardSchemes = cardSchemesAdapter.cardSchemesWithReadableArray(data.getArray(CARD_SCHEMES_KEY));
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
private JSONObject getJSONWithMap(ReadableMap metaDataMap) {
|
|
102
|
-
return new JSONObject(metaDataMap.toHashMap());
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private boolean valueIsValidFor(ReadableMap map, String key) {
|
|
106
|
-
return (map.hasKey(key) && !map.isNull(key));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
@Override
|
|
110
|
-
public void output(Bitmap data) {
|
|
111
|
-
Fidel.bannerImage = data;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
@Nonnull
|
|
115
|
-
@Override
|
|
116
|
-
public Map<String, Object> getConstants() {
|
|
117
|
-
Map<String, Object> constants = countryAdapter.getConstants();
|
|
118
|
-
constants.putAll(cardSchemesAdapter.getConstants());
|
|
119
|
-
return constants;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
package com.fidelreactlibrary.adapters;
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.WritableMap;
|
|
4
|
-
import com.fidel.sdk.LinkResultErrorCode;
|
|
5
|
-
import com.fidelreactlibrary.adapters.abstraction.DataConverter;
|
|
6
|
-
import com.fidelreactlibrary.adapters.abstraction.ObjectFactory;
|
|
7
|
-
|
|
8
|
-
import org.json.JSONException;
|
|
9
|
-
import org.json.JSONObject;
|
|
10
|
-
|
|
11
|
-
import java.lang.reflect.Field;
|
|
12
|
-
import java.util.Iterator;
|
|
13
|
-
|
|
14
|
-
public final class WritableMapDataConverter implements DataConverter<Object, WritableMap> {
|
|
15
|
-
|
|
16
|
-
private final ObjectFactory<WritableMap> writableMapFactory;
|
|
17
|
-
public WritableMapDataConverter(ObjectFactory<WritableMap> writableMapFactory) {
|
|
18
|
-
this.writableMapFactory = writableMapFactory;
|
|
19
|
-
}
|
|
20
|
-
@Override
|
|
21
|
-
public WritableMap getConvertedDataFor(Object data) {
|
|
22
|
-
if (data == null) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
WritableMap map = writableMapFactory.create();
|
|
26
|
-
|
|
27
|
-
for (Field field: data.getClass().getDeclaredFields()) {
|
|
28
|
-
if (field.getType() == String.class) {
|
|
29
|
-
try {
|
|
30
|
-
map.putString(field.getName(), (String) field.get(data));
|
|
31
|
-
} catch (Exception e) {
|
|
32
|
-
map.putNull(field.getName());
|
|
33
|
-
}
|
|
34
|
-
} else if (field.getType() == boolean.class || field.getType() == Boolean.class) {
|
|
35
|
-
try {
|
|
36
|
-
map.putBoolean(field.getName(), field.getBoolean(data));
|
|
37
|
-
} catch (Exception e) {
|
|
38
|
-
map.putBoolean(field.getName(), false);
|
|
39
|
-
}
|
|
40
|
-
} else if (field.getType() == int.class) {
|
|
41
|
-
try {
|
|
42
|
-
map.putInt(field.getName(), field.getInt(data));
|
|
43
|
-
} catch (Exception e) {
|
|
44
|
-
map.putInt(field.getName(), -1);
|
|
45
|
-
}
|
|
46
|
-
} else if (field.getType() == LinkResultErrorCode.class) {
|
|
47
|
-
String displayFieldName = field.getName().equals("errorCode") ? "code" : field.getName();
|
|
48
|
-
try {
|
|
49
|
-
LinkResultErrorCode errorCode = (LinkResultErrorCode)field.get(data);
|
|
50
|
-
map.putString(displayFieldName, errorCode.toString().toLowerCase());
|
|
51
|
-
} catch (Exception e) {
|
|
52
|
-
map.putNull(displayFieldName);
|
|
53
|
-
}
|
|
54
|
-
} else if (field.getType() == JSONObject.class) {
|
|
55
|
-
try {
|
|
56
|
-
WritableMap mapToPut = this.getMapFor((JSONObject)field.get(data));
|
|
57
|
-
map.putMap(field.getName(), mapToPut);
|
|
58
|
-
} catch (Exception e) {
|
|
59
|
-
map.putNull(field.getName());
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return map;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private WritableMap getMapFor(JSONObject json) {
|
|
67
|
-
Iterator<String> jsonKeyIterator = json.keys();
|
|
68
|
-
WritableMap map = writableMapFactory.create();
|
|
69
|
-
while (jsonKeyIterator.hasNext()) {
|
|
70
|
-
String key = jsonKeyIterator.next();
|
|
71
|
-
try {
|
|
72
|
-
Object value = json.get(key);
|
|
73
|
-
Class<?> valueClass = value.getClass();
|
|
74
|
-
if (valueClass == String.class) {
|
|
75
|
-
map.putString(key, (String)value);
|
|
76
|
-
}
|
|
77
|
-
else if (valueClass == Boolean.class) {
|
|
78
|
-
map.putBoolean(key, (boolean)value);
|
|
79
|
-
}
|
|
80
|
-
else if (valueClass == Integer.class) {
|
|
81
|
-
map.putInt(key, (int)value);
|
|
82
|
-
}
|
|
83
|
-
else if (valueClass == JSONObject.class) {
|
|
84
|
-
WritableMap mapToPut = this.getMapFor((JSONObject)value);
|
|
85
|
-
map.putMap(key, mapToPut);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
catch (JSONException e) {
|
|
89
|
-
e.printStackTrace();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return map;
|
|
93
|
-
}
|
|
94
|
-
}
|
package/android/src/main/java/com/fidelreactlibrary/events/CallbackActivityEventListener.java
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
package com.fidelreactlibrary.events;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.content.Intent;
|
|
5
|
-
|
|
6
|
-
import com.facebook.react.bridge.BaseActivityEventListener;
|
|
7
|
-
import com.facebook.react.bridge.Callback;
|
|
8
|
-
import com.facebook.react.bridge.WritableMap;
|
|
9
|
-
import com.fidel.sdk.Fidel;
|
|
10
|
-
import com.fidel.sdk.LinkResult;
|
|
11
|
-
import com.fidel.sdk.LinkResultError;
|
|
12
|
-
import com.fidelreactlibrary.adapters.abstraction.DataConverter;
|
|
13
|
-
import com.fidelreactlibrary.adapters.abstraction.DataProcessor;
|
|
14
|
-
import com.fidel.sdk.data.abstraction.FidelCardLinkingObserver;
|
|
15
|
-
|
|
16
|
-
public final class CallbackActivityEventListener
|
|
17
|
-
extends BaseActivityEventListener
|
|
18
|
-
implements CallbackInput, FidelCardLinkingObserver {
|
|
19
|
-
|
|
20
|
-
private final DataConverter<Object, WritableMap> linkResultConverter;
|
|
21
|
-
private final DataProcessor<WritableMap> errorHandler;
|
|
22
|
-
private Callback callback;
|
|
23
|
-
|
|
24
|
-
public CallbackActivityEventListener(DataConverter<Object, WritableMap> linkResultConverter,
|
|
25
|
-
DataProcessor<WritableMap> errorHandler) {
|
|
26
|
-
this.linkResultConverter = linkResultConverter;
|
|
27
|
-
this.errorHandler = errorHandler;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@Override
|
|
31
|
-
public void onActivityResult(Activity activity,
|
|
32
|
-
int requestCode,
|
|
33
|
-
int resultCode,
|
|
34
|
-
Intent data) {
|
|
35
|
-
super.onActivityResult(activity, requestCode, resultCode, data);
|
|
36
|
-
if (requestCode == Fidel.FIDEL_LINK_CARD_REQUEST_CODE) {
|
|
37
|
-
LinkResult result = data.getParcelableExtra(Fidel.FIDEL_LINK_CARD_RESULT_CARD);
|
|
38
|
-
LinkResultError error = result.getError();
|
|
39
|
-
if (error == null) {
|
|
40
|
-
WritableMap convertedLinkResult = linkResultConverter.getConvertedDataFor(result);
|
|
41
|
-
callback.invoke(null, convertedLinkResult);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
WritableMap convertedError = linkResultConverter.getConvertedDataFor(error);
|
|
45
|
-
errorHandler.process(convertedError);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
@Override
|
|
51
|
-
public void callbackIsReady(Callback callback) {
|
|
52
|
-
this.callback = callback;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
@Override
|
|
56
|
-
public void onCardLinkingFailed(LinkResultError linkResultError) {
|
|
57
|
-
WritableMap convertedError = linkResultConverter.getConvertedDataFor(linkResultError);
|
|
58
|
-
errorHandler.process(convertedError);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
@Override
|
|
62
|
-
public void onCardLinkingSucceeded(LinkResult linkResult) {
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
package com.fidelreactlibrary.events;
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
4
|
-
import com.facebook.react.bridge.WritableMap;
|
|
5
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;
|
|
6
|
-
import com.fidelreactlibrary.adapters.abstraction.DataProcessor;
|
|
7
|
-
|
|
8
|
-
public final class ErrorEventEmitter implements DataProcessor<WritableMap> {
|
|
9
|
-
|
|
10
|
-
private ReactApplicationContext reactContext;
|
|
11
|
-
|
|
12
|
-
public ErrorEventEmitter(ReactApplicationContext reactContext) {
|
|
13
|
-
this.reactContext = reactContext;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
@Override
|
|
17
|
-
public void process(WritableMap data) {
|
|
18
|
-
reactContext
|
|
19
|
-
.getJSModule(RCTDeviceEventEmitter.class)
|
|
20
|
-
.emit("CardLinkFailed", data);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
package com.fidelreactlibrary;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
|
|
5
|
-
import com.facebook.react.bridge.JavaOnlyMap;
|
|
6
|
-
import com.facebook.react.bridge.WritableMap;
|
|
7
|
-
import com.fidel.sdk.Fidel;
|
|
8
|
-
import com.fidel.sdk.LinkResult;
|
|
9
|
-
import com.fidel.sdk.LinkResultError;
|
|
10
|
-
import com.fidel.sdk.LinkResultErrorCode;
|
|
11
|
-
import com.fidelreactlibrary.events.CallbackActivityEventListener;
|
|
12
|
-
import com.fidelreactlibrary.fakes.CallbackSpy;
|
|
13
|
-
import com.fidelreactlibrary.fakes.DataConverterStub;
|
|
14
|
-
import com.fidelreactlibrary.fakes.DataProcessorSpy;
|
|
15
|
-
import com.fidelreactlibrary.fakes.IntentMock;
|
|
16
|
-
|
|
17
|
-
import org.junit.After;
|
|
18
|
-
import org.junit.Before;
|
|
19
|
-
import org.junit.Test;
|
|
20
|
-
import org.junit.runner.RunWith;
|
|
21
|
-
import org.robolectric.Robolectric;
|
|
22
|
-
import org.robolectric.RobolectricTestRunner;
|
|
23
|
-
|
|
24
|
-
import static org.junit.Assert.*;
|
|
25
|
-
|
|
26
|
-
@RunWith(RobolectricTestRunner.class)
|
|
27
|
-
public class CallbackActivityEventListenerTests {
|
|
28
|
-
|
|
29
|
-
private CallbackActivityEventListener sut;
|
|
30
|
-
private CallbackSpy callbackSpy;
|
|
31
|
-
private DataConverterStub<Object, WritableMap> linkResultConverterStub;
|
|
32
|
-
private Activity activity;
|
|
33
|
-
private IntentMock<LinkResult> intent;
|
|
34
|
-
private DataProcessorSpy<WritableMap> errorHandlerSpy;
|
|
35
|
-
|
|
36
|
-
private static final String RESULT_EXTRA_KEY = Fidel.FIDEL_LINK_CARD_RESULT_CARD;
|
|
37
|
-
private static final int REQUEST_CODE = Fidel.FIDEL_LINK_CARD_REQUEST_CODE;
|
|
38
|
-
private static final LinkResultError testLinkResultError
|
|
39
|
-
= new LinkResultError(LinkResultErrorCode.INVALID_URL, "Test message", "some date");
|
|
40
|
-
private static final LinkResult testLinkResult = new LinkResult("TEST CARD ID");
|
|
41
|
-
|
|
42
|
-
@Before
|
|
43
|
-
public final void setUp() {
|
|
44
|
-
linkResultConverterStub = new DataConverterStub<>();
|
|
45
|
-
errorHandlerSpy = new DataProcessorSpy<>();
|
|
46
|
-
sut = new CallbackActivityEventListener(linkResultConverterStub, errorHandlerSpy);
|
|
47
|
-
callbackSpy = new CallbackSpy();
|
|
48
|
-
sut.callbackIsReady(callbackSpy);
|
|
49
|
-
|
|
50
|
-
activity = Robolectric.buildActivity(Activity.class).setup().get();
|
|
51
|
-
intent = new IntentMock<>(activity, Activity.class);
|
|
52
|
-
intent.parcelableExtraToReturn = testLinkResult;
|
|
53
|
-
linkResultConverterStub.convertedDataToReturn = new JavaOnlyMap();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@After
|
|
57
|
-
public final void tearDown() {
|
|
58
|
-
sut = null;
|
|
59
|
-
callbackSpy = null;
|
|
60
|
-
linkResultConverterStub = null;
|
|
61
|
-
activity = null;
|
|
62
|
-
intent = null;
|
|
63
|
-
errorHandlerSpy = null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
@Test
|
|
67
|
-
public void test_WhenReceivingLinkResult_SendItConvertedInCallback() {
|
|
68
|
-
sut.onActivityResult(activity, REQUEST_CODE, 0, intent);
|
|
69
|
-
|
|
70
|
-
assertEquals(RESULT_EXTRA_KEY, intent.parcelableExtraNameAskedFor);
|
|
71
|
-
assertTrue(callbackSpy.didInvoke);
|
|
72
|
-
assertEquals(linkResultConverterStub.convertedDataToReturn, callbackSpy.receivedResultMap);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
@Test
|
|
76
|
-
public void test_WhenReceivingLinkResultWithError_DontCallCallback() {
|
|
77
|
-
onActivityResultWithError();
|
|
78
|
-
assertFalse(callbackSpy.didInvoke);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
@Test
|
|
82
|
-
public void test_WhenReceivingLinkResultWithError_SendConvertedErrorToItsHandler() {
|
|
83
|
-
onActivityResultWithError();
|
|
84
|
-
linkResultConverterStub.convertedDataToReturn = new JavaOnlyMap();
|
|
85
|
-
assertEquals("When returning error it should be converted",
|
|
86
|
-
intent.parcelableExtraToReturn.getError(), linkResultConverterStub.dataReceived);
|
|
87
|
-
assertEquals("When returning error send converted error to it's handler",
|
|
88
|
-
linkResultConverterStub.convertedDataToReturn, errorHandlerSpy.dataToProcess);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
@Test
|
|
92
|
-
public void test_WhenRequestCodeIsNotFidelRequestCode_DontInvokeTheCallback() {
|
|
93
|
-
sut.onActivityResult(activity,0, 0, intent);
|
|
94
|
-
assertFalse(callbackSpy.didInvoke);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
@Test
|
|
98
|
-
public void test_WhenRequestCodeIsNotFidelRequestCode_DontAskForFidelExtras() {
|
|
99
|
-
sut.onActivityResult(activity,0, 0, intent);
|
|
100
|
-
assertNull(intent.parcelableExtraNameAskedFor);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
@Test
|
|
104
|
-
public void test_WhenCardLinkingFails_SendConvertedLinkResultToErrorHandler() {
|
|
105
|
-
sut.onCardLinkingFailed(testLinkResultError);
|
|
106
|
-
assertEquals(linkResultConverterStub.convertedDataToReturn, errorHandlerSpy.dataToProcess);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
@Test
|
|
110
|
-
public void test_WhenCardLinkingFails_ConvertTheErrorToWritableMap() {
|
|
111
|
-
sut.onCardLinkingFailed(testLinkResultError);
|
|
112
|
-
assertEquals(linkResultConverterStub.dataReceived, testLinkResultError);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
@Test
|
|
116
|
-
public void test_WhenCardLinkingSucceeds_DoNotCallErrorHandler() {
|
|
117
|
-
sut.onCardLinkingSucceeded(testLinkResult);
|
|
118
|
-
assertNull(errorHandlerSpy.dataToProcess);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
@Test
|
|
122
|
-
public void test_WhenCardLinkingSucceeds_DoNotCallCallback() {
|
|
123
|
-
sut.onCardLinkingSucceeded(testLinkResult);
|
|
124
|
-
assertNull(callbackSpy.receivedErrorMap);
|
|
125
|
-
assertNull(callbackSpy.receivedResultMap);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
private void onActivityResultWithError() {
|
|
129
|
-
LinkResultErrorCode errorCode = LinkResultErrorCode.USER_CANCELED;
|
|
130
|
-
intent.parcelableExtraToReturn = new LinkResult(errorCode, "Test error message", "2021-05-19T12:37:55.278Z");
|
|
131
|
-
sut.onActivityResult(activity, REQUEST_CODE, 0, intent);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
package com.fidelreactlibrary;
|
|
2
|
-
|
|
3
|
-
import com.fidel.sdk.Fidel.Country;
|
|
4
|
-
import com.fidelreactlibrary.adapters.FidelCountryAdapter;
|
|
5
|
-
|
|
6
|
-
import org.junit.After;
|
|
7
|
-
import org.junit.Before;
|
|
8
|
-
import org.junit.Test;
|
|
9
|
-
|
|
10
|
-
import java.util.Map;
|
|
11
|
-
|
|
12
|
-
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
|
13
|
-
import static org.junit.Assert.assertEquals;
|
|
14
|
-
import static org.junit.Assert.assertNotEquals;
|
|
15
|
-
import static org.junit.Assert.assertNotNull;
|
|
16
|
-
import static org.junit.Assert.assertNull;
|
|
17
|
-
import static org.junit.Assert.assertThat;
|
|
18
|
-
|
|
19
|
-
public class FidelCountryAdapterTests {
|
|
20
|
-
|
|
21
|
-
private static final String COUNTRIES_KEY = "Country";
|
|
22
|
-
|
|
23
|
-
private FidelCountryAdapter sut;
|
|
24
|
-
|
|
25
|
-
@Before
|
|
26
|
-
public final void setUp() {
|
|
27
|
-
sut = new FidelCountryAdapter();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@After
|
|
31
|
-
public final void tearDown() {
|
|
32
|
-
sut = null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@Test
|
|
36
|
-
public void test_ToExposeCountryConstants() {
|
|
37
|
-
Map<String, Object> exposedConstants = sut.getConstants();
|
|
38
|
-
assertThat(exposedConstants.keySet(), hasItem(COUNTRIES_KEY));
|
|
39
|
-
Map<String, Integer> countriesMap = (Map<String, Integer>)exposedConstants.get(COUNTRIES_KEY);
|
|
40
|
-
assertNotNull(countriesMap);
|
|
41
|
-
for (Country country : Country.values()) {
|
|
42
|
-
String countryKey = sut.keyFor(country);
|
|
43
|
-
assertCorrectCountryValueFor(countryKey, country, countriesMap);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
@Test
|
|
48
|
-
public void test_WhenAskedForKeyForCountry_ItProvidesIt() {
|
|
49
|
-
for (Country country : Country.values()) {
|
|
50
|
-
assertNotNull(sut.keyFor(country));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
@Test
|
|
55
|
-
public void test_WhenCountryOrdinalNumberIsTooHigh_ReturnNullCountry() {
|
|
56
|
-
assertNull(sut.countryWithInteger(1239));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
@Test
|
|
60
|
-
public void test_WhenCountryOrdinalNumberIsValid_ReturnCountryFromThatOrdinalNumber() {
|
|
61
|
-
Country[] countries = Country.values();
|
|
62
|
-
for (int countryIndex = 0; countryIndex < countries.length; countryIndex++) {
|
|
63
|
-
assertEquals(sut.countryWithInteger(countryIndex), countries[countryIndex]);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
private void assertCorrectCountryValueFor(String key,
|
|
68
|
-
Country countryValue,
|
|
69
|
-
Map<String, Integer> map) {
|
|
70
|
-
assertNotEquals(key, "notFound");
|
|
71
|
-
assertThat(map.keySet(), hasItem(key));
|
|
72
|
-
assertEquals(map.get(key).intValue(), countryValue.ordinal());
|
|
73
|
-
}
|
|
74
|
-
}
|