[WordPress] How To trigger TOT verification flow with custom code?

Collect required Data and call verifyPerson

  • Endpoint:  wp-admin/admin-ajax.php?action=tot_verify_person
  • Method: POST
  • Payload

{ "appData": { "billing_first_name": "string", "billing_last_name": "string", "billing_email": "string", "billing_phone": "string", "billing_country": "string", "billing_address_1": "string", "billing_address_2": "string", "billing_city": "string", "billing_state": "string", "billing_postcode": "string", "tot-api-verify-person-nonce": "string", "user_id": "string" // optional }, }

For tot-api-verify-person-nonce: you need to generate one for your use 

Handle The response

For unverified user: response.code => WorkflowService:nextStepIsInteractive

For verified user: response.code => WorkflowService:conditionsMet

And here’s an example on how to handle in JS

function handleVerificationResponse(response) { if (response.code === "WorkflowService:nextStepIsInteractive" && response.status === 422) { // Launch verification interface const { modalType, params } = response.continuation; params.disableClose = true; // Trigger verification let verifyPersonInProgress = true; window.tot('modalOpen', modalType, params); // @see next section for handling modal close event } else if (response.code === "WorkflowService:conditionsMet") { // User is verified } else { // Handle other response types console.error('Unexpected verification response:', response); } }

Handle Modal Close event

Once the end user is done - the modal will close and control will return to your app.  To be informed of this you will probably want to register for this event so you can take action. Here’s an example that’s done: 

tot("bind", "modalClose", function (eventData, evt) { console.log("[CONSOLE] my modalClose event called!"); verifyPersonInProgress = false; if (evt && evt.data) { var eventData = {}; try { eventData = JSON.parse(evt.data); } catch (err) { return false; } eventData = eventData.data || eventData; if (eventData.continue) { if (lastEvent.eventTimestamp === evt.timeStamp) { return; // don't process invalid data, nor the same event twice. } lastEvent.eventTimestamp = evt.timeStamp; checkVerificationStatusAndDoSomething(); // your function. } } return false; });

function handleVerificationResponse(response) {
    if (response.code === "WorkflowService:nextStepIsInteractive" && response.status === 422) {

        // Launch verification interface
        const {
            modalType,
            params
        } = response.continuation;
        params.disableClose = true;

        // Trigger verification
        let verifyPersonInProgress = true;
        window.tot('modalOpen', modalType, params);

        // @see next section for handling modal close event

    } else if (response.code === "WorkflowService:conditionsMet") {
        // User is verified
    } else {
        // Handle other response types
        console.error('Unexpected verification response:', response);
    }
}

Once the end user is done - the modal will close and control will return to your app. To be informed of this you will probably want to register for this event so you can take action. Here’s an example that’s done:

tot("bind", "modalClose", function (eventData, evt) {
   console.log("[CONSOLE] my modalClose event called!");
   verifyPersonInProgress = false;
   if (evt && evt.data) {
       var eventData = {};
       try {
           eventData = JSON.parse(evt.data);
       } catch (err) {
           return false;
       }
       eventData = eventData.data || eventData;
       if (eventData.continue) {
           if (lastEvent.eventTimestamp === evt.timeStamp) {
               return; // don't process invalid data, nor the same event twice.
           }
           lastEvent.eventTimestamp = evt.timeStamp;
           checkVerificationStatusAndDoSomething(); // your function.
       }
   }
   return false;
});

Read more

How do you setup identity or age verification so that only certain locations need to get verified?

Answer: Use Location-Based Identity Verification. This is enabled via the locationRestrictions.requiresVerification attribute in your application configuration to define which countries and regions require verification. Summary Token of Trust now supports location-based verification requirements through the locationRestrictions configuration. This feature allows you to specify which geographic locations (countries and regions)

By darrin