Skip to main content

Card Tokenization with EBANX.js

EBANX card tokenization is a process that securely replaces sensitive payment information, like credit card numbers, with a unique token. This token can be stored and reused for future payments without exposing sensitive card data, helping you comply with PCI DSS regulations. For you as a merchant, this means you can offer a faster checkout experience for returning customers and handle recurring payments securely, all while reducing your risk of handling sensitive information directly. Tokenization ensures that payment data is protected, simplifying your security requirements and improving the customer experience. This page explains how to create a credit card token.

Tokenization methods

There are two options to create a token.

MethodDescriptionSide
EBANX.jsGenerate the token on the client side using the EBANX.js JavaScript library, and then send the token in your API call.Client Side
Direct APIUse the Direct API to generate the token server-side and include it in your payment request.Server Side

Requirements

  • Credentials
    • If using EBANX.js
      • You'll need your EBANX.js Public Integration Key, which can be found in your EBANX Dashboard.
      • If you don't have it, complete the Merchant Signup Form.
    • If using Direct API

Instructions


Method 1 - Create a token using EBANX.js

  1. Install EBANX.js

    Insert script tag

    Add the following to your HTML.

    <script type="text/javascript" src="https://ebanx-js.ebanx.com/latest/dist/ebanx.min.js"></script>

    Initialize

    Include the following function in your JavaScript.

    EBANX.init({
    publicIntegrationKey: '{your_public_integration_key}',
    country: '{country_code_here}',
    mode: 'test',
    });

    Initialization parameters

    FieldDescription
    publicIntegrationKeyMerchant's public integration key
    countryCustomer country code.
    2-digit String
    International standard - ISO 3166-1 alpha-2
    modetest or production
  2. Create object with payment information

    Include the following fields:

    // Payment Information object
    const tokenizeOptions = {
    card: {
    number: '4111111111111111',
    dueDate: '12/2025',
    holderName: 'JOAO DA SILVA',
    },
    paymentTypeCode: 'creditcard',
    countryCode: 'br',
    };
  3. Create token

    Call the EBANX.cardTokenizer.tokenize function, passing the object created in the previous step.

    EBANX.cardTokenizer
    .tokenize(tokenizeOptions)
    .then((tokenizedCard) => {
    // use tokenizedCard to fullfil payment
    })
    .catch((error) => {
    // handle errors
    });

    EBANX.cardTokenizer.tokenize returns a Promise. Handle the asynchronous call with a callback function.

    // Example - tokenizedCard
    {
    payment_type_code: 'visa';
    token: 'c7957fc8d0e92c8fa859120ccbf24ef03486dc2cbc9081447bf883a6c495c71fdcd85b77db23373ae3ab76910a8857eb7788540c190a7160195d51de016699f6';
    }
  4. Add token to Direct API payment request

    Use the EBANX Direct API to create a payment request.

    Include the token from previous step to the card object in your API call.

    Examples

    -Using Spread Operator:

    // payment.card object in your EBANX Direct API request

    "payment" : {
    "card": {
    ...tokenizedCard // Spread Operator
    }
    }

    -Older Javascript:

    // payment.card object in your EBANX Direct API request

    "payment" : {
    "card": {
    'payment_type_code': 'visa';
    'token': 'c7957fc8d0e92c8fa859120ccbf24ef03486dc2cbc9081447bf883a6c495c71fdcd85b77db23373ae3ab76910a8857eb7788540c190a7160195d51de016699f6';
    }
    }
  5. Congratulations!

    You have succesfully created a token using EBANX.js.

Resources

Use the following resources when testing in Sandbox Mode. All transactions in sandbox mode simulate real transactions, but no actual funds are moved.



Importing Tokens

If you need to import existing tokens from another provider, you’ll need to export them securely using encryption. Use the following public key to encrypt the files from your current provider before sending them to EBANX:

Still need help?

Help Image

We hope this article was helpful. If you still have questions, you can explore the following options: