Document Verification

Required Class: SmileIdentityCore Class

Running Document Verification on PHP

  1. Get your Smile ID Partner ID

  2. Get your API Key

  3. Create a Callback Endpoint

  4. Get your user's Selfie images

  5. Get the user's ID document image

  6. Submit the Job to Smile ID

  7. Interpret your results

Get your Partner ID

You can find your Partner ID in the menu list when logged into the portal.

Get your API Key

Your API Key is also in the developer section of the portal.

  • Click on the Generate New API Key button

  • Copy your api key (ensure you are in the right environment)

Create a Callback Endpoint

Responses from this product are asynchronous (based on various actions we carry out on the product) and are sent as soon as they are ready, you will need to setup a callback when submitting a job. You can read about creating a Callback URL here.

Get the User's Selfie

To successfully run document verification jobs you need to submit the user's selfie. There are two types of selfies that can be submitted

  • Selfie - a single colour-image selfie of user

  • (optional but required for proof of live) Liveness images - 8 colour images of user

The selfies can either be submitted as files (with the path to the image specified during submission) or as base64 encoded strings.

We recommend that you use our Web SDK to capture both of these types of images

Get the ID Document Image from your User

In addition to the user's selfie, we also need an image of the ID document to complete a document verification job. We will also need the country of issuance of the ID document and the document type. For the full list of document types we support, you can check the Supported Documents section of the docs. To check the authenticity of the document, we require high resolution images, please read the minimum specification of the document image and best practices in document verification product page.

Submit the Job to Smile ID

You can copy the sample code below and edit with your partner and job details.

<?php
require 'vendor/autoload.php';

// Initialize
$partner_id = "<Put your partner ID here>"; // login to the Smile ID portal to view your partner id
$default_callback = "<Put your default callback here>"; //callback is only required if you are running an asynchronous job
$api_key = "<Put your API key here>"; // copy your API key from the Smile ID portal
$sid_server = "<0 or 1>"; // Use '0' for the sandbox server, use '1' for production server

$connection = new SmileIdentityCore(
    $partner_id,
    $default_callback,
    $api_key,
    $sid_server
);

// Create required tracking parameters
$partner_params = array(
    'job_id' => "<put your unique job ID here>",
    'user_id' => "<put your unique ID for the user here>",
    'job_type' => 6
);

// Create image list
// image_type_id Integer
// 0 - Selfie image jpg (if you have the full path of the selfie)
// 2 - Selfie image jpg base64 encoded (if you have the base64image string of the selfie)
// 4 - Liveness image jpg (if you have the full path of the liveness image)
// 6 - Liveness image jpg base64 encoded (if you have the base64image string of the liveness image)
// 1 - Front of ID document image jpg (if you have the full path of the selfie)
// 3 - Front of ID document image jpg base64 encoded (if you have the base64image string of the selfie)
// 5 - Back of ID document image jpg (if you have the full path of the selfie)
// 7 - Back of ID document image jpg base64 encoded (if you have the base64image string of the selfie)
$image_details = array(

    array(
        "image_type_id" => <0 | 2>,
        "image" => "<full path to selfie image or base64image string>"
    ),
    array( // Not required if you don't require proof of life (note photo of photo check will still be performed on the uploaded selfie)
        "image_type_id" => <4 | 6>,
        "image" => "<full path to liveness image or base64 image string>"
    ),
    array(
        "image_type_id" => <1 | 3>,
        "image" => "<full path to front of id document image or base64image string>"
    ),
    array( // Optional, only use if you're uploading the back of the id document image
        "image_type_id" => <5 | 7>,
        "image" => "<full path to front of id document image or base64image string>"
    )
);

// The ID Document Information
$id_info = array(
  "country" => '<2-letter country code>', // The country where ID document was issued
  "id_type" => '<id type>' // The ID document type
);

// Set the options for the job
$options = array(
  "return_job_status" => <true | false>, // Set to true if you want to get the job result in sync (in addition to the result been sent to your callback). If set to false, result is sent to callback url only.
  "return_history" => <true | false>, // Set to true to return results of all jobs you have ran for the user in addition to current job result. You must set return_job_status to true to use this flag.
  "return_image_links" => <true |false>, // Set to true to receive selfie and liveness images you uploaded. You must set return_job_status to true to use this flag.
  "signature" => true
);

// Submit the job.
// This method returns a json array
$response = $connection->submit_job($partner_params, $image_details, $id_info, $options);
?>

Getting the Job Result

By default you always get the result of your job in the callback url you provided, however for some use cases you might want to get the job result in sync after submission. The flag return_job_status can be set to true if you want to get the job result in sync.

Response when return_job_status is set to false

If return_job_status is set to false, the response will be a JSON string containing:

{success: true, smile_job_id: <the generated smile_job_id>}

The job result will be sent to the callback url you provided, it will look as follows:

{
    DOB: "1989-01-20",
    FullName: “John Joe Doe”,
    Gender: “M”,
    IDType: "PASSPORT",
    Actions: {
        Liveness_Check: "Passed",
        Register_Selfie: "Approved",
        Verify_Document: "Passed",
        Human_Review_Compare: "Passed",
        Return_Personal_Info: "Returned",
        Selfie_To_ID_Card_Compare: "Completed",
        Human_Review_Liveness_Check: "Passed"
    },
    Country: "NG",
    Document: "----base64 encoded string----”,
    IDNumber: "B00123456",
    ResultCode: "0810",
    ResultText: "Document Verified After Human Review",
    SmileJobID: "0000000046",
    PartnerParams: {
        job_id: "Testing_0036",
        user_id: "Test_0036",
        job_type: "6"
    },
    ExpirationDate: "2025-11-26",
    timestamp: "2021-12-14T20:07:56.829Z",
    signature: "---signature---”
}

Response when return_job_status is set to true

If you have use cases that require you to get the result in sync, you can set the return_job_status to true. Please note that it can take up to 1 minute 30 seconds to get an in sync result as there are times when the submitted job requires human review.

If you set return_job_status to true (with image_links and history also set to true) then you will receive the JSON object containing the machine result like below:

{
  "timestamp": "2022-03-31T14:31:46.185Z",
  "signature": "---signature---",
  "job_complete": true,
  "job_success": true,
  "code": "2302",
  "result": {
    "DOB": "1989-01-20",
    "Gender": "M",
    "IDType": "PASSPORT",
    "Actions": {
      "Liveness_Check": "Passed",
      "Register_Selfie": "Passed",
      "Verify_Document": "Passed",
      "Human_Review_Compare": "Passed",
      "Return_Personal_Info": "Returned",
      "Selfie_To_ID_Card_Compare": "Completed",
      "Human_Review_Liveness_Check": "Passed"
    },
    "Address": "Not Available",
    "Country": "NG",
    "Document": "----base64 encoded string----",
    "FullName": "John Joe Doe",
    "IDNumber": "B00123456",
    "ResultCode": "0810",
    "ResultText": "Document Verified",
    "SmileJobID": "0000000046",
    "PhoneNumber": "Not Available",
    "PhoneNumber2": "Not Available",
    "PartnerParams": {
      "job_id": "Testing_0036",
      "user_id": "Test_0036",
      "job_type": "6"
    },
    "ExpirationDate": "2025-11-26",
    "SecondaryIDNumber": "Not Available"
  },
  "history": [
    {
      "DOB": "1989-01-20",
      "Gender": "M",
      "IDType": "PASSPORT",
      "Actions": {
        "Liveness_Check": "Passed",
        "Register_Selfie": "Passed",
        "Verify_Document": "Passed",
        "Human_Review_Compare": "Passed",
        "Return_Personal_Info": "Returned",
        "Selfie_To_ID_Card_Compare": "Completed",
        "Human_Review_Liveness_Check": "Passed"
      },
      "Address": "Not Available",
      "Country": "ZA",
      "Document": "----base64 encoded string----",
      "FullName": "John Joe Doe",
      "IDNumber": "B00123456",
      "ResultCode": "0810",
      "ResultText": "Document Verified",
      "SmileJobID": "0000000046",
      "PhoneNumber": "Not Available",
      "PhoneNumber2": "Not Available",
      "PartnerParams": {
        "job_id": "Testing_0036",
        "user_id": "Test_0036",
        "job_type": "6"
      },
      "ExpirationDate": "2025-11-26",
      "SecondaryIDNumber": "Not Available"
    }
  ],
  "image_links": {
    "selfie_image": "-----link to selfie image------"
  },
  "success": true,
  "smile_job_id": "0000000046"
}

Interpret your Results

You can read more about result codes and responses in the Document Verification section of the docs.

Last updated