Account Boarding Merchant Agreement

Overview


In order to be boarded every Merchant needs to agree to Go Plus Terms and Conditions. To help Developers integrate Agreement API into their website we are supporting Agreement API through Cardknox iFields.

Integrate Agreement API using ifields

Obtain your iFields xKey from your Cardknox Partner Portal account settings.

Adding Reference to iFields


Step 1: Check the latest stable iFields version here: https://cdn.cardknox.com/ifields/versions.htm

Step 2: Add the ifields.js file after the <head> tag on your website:

<script src=https://cdn.cardknox.com/ifields/**ifields-version-number**/ifields.min.js></script>

Adding iFrame and JavaScript Objects for Merchant Agreement


Step 1: Add the following iFrame JS snippet inside the <body> where Merchant Agreement is desired.

  • Make sure you have an attribute data-ifields-id="agreement" as part of <iframe> tag

<iframe id="agreement" class="agreement" data-ifields-id="agreement" src="https://cdn.cardknox.com/ifields/**ifields-version-number**/agreement.htm"></iframe>

Step 2: Create JavaScript function to handle Agreement API callback

function handleAgreementResponse(response) {
    let msg = null;
    if (!response) {
        msg = "Failed to load token. No Response";
    } else if (response.status !== iStatus.success) {
        msg = "Failed to load token. "+response.statusText || "No Error description available";
    } else if (!response.token) {
        msg = "Failed to load token. No Token available";
    } else {
        msg = response.token;
    }
    setTimeout(() => {alert(msg)}, 10);
}

For response object reference refer here: Agreement Response

Step 3: Enable Customer Agreement to get the token

There are two ways to get the token:

  • Asynchronously (a callback will be performed once the customer agrees to Terms and Conditions) Just add enableAgreement call when the document is loaded (autoAgree the parameter is set to true):

document.addEventListener("DOMContentLoaded", function(event) {
    ................ 
    ckCustomerAgreement.enableAgreement({
        iframeField: 'agreement',
        xKey: '<Your ifields xKey>',
        autoAgree: true,
        callbackName: 'handleAgreementResponse'
    });
    ................    
}
  • Synchronously (Explicitly calling getToken function for example on Submit) Add enableAgreement call when the document is loaded (autoAgree the parameter is set to false):

document.addEventListener("DOMContentLoaded", function(event) {
    ................ 
    ckCustomerAgreement.enableAgreement({
        iframeField: 'agreement',
        xKey: '<Your ifields xKey>',
        autoAgree: false
    });
    ................    
}

In your Submit function add the following code:

ckCustomerAgreement.getToken()
    .then(resp => {
        handleAgreementResponse(resp);
    })
    .catch(err => {
        console.error("Agreement Token Error", exMsg(err));
        handleAgreementResponse(err);
    });

Objects Reference


iStatus

const iStatus = {
    success: 100,
    unsupported: -100,
    error: -200
}

Agreement Response

The object holding the response with token from Agreement API.

Name

Type

Description

status

There are 2 possible cases:

  • Agreement was accepted and Token was obtained status=iStatus.success

  • Agreement wasn’t accepted or an error occurred obtaining the token: status=iStatus.error

statusText

String

When status=iStatus.error this field will be populated with the reason

token

String

When status=iStatus.success this field will be populated with token

Last updated