1. Home
  2. Interswitch lending Service
  3. Value Financing
  4. Tokenization Using Hosted Fields

Tokenization Using Hosted Fields

This provides a way for merchant channels to securely collect card details for customers paying with credit on their channels. It enables the merchant to control the experience and look and feel.

The following fields are hosted securely in iframes which the merchant can embed in their checkout page;

  1. PAN
  2. Expiry Date
  3. PIN
  4. CVV

Step-by-step guide

For the duration of this guide, we will be using the form below.

Card form
<body>
  <form id="cardForm">
    <div class="panel">
      <header class="panel__header">
        <h2>Submit Card Details</h2>
      </header>
      <div class="panel__content">
        <div class="textfield--float-label">
          <label class="hosted-field--label" for="card-pan">
            <span class="icon"> </span> Card Number
          </label>
          <div id="card-pan" class="hosted-field"></div>
        </div>
        <div class="textfield--float-label">
          <label class="hosted-field--label" for="expiration-date">Expiration Date</label>
          <div id="expiration-date" class="hosted-field"></div>
        </div>
        <div class="textfield--float-label">
          <label class="hosted-field--label" for="card-cvv"> CVV</label>
          <div id="card-cvv" class="hosted-field"></div>
        </div>
        <div class="textfield--float-label">
          <label class="hosted-field--label" for="card-pin">Pin</label>
          <div id="card-pin" class="hosted-field"></div>
        </div>
      </div>
      <footer class="panel__footer">
        <button class="pay-button" type="submit">Submit</button>
      </footer>
    </div>
  </form>
</body>
  1. Load the SDK.

    Loading the SDK will make available a global interswitch.hostedFields variable available.

  2. Create a hosted field instance calling the newInstance method on the interswitch.hostedFields variable. The method takes options and a callback. An hosted field instance which can be used to register events listeners and finally submit the customer’s request when the customer clicks on a the submit button will be returned to the callback
    Create Hosted Fields Instance
      function (err, hostedFieldInstance) {
        if (err) {
          // something is wrong,
          return;
        }
        function findLabel(field) {
          return $('.hosted-field--label[for="' field.container.id + '"]');
        }
        hostedFieldInstance.on('focus'function (event) {
          var field = event.fields[event.emittedBy];
          findLabel(field).addClass('label-float').removeClass('filled');
        })
      })

    The options include authorization, accept offer request, fields and styles as shown below.

    Available Options
    var options = {
      request: {
        customerId: "2348030583962",
        providerCode: "MKT"
      },
      styles: {
        'input': {
          'font-size''16px',
          'font-family''roboto, verdana, sans-serif',
          'color''black'
        },
        ':focus': {
          'color''blue'
        },
        '.valid': {
          'color''black'
        },
        '.invalid': {
          'color''red'
        }
      },
      fields: {
        pan: {
          selector: '#card-pan',
          placeholder: '1111 1111 1111 1111'
        },
        cvv: {
          selector: '#card-cvv',
          placeholder: '111'
        },
        exp: {
          selector: '#expiration-date',
          placeholder: 'MM/YY'
        },
        pin: {
          selector: '#card-pin',
          placeholder: 'PIN'
        }
      }
    }
  3. As soon as the customer submits, initiate a submit request on the hostedFieldInstance returned in 2.
    Submit Loan Application
    var submit = document.querySelector('button[type="submit"]');
    submit.addEventListener('click'function (evt) {
      hostedFieldInstance.submit(function (err, payload) {
        if (err) {
          alert("Loan application failed");
          return;
        }
        else {
          var token = payload.body.token;
          var tokenExpiry = payload.body.tokenExpiryDate;
          return;
        }
      });
    }, false)

Articles

Was this article helpful to you? Yes No

How can we help?