Firstoken API Docs
  • ⚙️API Reference
    • Firstoken API
      • Tokenization As A Service
        • Simple Tokenization
        • Simple Detokenization
        • Inspect Token
        • Delete Tokens
      • Transactions
        • Create a Transaction
        • Retrieve a Transaction
        • Inspect a Transaction
        • Delete a Transaction
        • Tokenize a Transaction
      • Proxy
        • Allowed Headers
        • Actions
        • Methods
          • POST - Proxy
          • GET - Proxy
          • PUT - Proxy
          • PATCH - Proxy
          • DELETE - Proxy
        • Get Payload Hash
        • Proxy JOSE
        • Proxy WSSEC
      • Inbound Routes
        • Create an Inbound - POST
      • Payments
        • Attributes of the Request
        • Common response
        • Endpoints
          • Authorizations
          • Reversals
          • Capture
            • Capture Refunds
            • Capture Void
          • Payments
            • Payment Refunds
            • Payment Void
          • Refunds void
          • Credit
            • Credit Void
          • Get Transaction Details
        • Decision Manager
          • How it works
          • Create decision
          • Update Decision
        • Risk Payer Authentication
          • How to use it
          • 3-D Secure Flows
            • Successful Frictionless Authentication
            • Unsuccessful Frictionless Authentication
            • Attempts Processing Frictionless Authentication
            • Unavailable Frictionless Authentication
            • Rejected Frictionless Authentication
            • Authentication not available on Lookup
            • Enrollment check error
            • Time-out
            • Bypassed Authentication
            • Successful Step-Up Authentication
            • Unsuccessful Step-Up Authentication
            • Unavailable Step-Up Authentication
            • Require Method URL
        • Point of Sale Payments
          • Authorization
          • Capture
          • Payment
          • Credit
  • 📖Guides
    • Firstoken Captures Hosted Iframe
      • How Firstoken Captures works
      • Generating a JSON Web Token
      • JSON form Schema
      • Iframe Communication
    • De-scoping Components
      • How Firstoken De-scoping Components works
      • Inbound Routes Module
        • Create an Inbound Route
        • Edit an Inbound Route
        • Delete an Inbound Route
      • Webhook Module
        • Create a Webhook
        • Edit a Webhook
        • Delete a Webhook
        • Webhook events
        • How to sign Webhooks data
      • Proxy Module
        • Create a Proxy
        • Edit a Proxy
        • Delete a Proxy
    • Firstoken Captures SDK JS
      • Getting Started
      • Functions
      • Type of Elements
      • Elements Options
      • CSS Object
      • Full Example of Usage
      • SDK versions
Powered by GitBook
On this page

Was this helpful?

  1. Guides
  2. Firstoken Captures SDK JS

Full Example of Usage

PreviousCSS ObjectNextSDK versions

Last updated 7 months ago

Was this helpful?

We have prepared a convenient code example with popular field configurations, ready for immediate use.


<script src="https://cdn.firstoken.co/captures/js/2.2/sdk.js"></script>
<form id="collect-form" method="post">
  <div class="form-field-group ">
    <div id="cc-holder" class="form-field regular-field"></div>
    <div id="cc-number" class="form-field regular-field"></div>
    <div class="two-column">
      <div id="cc-expiration-date" class="form-field min-field"></div>
      <div id="cc-cvv" class="form-field min-field"></div>
    </div>
  </div>
  <button type="submit" class="form-button"> Continuar</button>
</form>
* {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
      font-size: 13.3px;
      font-family: 'Roboto', sans-serif;
    }

    body {
      background-color: #F5F5F5;
    }

    svg {
      width: 175px;
      height: 40px;
    }

    .banner {
      min-width: 100%;
      height: 60px;
      padding: 15px 10% 20px 10%;
      background-color: #fff;
    }

    button {
      background: #0099df;
      border-radius: 4px;
      color: #fff;
      border: none;
      outline: 0;
      width: 105px;
      height: 44px;
      line-height: normal;
      text-align: center;
      font-size: 16px;
      display: table
    }

    form {
      padding-top: 3%;
      margin: 0 auto;
      display: flex;
      width: 500px;
      flex-direction: column;
      align-items: center;
    }

    form .input {
      background-color: red;
    }

    .form-field {
      width: 275px;
      height: 35px;
      position: relative;
      background: white;
      border-radius: 0px;
      border: 0.5px solid #CCCCCC;
      padding: 0 10px;
    }

    .regular-field {
      width: 100%;
      margin-right: 15px;
    }

    .form-field.regular-field:first-of-type {
      border-top-right-radius: 8px;
      border-top-left-radius: 8px;
    }

    .two-column {
      display: flex;
      width: 100%;
    }

    .min-field {
      width: 50%;
    }

    .two-column .min-field:last-of-type {
      border-bottom-right-radius: 8px;
    }

    .two-column .min-field:first-of-type {
      border-bottom-left-radius: 8px;
    }

    .form-field-group .min-field:last-of-type {
      margin-right: 0;
      margin-bottom: 20px;
    }

    .form-field:hover {
      border-color: black;
    }

    iframe {
      width: 100%;
      height: 100%;
    }

    .form-field.error {
      border-color: red;
    }

    .form-field-group {
      display: flex;
      flex-direction: column;
    }
const FT = window.FTCaptures.init("<ROUTE_ID>", "production", function (state) { });
const css = {
      "color": "#1b1d1f",
      "::placeholder": {
        "color": "lightgray"
      },
      "font-family" : "Arial"
    };
FT.field("#cc-holder", {
  type: "card-holder",
  name: "card_holder",
  placeholder: "Name on card",
  autocomplete: "cc-holder",
  errorColor: "750000",
  required: "true",
  css: css
});

FT.field("#cc-number", {
  type: "card-number",
  name: "card_number",
  placeholder: "Card Number",
  autocomplete: "cc-number",
  errorColor: "750000",
  required: "true",
  css: css,
});

FT.field("#cc-expiration-date", {
  type: "card-expiration-date",
  name: "card_expiration_date",
  placeholder: "MM / YY",
  autocomplete: "cc-expiration-date",
  errorColor: "750000",
  required: "true",
  css: css,
});

FT.field("#cc-cvv", {
  type:"card-security-code",
  name: "card_security_code",
  placeholder: "CVV",
  autocomplete: "cc-csc",
  errorColor: "750000",
  required: "true",
  css: css,
});

FTCaptures.on("cardHolderValidationFailed", function (event) {
  console.log(event.data.isValid)
});
FTCaptures.on("cardNumberValidationFailed", function (event) {
  console.log(event.data.isValid)
});
FTCaptures.on("cardExpirationDateValidationFailed", function (event) {
  console.log(event.data.isValid)
});
FTCaptures.on("cardSecurityCodeValidationFailed", function (event) {
  console.log(event.data.isValid)
});

document.addEventListener('DOMContentLoaded', function () {
  const form = document.querySelector('#collect-form');
  form.addEventListener('submit', async function (e) {
    e.preventDefault();
    try {
        const validationResults = await FTCaptures.validate("<ROUTE_ID>");

        if (!validationResults.hasErrors) {
          const tokenizationResult = await FTCaptures.tokenize("<ROUTE_ID>");
          console.log(tokenizationResult)
          form.submit();
        }
        else {
          console.log(validationResults)  
          alert("There are one or more fields with errors.")
        }
      } catch (error) {
        console.error(error);
      }
  });
});
 
📖