Tokenizing a Credit Card

Tokenizing a Credit Card

As a developer, use Stax.js to tokenize a credit card (securely store the card and receive a payment method ID for future use) in your website's payment form.

Stax.js is Stax's browser-side JavaScript library. It sends sensitive bank and card information directly from your user's browser to Stax's servers. This supports your Payment Card Industry Data Security Standard (PCI DSS) compliance efforts; it does not guarantee compliance. Consult your legal and compliance teams about your specific requirements.

Accepting a payment with a card is similar to tokenizing a card, but it also processes a payment from the tokenized card. You can also include additional details within the call to take advantage of Level 2 processing.

Support PCI Compliance Efforts

Sensitive data never touches your servers

Secure Storage

Cards are tokenized and stored securely for future use

Level 2 Processing

Support for additional payment details

Add Stax.js to your site

Add the script shown below to the <head> of your HTML file. Copy the rendered script, not this page's documentation markup.

<script src="https://staxjs.staxpayments.com/staxjs-captcha.js"></script>

Run the examples together on the same HTML page. Create the payment form from the Implementation tab before running the initialization JavaScript. Then load the card fields, register the validation handlers, define extraDetails, and register the tokenization handler, in that order. Run your JavaScript after the form's HTML so its containers and button exist.

Initialize Stax.js

Getting Your Web Payments Token

In Stax Pay, open Apps > API Keys and copy your Web Payments Token (public key). Use that value when the initialization example prompts you for it; do not enter a private API key.

Initialize your Stax.js instance with the StaxJs class using your Web Payments Token. This example prompts for your account's actual public token instead of using an invented token value:

Note: Passing the number and CVV into the Stax.js instance generates a secure iframe around these two fields, keeping sensitive card information from touching your servers.

// Copy the public token from Stax Pay > Apps > API Keys.
const webPaymentsToken = window.prompt("Enter your Web Payments Token (public key):");
if (!webPaymentsToken || !webPaymentsToken.trim()) {
  throw new Error("A Web Payments Token is required to initialize Stax.js.");
}

var staxjs = new StaxJs(webPaymentsToken.trim(), {
  number: {
    id: "card-number", // The ID of the container for the card-number field.
    placeholder: "0000 0000 0000 0000",
    style: "height: 30px; width: 100%; font-size: 15px;",
    type: "text",
    format: "prettyFormat" // Use prettyFormat, plainFormat, or maskedFormat.
  },
  cvv: {
    id: "card-cvv", // The ID of the container for the CVV field.
    placeholder: "CVV",
    style: "height: 30px; width: 100%; font-size: 15px;",
    type: "text"
  }
});

Did this page help you?