fidel-react-native 1.5.0 → 1.6.2

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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # Fidel React Native bridge library change log
2
2
 
3
+ ## 1.6.2
4
+ - Update Fidel API logo
5
+
6
+ ## 1.6.1
7
+ - Always provide the `scheme` field in Android, after successful card enrollments.
8
+ - Provide support for `resConfigs` optimization parameter in Android.
9
+
10
+ ## 1.6.0
11
+ - Added the `defaultSelectedCountry` property which sets the country that will be selected by default, when opening the card enrollment screen.
12
+
3
13
  ## 1.5.0
4
14
  - Remove card scanning confirmation screen.
5
15
 
package/README.md CHANGED
@@ -81,6 +81,7 @@ const countries = [Fidel.Country.ireland, Fidel.Country.unitedStates];
81
81
  Fidel.setOptions({
82
82
  bannerImage: resolvedImage,
83
83
  allowedCountries: countries,
84
+ defaultSelectedCountry: Fidel.Country.unitedStates,
84
85
  supportedCardSchemes: Array.from(cardSchemes),
85
86
  autoScan: false,
86
87
  metaData: {'meta-data-1': 'value1'}, // additional data to pass with the card
@@ -183,6 +184,18 @@ Fidel.setOptions({
183
184
 
184
185
  The possible options are: `.canada`, `.ireland`, `.japan`, `.sweden`, `.unitedArabEmirates`, `.unitedKingdom`, `.unitedStates`. You can set one or multiple of these countries. If you don't set any allowed countries, the user will be able to choose any of the countries above. If you set only one country, the card linking screen will not show the country picker UI. Note that, when you set multiple countries, they will be displayed in the country picker UI in the order that you set them.
185
186
 
187
+ ### defaultSelectedCountry
188
+
189
+ Use this parameter to set the country that will be selected by default when opening the card enrollment screen.
190
+
191
+ ```javascript
192
+ Fidel.setOptions({
193
+ defaultSelectedCountry: Fidel.Country.unitedKingdom
194
+ });
195
+ ```
196
+
197
+ The possible options are: `.canada`, `.ireland`, `.japan`, `.sweden`, `.unitedArabEmirates`, `.unitedKingdom`, `.unitedStates`. The `defaultSelectedCountry` has to be part of the `allowedCountries` list. The default value of this option is `.unitedKingdom`.
198
+
186
199
  ### supportedCardSchemes
187
200
 
188
201
  We currently support _Visa_, _Mastercard_ and _AmericanExpress_, but you can choose to support only one, two or all three. By default the SDK is configured to support all three.
@@ -1,7 +1,7 @@
1
1
 
2
2
  buildscript {
3
3
  repositories {
4
- jcenter()
4
+ mavenCentral()
5
5
  }
6
6
 
7
7
  dependencies {
@@ -20,7 +20,7 @@ android {
20
20
  minSdkVersion 21
21
21
  targetSdkVersion 30
22
22
  versionCode 1
23
- versionName "1.5.0"
23
+ versionName "1.6.2"
24
24
  }
25
25
  lintOptions {
26
26
  abortOnError false
@@ -39,10 +39,10 @@ repositories {
39
39
 
40
40
  dependencies {
41
41
  implementation 'com.facebook.react:react-native:+'
42
- implementation 'com.github.FidelLimited:android-sdk:1.6.0'
42
+ implementation 'com.github.FidelLimited:android-sdk:1.7.2'
43
43
 
44
44
  testImplementation 'junit:junit:4.13.2'
45
- testImplementation 'androidx.test.ext:junit:1.1.2'
45
+ testImplementation 'androidx.test.ext:junit:1.1.3'
46
46
  testImplementation 'org.assertj:assertj-core:3.13.2'
47
47
  testImplementation 'org.robolectric:robolectric:4.5.1'
48
48
  }
@@ -30,6 +30,7 @@ public final class FidelOptionsAdapter implements DataProcessor<ReadableMap>, Da
30
30
  public static final String TERMS_CONDITIONS_URL_KEY = "termsConditionsUrl";
31
31
  public static final String META_DATA_KEY = "metaData";
32
32
  public static final String ALLOWED_COUNTRIES_KEY = "allowedCountries";
33
+ public static final String DEFAULT_SELECTED_COUNTRY_KEY = "defaultSelectedCountry";
33
34
  public static final String CARD_SCHEMES_KEY = "supportedCardSchemes";
34
35
  public static final List<String> OPTION_KEYS = Collections.unmodifiableList(
35
36
  Arrays.asList(
@@ -89,6 +90,9 @@ public final class FidelOptionsAdapter implements DataProcessor<ReadableMap>, Da
89
90
  if (valueIsValidFor(data, ALLOWED_COUNTRIES_KEY)) {
90
91
  Fidel.allowedCountries = countryAdapter.parseAllowedCountries(data.getArray(ALLOWED_COUNTRIES_KEY));
91
92
  }
93
+ if (valueIsValidFor(data, DEFAULT_SELECTED_COUNTRY_KEY)) {
94
+ Fidel.defaultSelectedCountry = countryAdapter.countryWithInteger(data.getInt(DEFAULT_SELECTED_COUNTRY_KEY));
95
+ }
92
96
  if (data.hasKey(CARD_SCHEMES_KEY)) {
93
97
  Fidel.supportedCardSchemes = cardSchemesAdapter.cardSchemesWithReadableArray(data.getArray(CARD_SCHEMES_KEY));
94
98
  }
@@ -1,7 +1,6 @@
1
1
  package com.fidelreactlibrary.adapters;
2
2
 
3
3
  import com.facebook.react.bridge.WritableMap;
4
- import com.fidel.sdk.LinkResultError;
5
4
  import com.fidel.sdk.LinkResultErrorCode;
6
5
  import com.fidelreactlibrary.adapters.abstraction.DataConverter;
7
6
  import com.fidelreactlibrary.adapters.abstraction.ObjectFactory;
@@ -14,7 +13,7 @@ import java.util.Iterator;
14
13
 
15
14
  public final class WritableMapDataConverter implements DataConverter<Object, WritableMap> {
16
15
 
17
- private ObjectFactory<WritableMap> writableMapFactory;
16
+ private final ObjectFactory<WritableMap> writableMapFactory;
18
17
  public WritableMapDataConverter(ObjectFactory<WritableMap> writableMapFactory) {
19
18
  this.writableMapFactory = writableMapFactory;
20
19
  }
@@ -24,32 +23,44 @@ public final class WritableMapDataConverter implements DataConverter<Object, Wri
24
23
  return null;
25
24
  }
26
25
  WritableMap map = writableMapFactory.create();
27
- try {
28
- for (Field field: data.getClass().getDeclaredFields()) {
29
- if (field.getType() == String.class) {
30
- map.putString(field.getName(), (String)field.get(data));
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());
31
33
  }
32
- else if (field.getType() == boolean.class || field.getType() == Boolean.class) {
33
- map.putBoolean(field.getName(), (boolean)field.get(data));
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);
34
39
  }
35
- else if (field.getType() == int.class) {
36
- map.putInt(field.getName(), (int)field.get(data));
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);
37
45
  }
38
- else if (field.getType() == LinkResultErrorCode.class) {
46
+ } else if (field.getType() == LinkResultErrorCode.class) {
47
+ String displayFieldName = field.getName().equals("errorCode") ? "code" : field.getName();
48
+ try {
39
49
  LinkResultErrorCode errorCode = (LinkResultErrorCode)field.get(data);
40
- String displayFieldName = field.getName() == "errorCode" ? "code" : field.getName();
41
50
  map.putString(displayFieldName, errorCode.toString().toLowerCase());
51
+ } catch (Exception e) {
52
+ map.putNull(displayFieldName);
42
53
  }
43
- else if (field.getType() == JSONObject.class) {
54
+ } else if (field.getType() == JSONObject.class) {
55
+ try {
44
56
  WritableMap mapToPut = this.getMapFor((JSONObject)field.get(data));
45
57
  map.putMap(field.getName(), mapToPut);
58
+ } catch (Exception e) {
59
+ map.putNull(field.getName());
46
60
  }
47
61
  }
48
- return map;
49
- }
50
- catch (Exception e) {
51
- return map;
52
62
  }
63
+ return map;
53
64
  }
54
65
 
55
66
  private WritableMap getMapFor(JSONObject json) {
@@ -59,14 +70,14 @@ public final class WritableMapDataConverter implements DataConverter<Object, Wri
59
70
  String key = jsonKeyIterator.next();
60
71
  try {
61
72
  Object value = json.get(key);
62
- Class valueClass = value.getClass();
73
+ Class<?> valueClass = value.getClass();
63
74
  if (valueClass == String.class) {
64
75
  map.putString(key, (String)value);
65
76
  }
66
- else if (valueClass == boolean.class || valueClass == Boolean.class) {
77
+ else if (valueClass == Boolean.class) {
67
78
  map.putBoolean(key, (boolean)value);
68
79
  }
69
- else if (valueClass == int.class || valueClass == Integer.class) {
80
+ else if (valueClass == Integer.class) {
70
81
  map.putInt(key, (int)value);
71
82
  }
72
83
  else if (valueClass == JSONObject.class) {
@@ -53,6 +53,43 @@ public class WritableMapDataConverterTests {
53
53
  assertNull(sut.getConvertedDataFor(null));
54
54
  }
55
55
 
56
+ @Test
57
+ public void test_WhenExpectedNonNullStringFieldContainsNullValueInLinkResult_ReturnMapWithNullValueForIt() {
58
+ LinkResult linkResult = new LinkResult(TEST_CARD_ID);
59
+ setFieldsFor(linkResult);
60
+ linkResult.accountId = null;
61
+ WritableMap receivedMap = sut.getConvertedDataFor(linkResult);
62
+ assertNull(receivedMap.getString("accountId"));
63
+ }
64
+
65
+ @Test
66
+ public void test_WhenExpectedNonNullBooleanFieldContainsNullValueInLinkResult_ReturnMapWithFalseValueForIt() {
67
+ LinkResult linkResult = new LinkResult(TEST_CARD_ID);
68
+ setFieldsFor(linkResult);
69
+ linkResult.live = null;
70
+ WritableMap receivedMap = sut.getConvertedDataFor(linkResult);
71
+ assertFalse(receivedMap.getBoolean("live"));
72
+ }
73
+
74
+ @Test
75
+ public void test_WhenExpectedLinkResultWithNullMetaData_ReturnMapWithNullMetaData() {
76
+ LinkResult linkResult = new LinkResult(TEST_CARD_ID);
77
+ setFieldsFor(linkResult);
78
+ linkResult.metaData = null;
79
+ WritableMap receivedMap = sut.getConvertedDataFor(linkResult);
80
+ assertNull(receivedMap.getMap("metaData"));
81
+ }
82
+
83
+ @Test
84
+ public void test_WhenConvertingLinkResultWithError_AndErrorCodeIsUnknown_SetNullErrorCodeField() {
85
+ LinkResult linkResult = new LinkResult(null, TEST_ERROR_MESSAGE, "2021-05-19T12:37:55.278Z");
86
+ Object objectToConvert = linkResult.getError();
87
+
88
+ WritableMap receivedMap = sut.getConvertedDataFor(objectToConvert);
89
+ assertNotNull(receivedMap);
90
+ assertNull(receivedMap.getString("code"));
91
+ }
92
+
56
93
  @Test
57
94
  public void test_WhenConvertingValidLinkResult_IncludeAllObjectFields() throws IllegalAccessException {
58
95
  LinkResult linkResult = new LinkResult(TEST_CARD_ID);
@@ -98,7 +135,7 @@ public class WritableMapDataConverterTests {
98
135
  assertEquals(receivedString, field.get(objectToConvert));
99
136
  }
100
137
  else if (field.getType() == LinkResultErrorCode.class) {
101
- String displayFieldName = field.getName() == "errorCode" ? "code" : field.getName();
138
+ String displayFieldName = field.getName().equals("errorCode") ? "code" : field.getName();
102
139
  String receivedErrorCodeString = receivedMap.getString(displayFieldName);
103
140
  LinkResultErrorCode expectedErrorCode = (LinkResultErrorCode) field.get(objectToConvert);
104
141
  String expectedErrorCodeString = expectedErrorCode.toString().toLowerCase();
@@ -62,6 +62,11 @@ NSString *const kOptionKey = @"Option";
62
62
  FLFidel.objc_allowedCountries = (NSArray<NSNumber *> *) rawData;
63
63
  }
64
64
 
65
+ if ([self valueIsValidFor:kDefaultSelectedCountryOptionKey fromDictionary:options]) {
66
+ id rawData = options[kDefaultSelectedCountryOptionKey];
67
+ FLFidel.defaultSelectedCountry = [((NSNumber *) rawData) integerValue];
68
+ }
69
+
65
70
  if ([self valueIsValidFor:kAutoScanOptionKey fromDictionary:options]) {
66
71
  FLFidel.autoScan = [options[kAutoScanOptionKey] boolValue];
67
72
  }
@@ -10,14 +10,15 @@
10
10
 
11
11
  typedef NS_ENUM(NSUInteger, FLSDKOption) {
12
12
  FLSDKOptionBannerImage = 0,
13
- FLSDKOptionCountry = 1,
14
- FLSDKOptionAutoScan = 2,
15
- FLSDKOptionMetaData = 3,
16
- FLSDKOptionCompanyName = 4,
17
- FLSDKOptionProgramName = 5,
18
- FLSDKOptionDeleteInstructions = 6,
19
- FLSDKOptionPrivacyURL = 7,
20
- FLSDKOptionTermsConditionsURL = 8,
21
- FLSDKOptionCardSchemes = 9,
13
+ FLSDKOptionAllowedCountries = 1,
14
+ FLSDKOptionDefaultSelectedCountry = 2,
15
+ FLSDKOptionAutoScan = 3,
16
+ FLSDKOptionMetaData = 4,
17
+ FLSDKOptionCompanyName = 5,
18
+ FLSDKOptionProgramName = 6,
19
+ FLSDKOptionDeleteInstructions = 7,
20
+ FLSDKOptionPrivacyURL = 8,
21
+ FLSDKOptionTermsConditionsURL = 9,
22
+ FLSDKOptionCardSchemes = 10,
22
23
  FLSDKOptionUnexistent = NSUIntegerMax
23
24
  };
@@ -20,7 +20,8 @@
20
20
  #define FLSDKOptionValues\
21
21
  @{\
22
22
  kBannerImageOptionKey: @(FLSDKOptionBannerImage), \
23
- kAllowedCountriesOptionKey: @(FLSDKOptionCountry), \
23
+ kAllowedCountriesOptionKey: @(FLSDKOptionAllowedCountries), \
24
+ kDefaultSelectedCountryOptionKey: @(FLSDKOptionDefaultSelectedCountry), \
24
25
  kAutoScanOptionKey: @(FLSDKOptionAutoScan),\
25
26
  kMetaDataOptionKey: @(FLSDKOptionMetaData), \
26
27
  kCompanyNameOptionKey: @(FLSDKOptionCompanyName), \
@@ -33,6 +34,7 @@
33
34
 
34
35
  FOUNDATION_EXPORT NSString *const kBannerImageOptionKey;
35
36
  FOUNDATION_EXPORT NSString *const kAllowedCountriesOptionKey;
37
+ FOUNDATION_EXPORT NSString *const kDefaultSelectedCountryOptionKey;
36
38
  FOUNDATION_EXPORT NSString *const kAutoScanOptionKey;
37
39
  FOUNDATION_EXPORT NSString *const kMetaDataOptionKey;
38
40
  FOUNDATION_EXPORT NSString *const kCompanyNameOptionKey;
@@ -10,6 +10,7 @@
10
10
 
11
11
  NSString *const kBannerImageOptionKey = @"bannerImage";
12
12
  NSString *const kAllowedCountriesOptionKey = @"allowedCountries";
13
+ NSString *const kDefaultSelectedCountryOptionKey = @"defaultSelectedCountry";
13
14
  NSString *const kAutoScanOptionKey = @"autoScan";
14
15
  NSString *const kMetaDataOptionKey = @"metaData";
15
16
  NSString *const kCompanyNameOptionKey = @"companyName";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fidel-react-native",
3
- "version": "1.5.0",
3
+ "version": "1.6.2",
4
4
  "description": "Fidel's React Native bridge library for iOS and Android.",
5
5
  "main": "index.js",
6
6
  "nativePackage": true,
@@ -45,7 +45,8 @@
45
45
  },
46
46
  "homepage": "https://github.com/FidelLimited/rn-sdk#readme",
47
47
  "peerDependencies": {
48
- "react-native": "^0.41.2"
48
+ "react": "*",
49
+ "react-native": "*"
49
50
  },
50
51
  "dependencies": {}
51
52
  }