Integration
This integration guide is for setting up our embedded verification option. Complete the prerequisites before integrating the flow.

Prerequisites

Step 1

Following the account creation, create your branded verification site for verifying your users. Your users will be verified on this URL for hosted integrations.
Parameter to Note: baseUrl

Step 2

Create a template(s) for required verification(s) to assign to your users. You can create multiple templates and then use those templates as conditions to invoke multiple verification combinations to your users when they are created or trigger a risk action.
Parameter to Note: template_id
Click Add Template
Input the name and enable each verification assigned to the template

Step 3

Generate your API keys by going to the Settings -> Developer, click on the create key to generate your key.
Click Create API Key
The keys are only visible once so please copy and save the keys.
KEY (api_key) : This key will be used for API calls which are done through the server of your applications. For example: Create User API
SECRET (secret): This secret will be used for generating signature for using our embed integration on your application. (See the signature generation ahead)
Embed Key (embedKey): This key should be used in the embed integration on your application as well as part of generating the signature.
Created keys to save

Integration Flow (Embed)

Step 1

The flow starts with creating a user through the Create User API, which will return the user_idfor the user.
Send the template_idin the create user request to assign the verifications required for any new user.
Optionally include a reference_id to link created users in Trust Swiftly to your original application.
1
https://{Your base URL}/api/users
2
3
{
4
"status": "success",
5
"id": 69,
6
"user_id": "3639",
7
"magic_link": "https:\/\/test.trustswiftly.com\/account\/security-verify?expires=1625603631&key=16RWTtJRKTwjFIQCGWsdarWkW4Qq2DdvfUQhdzvug3AVwWu5mbZht&signature=768898ec51b20a623ba813969215fe9c113c3a7232204c0046265b3c6"
8
}
Copied!
Parameter to Note: user_id
Store the user id for all the further communications with the API and for rendering the embed flow.

Step 2

Generating signature for API calls in the embed integration.
For generating signature we use a SHA256 hash algorithm, the PHP implementation example is below:
1
$embedKey = 'xxxxxxx';
2
$secret = 'xxxxxxxxx';
3
$user_id = 12345;
4
$timestamp = time();
5
$payloadString = $embedKey . $user_id . $timestamp;
6
$hash = hash_hmac('sha256', $payloadString, $secret);
7
$signature = 't=' . $timestamp . ',v2=' . $hash;
8
$apisecret = '0761ac60dadd3c0a8fe636c0b7cba4ef90c277f77a5b4b27add7cd3f572eec58';
9
$embedKey = "32daa045246eaa06716ff7b4c34bbd6528df6968";
10
$timestamp = time();
11
$payloadString = $embedKey . $user_id . $timestamp;
12
$hash = hash_hmac('sha256', $payloadString, $apisecret);
13
$signature = 't=' . $timestamp . ',v2=' . $hash;
Copied!
This signature is required for the next step to display the embed integration.

Step 3

There are 3 methods to display the embedded integration.
  1. 1.
    Embed within your page
  2. 2.
    Embed with a Bootstrap modal and our button
  3. 3.
    (Optional) Use the embed in page but only possible if you have a single type of verify.
The prerequisites for using the embed integration is to have jQuery 3.6 or up and Bootstrap 5 in your application, the CDN links are given as below.
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
2
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.2/js/bootstrap.min.js"> </script>
3
<script src="https://cdn.trustswiftly.com/account/trustverifyv2.js"></script>
4
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap.min.css" crossorigin="anonymous" />
5
Copied!
Next you need to place a div where you require display of the contents.
1
<div id="trustVerify" class="bg-light p-5 rounded"> </div>
Copied!
Method 1 Use the embed integration in your page as embedded content.
1
trustVerify.configs = {
2
embedKey: '{ embedKey }',
3
signature: '{ signature }',
4
baseUrl: '{baseUrl}',
5
type: 'page',
6
verifyDivId: "trustVerify",
7
userId: { user_id }
8
};
9
trustVerify.load();
Copied!
This will generate the verify content in the HTML Dom element/div element with the id trustVerify
Method 2 Use the embed integration modal in your page with the Trust Swiftly button/modal
1
trustVerify.configs = {
2
embedKey: '{ embedKey }',
3
signature: '{ signature }',
4
baseUrl: '{baseUrl}',
5
type: 'modal',
6
verifyDivId: "trustVerify",
7
userId: { user_id }
8
};
9
trustVerify.load();
Copied!
This will generate the Trust Swiftly verify button which would open the Bootstrap modal within the given div element.
Example Button
Method 3 Use the embed integration modal in your page to to directly show the specific verification. This is useful if your verification template only has one verification.
1
trustVerify.configs = {
2
embedKey: '{ embedKey }',
3
signature: '{ signature }',
4
baseUrl: '{baseUrl}',
5
type: 'page',
6
verifyCall: 'single', //options (single,multi)
7
verifyMethod: 'email', //options(email,phone,document,voice,video..) only works with single call
8
verifyDivId: "trustVerify",
9
userId: { user_id }
10
};
11
12
trustVerify.loadSingle();
Copied!
This will generate the verification in the same page similar to the 1st method but it will directly load the specific verification.
Direct display of verification

Step 4

The completion calls and updating certain verifications for your user can be monitored through callbacks and webhooks. We recommend implementing two methods to ensure changes are tracked properly.
There are 3 ways to know if the user has completed a certain verification which are as mentioned below:
  1. 1.
    Using our JS completion functions
1
onComplete: function(data) {
2
alert('Verification Complete' + data.value)
3
}
4
5
//Or
6
7
onStateChange: function(data) {
8
if (data.method == "DOCUMENT") {
9
if (data.state == "Successful") {
10
alert('Verification Complete')
11
}
12
}
13
}
Copied!
3. Using the Get User API call
Last modified 3mo ago