Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error messages android #4

Merged
merged 10 commits into from
Sep 12, 2023
27 changes: 12 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ export default function App() {
<TouchableOpacity style={styles.button} onPress={onPressPhotoMatch}>
<Text style={styles.text}>Open Photo Match</Text>
</TouchableOpacity>

<TouchableOpacity style={styles.button} onPress={onPressEnroll}>
<Text style={styles.text}>Open Enroll</Text>
</TouchableOpacity>
Expand Down Expand Up @@ -175,7 +174,6 @@ const styles = StyleSheet.create({
fontSize: 22,
},
});

```

<hr/>
Expand Down Expand Up @@ -259,13 +257,13 @@ This method must be used to **set** the **theme** of the Capface SDK screen.

Here must be passed to initialize the Capface SDK! Case the parameters isn't provided the Capface SDK goes to be not initialized.

| `CapfaceSdk.Params` | type | Required |
| ------------------- | -------- | -------- |
| `device` | `string` | ✅ |
| `url` | `string` | ✅ |
| `key` | `string` | ✅ |
| `productionKey` | `string` | ✅ |
| `isDeveloperMode` | `boolean`| ❌ |
| `CapfaceSdk.Params` | type | Required |
| ------------------- | --------- | -------- |
| `device` | `string` | ✅ |
| `url` | `string` | ✅ |
| `key` | `string` | ✅ |
| `productionKey` | `string` | ✅ |
| `isDeveloperMode` | `boolean` | ❌ |

### `CapfaceSdk.Headers`

Expand Down Expand Up @@ -427,14 +425,13 @@ This interface represents the all scan messages during to CapfaceSDK flow. It in

| `CapfaceSdk.Errors` | Description | iOS | Android |
| ------------------------------- | ------------------------------------------------------------------------------------ | --- | ------- |
| `FaceTecDoenstInitialized` | When some processors method is runned, but CapfaceSDK **wasn't initialized**. | ✅ | ✅ |
| `FaceTecWasntProcessed` | When the image sent to the processors cannot be processed due to inconsistency. | ✅ | ✅ |
| `CapFaceHasNotBeenInitialized` | When some processors method is runned, but CapfaceSDK **has not been initialized**. | ✅ | ✅ |
| `CapFaceValuesWereNotProcessed` | When the image sent to the processors cannot be processed due to inconsistency. | ✅ | ✅ |
| `HTTPSError` | When exists some network error. | ✅ | ✅ |
| `JSONError` | When exists some problem in getting data in request of **base URL** information. | ❌ | ✅ |
| `FaceTecDifferentStatus` | When session status is different completed successfully. | ❌ | ✅ |
| `FaceTecLivenessWasntProcessed` | When the image user sent to the processors cannot be processed due to inconsistency. | ❌ | ✅ |
| `FaceTecScanWasntProcessed` | When the image ID sent to the processors cannot be processed due to inconsistency. | ❌ | ✅ |
| `NoParametersProvided` | When parameters is not provided. | ❌ | ✅ |
| `CapFaceInvalidSession` | When session status is invalid. | ❌ | ✅ |
| `CapFaceLivenessWasntProcessed` | When the image user sent to the processors cannot be processed due to inconsistency. | ❌ | ✅ |
| `CapFaceScanWasntProcessed` | When the image ID sent to the processors cannot be processed due to inconsistency. | ❌ | ✅ |

<hr/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void processSessionWhileFaceTecSDKWaits(final FaceTecSessionResult sessio
NetworkingHelpers.cancelPendingRequests();
faceScanResultCallback.cancel();
capFaceModule.sendEvent("onCloseModal", false);
capFaceModule.processorPromise.reject("Status is not session completed successfully!", "FaceTecDifferentStatus");
capFaceModule.processorPromise.reject("The session status has not been completed!", "CapFaceInvalidSession");
return;
}

Expand Down Expand Up @@ -99,8 +99,8 @@ public void onResponse(@NonNull Call call, @NonNull okhttp3.Response response) t
} else {
faceScanResultCallback.cancel();
capFaceModule.sendEvent("onCloseModal", false);
capFaceModule.processorPromise.reject("FaceTec SDK wasn't have to values processed!",
"FaceTecWasntProcessed");
capFaceModule.processorPromise.reject("CapFace SDK values were not processed!",
"CapFaceValuesWereNotProcessed");
}
} catch (JSONException e) {
e.printStackTrace();
Expand Down
5 changes: 1 addition & 4 deletions android/src/main/java/com/capitual/processors/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ public static boolean hasConfig() {
&& ProductionKeyText != null;
}

public static void initializeFaceTecSDKFromAutogeneratedConfig(
Context context,
boolean isDeveloperMode,
FaceTecSDK.InitializeCallback callback) {
public static void initialize(Context context, boolean isDeveloperMode, FaceTecSDK.InitializeCallback callback) {
if (isDeveloperMode) {
FaceTecSDK.initializeInDevelopmentMode(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void processSessionWhileFaceTecSDKWaits(final FaceTecSessionResult sessio
NetworkingHelpers.cancelPendingRequests();
faceScanResultCallback.cancel();
capFaceModule.sendEvent("onCloseModal", false);
capFaceModule.processorPromise.reject("Status is not session completed successfully!", "FaceTecDifferentStatus");
capFaceModule.processorPromise.reject("The session status has not been completed!", "CapFaceInvalidSession");
return;
}

Expand Down Expand Up @@ -99,8 +99,8 @@ public void onResponse(@NonNull Call call, @NonNull okhttp3.Response response) t
} else {
faceScanResultCallback.cancel();
capFaceModule.sendEvent("onCloseModal", false);
capFaceModule.processorPromise.reject("FaceTec SDK wasn't have to values processed!",
"FaceTecWasntProcessed");
capFaceModule.processorPromise.reject("CapFace SDK values were not processed!",
"CapFaceValuesWereNotProcessed");
}
} catch (JSONException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void processSessionWhileFaceTecSDKWaits(final FaceTecSessionResult sessio
NetworkingHelpers.cancelPendingRequests();
faceScanResultCallback.cancel();
capFaceModule.sendEvent("onCloseModal", false);
capFaceModule.processorPromise.reject("Status is not session completed successfully!", "FaceTecDifferentStatus");
capFaceModule.processorPromise.reject("The session status has not been completed!", "CapFaceInvalidSession");
return;
}

Expand Down Expand Up @@ -97,8 +97,8 @@ public void onResponse(@NonNull Call call, @NonNull okhttp3.Response response) t
} else {
faceScanResultCallback.cancel();
capFaceModule.sendEvent("onCloseModal", false);
capFaceModule.processorPromise.reject("FaceTec SDK wasn't have to values processed!",
"FaceTecWasntProcessed");
capFaceModule.processorPromise.reject("CapFace SDK values were not processed!",
"CapFaceValuesWereNotProcessed");
}
} catch (JSONException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void processSessionWhileFaceTecSDKWaits(final FaceTecSessionResult sessio
NetworkingHelpers.cancelPendingRequests();
faceScanResultCallback.cancel();
capFaceModule.sendEvent("onCloseModal", false);
capFaceModule.processorPromise.reject("Status is not session completed successfully!", "FaceTecDifferentStatus");
capFaceModule.processorPromise.reject("The session status has not been completed!", "CapFaceInvalidSession");
return;
}

Expand Down Expand Up @@ -173,8 +173,8 @@ public void onResponse(@NonNull Call call, @NonNull okhttp3.Response response) t
} else {
faceScanResultCallback.cancel();
capFaceModule.sendEvent("onCloseModal", false);
capFaceModule.processorPromise.reject("FaceTec SDK wasn't have to liveness values processed!",
"FaceTecLivenessWasntProcessed");
capFaceModule.processorPromise.reject("CapFace SDK wasn't have to liveness values processed!",
"CapFaceLivenessWasntProcessed");
}
} catch (JSONException e) {
e.printStackTrace();
Expand Down Expand Up @@ -204,7 +204,7 @@ public void processIDScanWhileFaceTecSDKWaits(final FaceTecIDScanResult idScanRe
NetworkingHelpers.cancelPendingRequests();
idScanResultCallback.cancel();
capFaceModule.sendEvent("onCloseModal", false);
capFaceModule.processorPromise.reject("Status is not success!", "FaceTecDifferentStatus");
capFaceModule.processorPromise.reject("The scan status has not been completed!", "CapFaceInvalidSession");
return;
}

Expand Down Expand Up @@ -314,8 +314,8 @@ public void onResponse(@NonNull Call call, @NonNull okhttp3.Response response) t
} else {
idScanResultCallback.cancel();
capFaceModule.sendEvent("onCloseModal", false);
capFaceModule.processorPromise.reject("FaceTec SDK wasn't have to scan values processed!",
"FaceTecScanWasntProcessed");
capFaceModule.processorPromise.reject("CapFace SDK wasn't have to scan values processed!",
"CapFaceScanWasntProcessed");
}
} catch (JSONException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void processIDScanWhileFaceTecSDKWaits(final FaceTecIDScanResult idScanRe
NetworkingHelpers.cancelPendingRequests();
idScanResultCallback.cancel();
capFaceModule.sendEvent("onCloseModal", false);
capFaceModule.processorPromise.reject("Status is not success!", "FaceTecDifferentStatus");
capFaceModule.processorPromise.reject("The scan status has not been completed!", "CapFaceInvalidSession");
return;
}

Expand Down Expand Up @@ -231,8 +231,8 @@ public void onResponse(@NonNull Call call, @NonNull okhttp3.Response response) t
} else {
idScanResultCallback.cancel();
capFaceModule.sendEvent("onCloseModal", false);
capFaceModule.processorPromise.reject("FaceTec SDK wasn't have to values processed!",
"FaceTecWasntProcessed");
capFaceModule.processorPromise.reject("CapFace SDK values were not processed!",
"CapFaceValuesWereNotProcessed");
}
} catch (JSONException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,22 @@ private boolean isDeveloperMode(Map params) {
return false;
}

private void handleFaceTecSDKConfiguration(Map params, ReadableMap headers) {
private String getKeyValue(@NonNull Map object, String key) {
if (object.containsKey(key)) {
return object.get(key).toString();
}
return null;
}

private void handleCapFaceConfiguration(@NonNull Map params, ReadableMap headers) {
try {
Config.setDevice(params.get("device").toString());
Config.setUrl(params.get("url").toString());
Config.setKey(params.get("key").toString());
Config.setProductionKeyText(params.get("productionKey").toString());
Config.setDevice(getKeyValue(params, "device"));
Config.setUrl(getKeyValue(params, "url"));
Config.setKey(getKeyValue(params, "key"));
Config.setProductionKeyText(getKeyValue(params, "productionKey"));
Config.setHeaders(headers);
} catch (Exception error) {
Log.d("Capitual - SDK", "Error while setting FaceTecSDK configuration!");
Log.d("Capitual - SDK", "CapFace SDK Configuration doesn't exists!");
}
}

Expand All @@ -83,29 +90,20 @@ public void initializeSdk(ReadableMap params, ReadableMap headers, com.facebook.
return;
}

handleFaceTecSDKConfiguration(params.toHashMap(), headers);
handleCapFaceConfiguration(params.toHashMap(), headers);

if (Config.hasConfig()) {
Config.initializeFaceTecSDKFromAutogeneratedConfig(
reactContext,
isDeveloperMode(params.toHashMap()),
new FaceTecSDK.InitializeCallback() {
@Override
public void onCompletion(final boolean successful) {
isInitialized = successful;
callback.invoke(successful);
if (!successful) {
String status = FaceTecSDK.getStatus(reactContext).toString();
Log.d("Capitual - SDK", "FaceTecSDK doesn't initialized!");
} else {
Log.d("Capitual - SDK", "FaceTecSDK initialized!");
}
}
});
Config.initialize(reactContext, isDeveloperMode(params.toHashMap()), new FaceTecSDK.InitializeCallback() {
@Override
public void onCompletion(final boolean successful) {
isInitialized = successful;
callback.invoke(successful);
}
});
} else {
isInitialized = false;
callback.invoke(false);
Log.d("Capitual - SDK", "FaceTecSDK doesn't initialized!");
Log.d("Capitual - SDK", "CapFace SDK doesn't initialized!");
}

this.handleTheme(Config.Theme);
Expand Down Expand Up @@ -202,8 +200,8 @@ public void removeListeners(Integer count) {
public void handleLivenessCheck(ReadableMap data, Promise promise) {
setProcessorPromise(promise);
if (!isInitialized) {
Log.d("Capitual - SDK", "FaceTecSDK doesn't initialized!");
this.processorPromise.reject("FaceTecSDK doesn't initialized!", "FaceTecDoenstInitialized");
Log.d("Capitual - SDK", "CapFace SDK has not been initialized!");
this.processorPromise.reject("CapFace SDK has not been initialized!", "CapFaceHasNotBeenInitialized");
return;
}

Expand All @@ -224,8 +222,8 @@ public void onSessionTokenReceived(String sessionToken) {
public void handleEnrollUser(ReadableMap data, Promise promise) {
setProcessorPromise(promise);
if (!isInitialized) {
Log.d("Capitual - SDK", "FaceTecSDK doesn't initialized!");
this.processorPromise.reject("FaceTecSDK doesn't initialized!", "FaceTecDoenstInitialized");
Log.d("Capitual - SDK", "CapFace SDK has not been initialized!");
this.processorPromise.reject("CapFace SDK has not been initialized!", "CapFaceHasNotBeenInitialized");
return;
}

Expand All @@ -247,8 +245,8 @@ public void onSessionTokenReceived(String sessionToken) {
public void handleAuthenticateUser(ReadableMap data, Promise promise) {
setProcessorPromise(promise);
if (!isInitialized) {
Log.d("Capitual - SDK", "FaceTecSDK doesn't initialized!");
this.processorPromise.reject("FaceTecSDK doesn't initialized!", "FaceTecDoenstInitialized");
Log.d("Capitual - SDK", "CapFace SDK has not been initialized!");
this.processorPromise.reject("CapFace SDK has not been initialized!", "CapFaceHasNotBeenInitialized");
return;
}

Expand All @@ -269,8 +267,8 @@ public void onSessionTokenReceived(String sessionToken) {
public void handlePhotoIDMatch(ReadableMap data, Promise promise) {
setProcessorPromise(promise);
if (!isInitialized) {
Log.d("Capitual - SDK", "FaceTecSDK doesn't initialized!");
this.processorPromise.reject("FaceTecSDK doesn't initialized!", "FaceTecDoenstInitialized");
Log.d("Capitual - SDK", "CapFace SDK has not been initialized!");
this.processorPromise.reject("CapFace SDK has not been initialized!", "CapFaceHasNotBeenInitialized");
return;
}

Expand All @@ -292,8 +290,8 @@ public void onSessionTokenReceived(String sessionToken) {
public void handlePhotoIDScan(ReadableMap data, Promise promise) {
setProcessorPromise(promise);
if (!isInitialized) {
Log.d("Capitual - SDK", "FaceTecSDK doesn't initialized!");
this.processorPromise.reject("FaceTecSDK doesn't initialized!", "FaceTecDoenstInitialized");
Log.d("Capitual - SDK", "CapFace SDK has not been initialized!");
this.processorPromise.reject("CapFace SDK has not been initialized!", "CapFaceHasNotBeenInitialized");
return;
}

Expand Down
2 changes: 1 addition & 1 deletion android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name" translatable="false">FaceTec SDK</string>
<string name="app_name" translatable="false">CapFace SDK</string>
<string name="enroll_simple">Enroll User</string>
<string name="auth_simple">Authenticate User</string>
<string name="liveness_check">3D Liveness Check</string>
Expand Down
Loading