Prepare

The prepare component can be found under the Sybrin.Identity namespace and is called PrepareComponent.

Full name: Sybrin.Identity.PrepareComponent.

It provides an interface for selecting a desired capture method, as well as an easy way to view a customizable privacy policy and usage guidelines.

With default styling, the prepare component appears as follows:

Upon clicking "View Our Privacy Policy", the onViewPrivacyPolicy event will fire. Hooking onto this event allows you to react to the button click and show your privacy policy.

Upon clicking "View Guidelines", the component will automatically open a new window and display guidelines for taking an identity document photo. The onViewGuidelines event will also fire, allowing you to run additional code if needed.

Clicking "Upload Photo" will fire the onBeforeUpload event and then invoke the uploadDocument function of the JavaScript API, resulting in a file picker popping up and allowing the user to complete data extraction using a file upload. Completion will result in the onScanResult event firing, and an error will result in the onScanError event firing. Cancelling will fire the onScanCancelled event.

Clicking "Take Photo" will result in the onTakePhoto event firing, which can then be used as a signal to initialize the document scan component, or the device select component first should the user system possess multiple viable video input devices.

If the component is configured to allow for mobile capture and the flow is being executed on a desktop web browser, the "Mobile Capture" button will be available. Clicking on "Mobile Capture" will cause the onMobileCaptureStart event to fire. This can then be used as a trigger to generate a mobile ID and signal for the prepare component to present a scannable QR code and a URL by invoking the initializeMobileCaptureWithId function. This will result in the following:

On this screen, clicking "Cancel" will revert the prepare component back to the previous state. Clicking "Copy Link" will copy the unique URL to the user's clipboard.

Initialization

The prepare component can be initialized using the following code:

<div id='prepare'></div>

The Sybrin Web SDK provides the option to either pass down the ID of the element you wish to use for component initialization, or to pass the element directly.

Please note that 'prepare' is just an example in this context and the ID may be changed as desired as long as it matches the value passed down during component initialization in JavaScript.

During initialization, the prepare component allows for a number of configuration options that may be passed down using an object literal. The parameters that may be used on the object include the following:

Required:

  • id (string): ID of the element you wish to use for component initialization. Not required if element is passed.

  • element (HTMLElement): Element you wish to use for component initialization. Not required if id is passed.

  • api (Sybrin.Identity.Api): Instance of a JavaScript API that may be pre-configured as desired. Not required if an instance of options is passed. This is the instance that will be used for invoking photo upload functionality.

  • options (Sybrin.Identity.Options): Configuration options to instantiate Sybrin.Identity.Api with. Not required if an instance of api is passed. This is the instance that will be used for invoking photo upload functionality.

  • documentTypeId (string): An ID that points to a unique document type for a specific country. Not required if countryCode and documentTypeName are specified.

  • countryCode (string): The Alpha-3 standard country code of the document to be uploaded. Not required if documentTypeId is passed.

  • documentTypeName (string): The document type to be uploaded. Please see document type overrides and filtering for a list of supported document type names. Not required if documentTypeId is passed.

Optional:

  • correlationId (string): Unique identifier for the case that will be passed down to the back-end if set.

  • enableMobileCapture (boolean): A flag that sets whether or not mobile capture should be enabled. If it is set to true and the flow is being executed on a desktop browser, the "Mobile Capture" button will be visible.

  • flowDirection (number): This property is used to control the flow direction of the guidelines window. 0 is left to right. 1 is right to left. Default 0

  • translations ({ [key: string]: string }): An object literal representing a dictionary lookup that will be used for translating the component. Please see the translations section on this page for a list of all translatable text, as well as the localization page for a detailed description on how to implement localization.

Warning: Initialization will fail if the intended host element does not exist yet.

Always ensure that the initialize function is only called after the DOM is loaded.

Destruction

The prepare component may be removed from the UI by calling the destroy() function on it.

Example:

component.destroy();

Functions

Initialize

initialize(): void

Initializes the component's DOM and events.

Destroy

destroy(): void

Destroys the component's DOM and events.

Set Translations

setTranslations(translations?: { [key: string]: string; }): void

Changes the component's translations to the provided values and updates the DOM accordingly.

Set Flow Direction

setFlowDirection(flowDirection: FlowDirection): void

Changes the component's flow direction.

Events

The prepare component offers multiple events. To hook onto an event, simply assign a function to it.

The following options are available:

  • onScanResult(result: DocumentScanResult)

  • onScanError(error: string)

  • onScanCancelled()

  • onBeforeUpload()

  • onMobileCaptureStart()

  • onMobileCaptureCancel()

  • onTakePhoto()

  • onViewPrivacyPolicy()

  • onViewGuidelines()

On Scan Result

This function is called after data extraction runs without error once the "Upload Photo" button is clicked. To hook onto the event, you may use the following code:

component.onScanResult = function(result) {
    console.log('Success: ', result.success);
    for (const property in result.data) {
        console.log('Value of ' + property + ' is ' + result.data[property]);
    }
}

The result parameter is of type Sybrin.Identity.DocumentScanResult and includes the following properties:

  • success (boolean): Whether or not data could be extracted.

  • message (string): Additional information when applicable, for instance an error message if one occurred.

  • data (object): An object with all data fields that were successfully extracted.

  • images (object): An object with images. These include

    • documentImage (string): Base64 string of the front photo of the document.

    • documentBackImage (string): Base64 string of the back photo of the document (if supplied).

    • portraitImage (string): Base64 string of the extracted face portrait image pulled from the document.

On Scan Error

This function is called when something goes wrong and an error occurs during data extraction. To hook onto the event, you may use the following code:

component.onScanError = function(error) {
    console.log('An error occurred: ', error);
}

The error parameter is of type string.

On Scan Cancelled

This function is called when a document scan for data extraction was started, but then cancelled before completion. To hook onto the event, you may use the following code:

component.onScanCancelled = function() {
    // Your code here
}

No parameter is passed to this function call.

On Before Upload

This function is called before the file upload window appears. It is recommended to use this function to set the correlationId of the component by calling setCorrelationId(). To hook onto the event, you may use the following code:

component.onBeforeUpload = function() {
    // Your code here
    // component.setCorrelationId('your-id-here');
}

No parameter is passed to this function call.

On Mobile Capture Start

This function is called when the "Mobile Capture" button is clicked. To hook onto the event, you may use the following code:

component.onMobileCaptureStart = function() {
    console.log('Mobile Capture clicked!');
}

No parameter is passed to this function call.

On Mobile Capture Cancel

This function is called when the "Cancel" button is clicked while the component is in the mobile capture state. To hook onto the event, you may use the following code:

component.onMobileCaptureCancel = function() {
    console.log('Cancel clicked!');
}

No parameter is passed to this function call.

On Take Photo

This function is called when the "Take Photo" button is clicked. To hook onto the event, you may use the following code:

component.onTakePhoto = function() {
    console.log('Take Photo clicked!');
}

No parameter is passed to this function call.

On View Privacy Policy

This function is called when the "View Our Privacy Policy" button is clicked. To hook onto the event, you may use the following code:

component.onViewPrivacyPolicy = function() {
    console.log('Privacy Policy clicked!');
}

No parameter is passed to this function call.

On View Guidelines

This function is called when the "View Guidelines" button is clicked. To hook onto the event, you may use the following code:

component.onViewGuidelines = function() {
    console.log('View Guidelines clicked!');
}

No parameter is passed to this function call.

Styling

The prepare component is structured a follows:

<div class="sybrin-identity-container">
    <div class="sybrin-identity-halves sybrin-identity-prompts-section">
        <div class="sybrin-identity-half">
            <div class="sybrin-identity-block sybrin-identity-privacy-block">
                <div class="sybrin-identity-block-icon">
                </div>
                <div class="sybrin-identity-block-prompt sy-i-translation-31">
                    Your ID document photo <b>will be encrypted</b> and stored in our digital vault.
                </div>
                <div class="sybrin-identity-block-button sybrin-identity-privacy-button sy-i-translation-32">
                    View Our <b>Privacy Policy</b> 
                </div>
            </div>
        </div>
        <div class="sybrin-identity-half">
            <div class="sybrin-identity-block sybrin-identity-guidelines-block">
                <div class="sybrin-identity-block-icon">
                </div>
                <div class="sybrin-identity-block-prompt sy-i-translation-33">
                    Take a good <b>ID Document photo</b>.
                </div>
                <div class="sybrin-identity-block-button sybrin-identity-guidelines-button sy-i-translation-34">
                    View <b>Guidelines</b> 
                </div>
            </div>
        </div>
    </div>
    <div class="sybrin-identity-container sybrin-identity-qr-section sybrin-hidden">
        <div class="sybrin-identity-block">
            <canvas class="sybrin-qr-canvas"></canvas>
            <div class="sybrin-identity-block-prompt">
                <p class="sy-i-translation-35">Using your mobile device, please scan the above QR code or manually navigate to the following URL in your mobile browser:</p>
                <p class="sybrin-mobile-capture-url"></p>
                <p class="sy-i-translation-36">The flow will continue after running identity capture and clicking the "Complete Step" button on your mobile device</p>
            </div>
            <div class="sybrin-identity-button-section">
                <button class="sybrin-identity-cancel-qr sybrin-identity-flow-button sybrin-secondary sy-i-translation-37">Cancel</button>
                <button class="sybrin-identity-copy sybrin-identity-flow-button sybrin-secondary sy-i-translation-38">Copy Link</button>
            </div>
        </div>
    </div>
    <div class="sybrin-identity-button-section sybrin-identity-buttons-main">
    </div>
</div>

When the component switches to mobile capture mode, the sybrin-identity-qr-section element is shown and the sybrin-identity-prompts-section element is hidden. By default and when cancelling mobile, the reverse is true.

The classes and elements specified above may be used to freely style the prepare component as desired. To do so, simply create a stylesheet and include it in the project, then style according to the above classes and elements.

Styling implementation example:

index.html
<html>
<head>
    <link rel="stylesheet" type="text/css" href="styles.css" media="screen"/>
</head>
<body>
    <div id='component'></div>
</body>
</html>

Translations

This component is affected by the following translation keys:

Additionally, the component may be used to invoke an internally defined set of guidelines, displayed in a separate window. This window's content can also be translated. The following keys are available:

Last updated