Skip to main content

Verify and Compare

Use the verifyAndCompare() method to run a Ghana Card Verify and Compare session. The SDK generates a token and launches the verification in an iframe.

1. Creating a Metric instance​

The Metric() constructor is used to create a Metric instance

const metric = new window.Metric({
client_id: "your_public_key",
client_secret: "your_secret_key",
});

Parameters​

client_id: An API encrypted public key string. For example, AIzaSyDaGmWKa4JsXZ-HjGw7ISLn_3namBGewQe


client_secret: An API encrypted secret key string. For example, AIzaSyDaGmWKa4JsXZ-HjGw7ISLn_3namBGewQe


2. Triggering a verification procedure​

The verifyAndCompare() method on the Metric object is called with three arguments: payload, callback, and options(optional). This creates an iframe element that loads the verification process. Once the verification process is complete, the iframe is removed from the DOM and the callback function is called with the results of the verification process.

const metric = new window.Metric({
client_id: "your_public_key",
client_secret: "your_secret_key",
});

metric.verifyAndCompare(payload, callback, options);

Parameters​

payload: An object that contains the data required to perform the verification. Verify and Compare is Ghana Card only. The object has the following properties:

  • card_number (optional): A string representing the Ghana Card number of the user. When provided, it should follow the format GHA-XXXXXXXXX-X.

  • phone_number (optional): A string representing the phone number of the user.

  • reference_id: A string representing the reference ID for the verification.

  • purpose: A string representing the purpose of the verification.

  • email (optional): An optional string representing the user's email address.

  • date_of_birth (optional): A string representing the user's date of birth in the format YYYY-MM-DD.

  • comment (optional): An optional string representing any additional comment to include.

  • first_name (optional): An optional string representing the user's first name.

  • last_name (optional): An optional string representing the user's last name.

callback: A function that takes a single argument results. The function will be called when the verification is complete, and results will contain an object with the following properties:

  • session_status: A string representing the status of the verification.

  • transaction_number: A string representing the transaction number of the verification.

options(optional): This object provides options for fine-tuning the verification process with extra parameters. It can contain the following properties:

  • with_instructions: Set to 1 to include verification guidelines and confirmation screens, or 0 to skip them and proceed directly to the liveness capture session.

  • require_location: This parameter determines whether the user's device location should be captured during the verification process. Set to 1 to enable location capture or 0 to omit it.

  • require_address_location: This parameter determines whether the user's home address should be captured after the verification process. Set to 1 to enable home address capture or 0 to omit it.

  • require_explicit_address_input: This parameter determines whether the user must manually provide their home address rather than having it inferred by the system. Set to 1 to require explicit address input or 0 to allow the system to infer the address when possible.

  • require_phone_number_verification: This parameter determines whether the user's phone number should be verified. Set to 1 to require phone number verification or 0 to omit it.

  • require_email_verification: This parameter determines whether the user's email address should be verified. Set to 1 to require email verification or 0 to omit it.

Full Example​

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Page Title</title>
</head>
<body>
<button onclick="verifyUser()">Verify Me</button>

<script type="text/javascript" src="https://sdk.dev.metric.africa/v1"></script>

<script>
const verifyUser = () => {
const metric = new window.Metric({
client_id: "XXXXXXXXXX",
client_secret: "XXXXXXXXXX",
});

metric.verifyAndCompare(
{
card_number: "GHA-000000000-0",
reference_id: "0300000000",
purpose: "state your purpose",
phone_number: "030000000",
email: "email@email.com",
},
(results) => {
console.log(results.session_status, results.transaction_number);
},
{
require_phone_number_verification: 1,
require_email_verification: 1,
require_address_location: 1,
}
);
};
</script>
</body>
</html>