Your own site#
You can keep the customer on your site. The verification steps then show inside a page of your site, on your own domain. Rokh supplies a small script (the SDK) for this.
You can also send the customer to the Rokh page and get the customer back at the end. Read Return to your site.
How it works#
- Your server makes a request. It receives
customer_url. - Your page loads the Rokh SDK and gives it
customer_url. - The SDK shows the Rokh steps in a frame of your page.
- The frame tells your page the progress of the customer. It never tells your page the result.
- Your server reads the result from the API or from a webhook.
The browser shows the frame only on the origins that you allow. On all other sites, the browser refuses the frame.
Allow your site#
An origin is the scheme, the host name and the port of your site, for example https://www.example.com. It has no path.
- Sign in to the vendor panel.
- Open Developers.
- In Verification in your own site, type each origin of your site on a separate line.
- Click Save.
Rules for origins:
- Use
https. For tests on your computer, you can also usehttp://localhostandhttp://127.0.0.1, with a port. - Give the exact host name. Rokh does not accept wildcards such as
https://*.example.com. - You can give at most 10 origins.
https://example.comandhttps://www.example.comare two different origins. Add both if your site uses both.
You can also use the API:
PUT /api/vendor/panel/embed
Authorization: Bearer rk_live_…
Content-Type: application/json
{"allowed_origins": ["https://www.example.com", "https://example.com"]}
GET /api/vendor/panel/embed gives the saved origins and the address of the SDK.
Note: The change has an effect on all your customer links, also on links that you made before.
Load the SDK#
Add the SDK to your page:
<script src="https://rokh.id/static/sdk/rokh-kyc.js"></script>
Note: If your customer links use your domain, load the SDK from your hostname, for example
https://kyc.example.com/static/sdk/rokh-kyc.js.
The SDK makes the object RokhKyc with two functions:
| Function | Effect |
|---|---|
RokhKyc.open(options) |
Shows the steps on the full screen, with a close button at the top. Use it on phones. |
RokhKyc.mount(container, options) |
Shows the steps inside an element of your page. Give the element a height of at least 640 pixels. |
Full screen#
<button id="verify" type="button">Verify my identity</button>
<script>
document.getElementById('verify').addEventListener('click', function () {
RokhKyc.open({
url: customerUrl, // the customer_url from your server
onProgress: function (event) { console.log(event.phase, event.step); },
onFinish: function (event) { /* ask your server for the result */ },
onError: function (event) { /* event.code */ },
onClose: function () { /* the customer closed the steps */ }
});
});
</script>
open returns an object with the function close(). Use it to remove the layer from your page, for example after onFinish.
Inside your page#
<div id="kyc" style="height: 100vh; min-height: 640px"></div>
<script>
var flow = RokhKyc.mount('#kyc', {url: customerUrl, onFinish: function () { /* … */ }});
// flow.destroy() removes the frame.
</script>
Options#
| Option | Type | Effect |
|---|---|---|
url |
string | Necessary. The customer_url of the request. The SDK refuses a different address. |
title |
string | The accessible name of the frame. Default: «احراز هویت». |
closeLabel |
string | The text of the close button of open. Default: «بستن». |
onEvent |
function | Receives every event. |
onReady |
function | Receives the ready event. |
onProgress |
function | Receives each progress event. |
onFinish |
function | Receives the finished event. |
onError |
function | Receives the error event. |
onClose |
function | open only. The customer clicked the close button. |
Events#
Each event is an object with these fields: source is "rokh", version is 1, and type is the type of the event.
type |
Other fields | Occurs when |
|---|---|---|
ready |
total_steps (or null) |
The steps can start. |
progress |
phase, step, completed_steps, total_steps |
The customer moves to a different screen. |
finished |
result |
The customer completed all steps (submitted), or used all attempts of a step (attempts_exhausted). |
error |
code |
The link is not valid (link_invalid), or the page could not load (load_failed). |
closed |
none | open only. The customer clicked the close button. The SDK makes this event. |
Values of phase:
phase |
Screen |
|---|---|
welcome |
The document choice |
instructions |
The instructions of a step |
retry |
The instructions of a step again, after a problem that the customer can correct |
capturing |
The camera is open |
sending |
The recording goes to Rokh |
checking |
Rokh examines the step |
submitting |
Rokh saves the last step |
finished |
The end |
step is document, face or declaration, or null when no step applies.
Warning: Do not use the events to accept a customer. A person can change the events in their own browser. Read the result only on your server, from the API or from a webhook.
Without the SDK#
You can also add the frame yourself:
<iframe src="CUSTOMER_URL" allow="camera; microphone; autoplay; fullscreen; screen-wake-lock"
title="احراز هویت" style="border:0;width:100%;height:100vh"></iframe>
- The
allowattribute is necessary. Without it, the browser does not let the steps use the camera. - Listen for
messageevents onwindow. Accept a message only whenevent.originishttps://rokh.idandevent.sourceis the window of your frame.
window.addEventListener('message', function (event) {
if (event.origin !== 'https://rokh.id' || event.source !== frame.contentWindow) return;
if (!event.data || event.data.source !== 'rokh' || event.data.version !== 1) return;
// event.data.type, event.data.phase …
});
Content security policy of your site#
If your site has a content security policy, add Rokh to it:
frame-src https://rokh.id;
script-src https://rokh.id;
Return to your site#
Use this way when you open the Rokh page as a full page, not in a frame.
- Add the origin of your site to the allowed origins. See Allow your site.
- Send
return_urlwhen you make the request. Its origin must be one of your allowed origins. - Send the customer to
customer_url.
After the last step, the Rokh page shows a button «بازگشت به …» with your name. After 8 seconds, the page opens return_url automatically. Rokh adds the parameter rokh_status to the address:
rokh_status |
Meaning |
|---|---|
submitted |
The customer completed all steps. |
attempts_exhausted |
The customer used all attempts of a step. |
Example: https://www.example.com/kyc/done?order=10493&rokh_status=submitted.
Warning: A person can change
rokh_statusin the address. Read the result only on your server.
Inside a frame, Rokh does not open return_url. Use the finished event there.
Phones and browsers#
- Chrome lets a frame use the camera when the frame has the
allowattribute. The SDK adds this attribute. Current versions of Safari on iPhone also support this attribute. - Test your page on the phones of your customers before you use it in production.
- If a browser does not show the camera inside your frame, use Return to your site for that browser.
- Use
RokhKyc.openon phones. The steps then have the full screen. - Do not put the frame inside a second frame of a different site. The browser examines all parent pages.
Your domain#
The steps show on your domain inside your page. The customer sees your address in the address bar. The frame itself comes from rokh.id. The customer pages also show your display name, your logo and your colours. Set them in Account.