Skip to main content

Initiate Verification

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 verify() method on the Metric object is called with four arguments: type, payload, callback, section(optional) This creates an iframe element that loads the verification process from the Metric API. 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_private_key",
});

metric.verify(type, payload, callback, section);

Parameters

type: A string literal type that indicates the type of verification to be performed. The value must be one of the following:ghana_card, new_voter, old_voter, passport, or driver_license.

payload: An object that contains the data required to perform the verification. The object has the following properties:
  • card_number: A string representing the card number of the user's ID.
  • phone_number: 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.
  • date_of_birth (required when type is "driver_license"): 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:
  • status: A string representing the status of the verification.
  • transaction_number: A string representing the transaction number of the verification.
section(optional): If desired, users can include the section parameter, which is optional and accepts a single value: "camera". This allows users to skip the guidelines and confirmation screens during the verification process and proceed directly to the liveness capture session.

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.verify(
"ghana_card",
{
card_number: "GHA-000000000-0",
reference_id: "0300000000",
purpose: "state your purpose",
phone_number: "030000000",
},
(results) => {
console.log(results.status, results.transaction_number);
}
);
};
</script>
</body>
</html>