Stax.js General Information / FAQ

Use Stax.js to store a customer's payment details or take a payment while controlling customer matching, billing addresses, and receipts.

Tokenization securely stores payment details and returns a payment method ID you can use later instead of handling the card number yourself. Call .tokenize() to store the payment method without charging it, or .pay() to store it and attempt a payment.

Respect request limits

When you call .pay() or .tokenize(), Stax.js calls the Stax API using your Web Payments Token (public key). These requests are limited to 10 requests per minute per IP address. Prevent duplicate submissions and avoid immediate retry loops when a request fails.

Check the payment result

The .pay() method returns an Invoice object with a PAID or ATTEMPTED status. Treat PAID as success; do not show a successful-payment message for ATTEMPTED. See the Invoice API for more about statuses.

Control payment receipts

Set send_receipt in the extraDetails object you pass to .pay(). It defaults to true and sends an email for both successful and unsuccessful payment attempts. If Stax matches an existing customer who has an email address, that customer email receives the receipt.

Recommended starting settings are validate: true to validate submitted details and send_receipt: true when taking payments so customers receive the outcome. These are integration recommendations, not a statement of compliance requirements.

FieldTypeDefaultBehavior and constraints
validatebooleanNot specified here; set explicitly to trueEnables Stax.js validation of submitted details.
send_receiptbooleantrueControls receipt emails for .pay(), including unsuccessful attempts.
match_customerbooleanMatching is enabled unless disabledSet to false only when you intentionally want to disable demographic matching.
customer_idstringOmittedMust identify a customer in your merchant account. When supplied, Stax uses that customer instead of demographic matching or customer creation.

Match an existing customer

When you call .tokenize() or .pay() without a customer_id, the API attempts to match an existing customer using these groups of fields:

  • email
  • company, address_1, and address_city
  • firstname and phone
  • firstname, lastname, address_1, and address_zip
  • lastname and phone

Every field in a group must exist and match exactly. For example, Bob Smith at 123 North Way, ZIP code 32801, does not match Bobby Smith at 123 Noth. Way, ZIP code 32801. When a group matches, Stax links the existing customer to the new payment method and, for .pay(), the transaction.

Additional customer details do not update the matched customer. For example, if Stax matches [email protected] and you also supply an address, Stax does not add that address to the existing customer record.

To disable demographic matching intentionally, set match_customer to the boolean false in extraDetails. This setting controls matching, not card security validation; keep validate: true.

Optional: Use a known customer ID

Create a customer through the API first, then pass the returned customer id as the string value of customer_id in extraDetails. You can also obtain customer_id from a successful .tokenize() response. Use the actual ID from your merchant account, not an invented value.

For example, "cd10fbd4-199c-4753-8db8-66c4e2c2b4e8" illustrates the ID format shown in the tokenization response example; it is not an ID to reuse in requests. customer_id is a parameter name, not a placeholder to replace in source code.

Both .pay() and .tokenize() accept customer_id. When you supply it, Stax uses that customer for the new payment method and, for .pay(), the invoice and payment, instead of creating or matching a customer. Customer fields such as name, phone, and address are ignored when you supply customer_id. This also lets you implement your own matching and pass the exact customer ID.

Optional: Supply a billing address

Pass billing address fields in the extraDetails object you provide to .tokenize() or .pay(). Stax.js sends them to its tokenization service (the service that stores payment details and returns a payment method ID). The address can be saved with the payment method and a new customer; it does not update an existing matched customer, and supplying customer_id causes customer address fields to be ignored.

FieldTypeConstraint
address_1stringMaximum 255 characters.
address_2stringOptional; maximum 255 characters.
address_citystringMaximum 55 characters.
address_statestringTwo-letter code, such as "FL".
address_zipstringSupply the billing ZIP or postal code.
address_countrystringSupply the billing country; the example uses "USA".

These fields have no default address values. When you enable validation and omit customer_id, address_1, address_city, and address_state are required along with the other required customer details. See Stax.js Validation.

To update the payment method's billing address later, send a server-side PUT request to the payment-method resource using your private API key and the payment method id returned by .tokenize(). For example, /payment-method/2e34394f-5f1d-4ec0-a56d-f669509a5b13 illustrates a concrete path using the documented sample ID; replace that sample ID with your response's id. Never put your private API key in browser code.

Optional: Run a complete tokenization example

This browser example stores a card without charging it. It enables validation, leaves customer matching enabled, and disables duplicate submissions while a request is running.

  1. In Stax Pay, open Apps > API Keys and copy your Web Payments Token (public key), not your private API key.
  2. Save the HTML below and serve it from your website. Enter your public token when prompted.
  3. Enter the card number and CVV (the card's security code) in the hosted fields. The example uses the sample customer's billing details and an October 2030 expiration date; update these values to match your test scenario before submitting.
  4. Click Tokenize after the card fields are complete. Use a test card with an unexpired date when testing.
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Stax.js tokenization example</title>
  <script src="https://staxjs.staxpayments.com/staxjs-captcha.js"></script>
</head>
<body>
  <p>Card number</p>
  <div id="card-number" style="width: 250px; height: 30px;"></div>
  <p>CVV</p>
  <div id="card-cvv" style="width: 80px; height: 30px;"></div>
  <button id="tokenize" type="button" disabled>Tokenize</button>
  <p id="status" role="status">Loading card fields…</p>
  <script>
    const button = document.querySelector("#tokenize");
    const status = document.querySelector("#status");
    let complete = false;
    let pending = false;
    const updateButton = () => {
      button.disabled = pending || !complete;
    };

    async function initialize() {
      try {
        // Use the public token from Stax Pay > Apps > API Keys.
        const token = window.prompt("Enter your Web Payments Token (public key):");
        if (!token || !token.trim()) {
          status.textContent = "No token entered. Reload to try again.";
          return;
        }
        const staxjs = new StaxJs(token.trim(), {
          number: {
            id: "card-number",
            placeholder: "0000 0000 0000 0000",
            style: "height: 30px; width: 100%;",
            type: "text",
            format: "prettyFormat"
          },
          cvv: {
            id: "card-cvv",
            placeholder: "CVV",
            style: "height: 30px; width: 100%;",
            type: "text"
          }
        });
        staxjs.on("card_form_uncomplete", () => {
          complete = false;
          updateButton();
        });
        staxjs.on("card_form_complete", () => {
          complete = true;
          updateButton();
        });
        await staxjs.showCardForm();
        status.textContent = "Enter your card details to continue.";

        button.onclick = async () => {
          if (pending || !complete) return;
          pending = true;
          updateButton();
          status.textContent = "Tokenizing…";
          try {
            const paymentMethod = await staxjs.tokenize({
              method: "card",
              firstname: "John",
              lastname: "Doe",
              month: "10",
              year: "2030",
              phone: "5555555555",
              address_1: "100 S Orange Ave",
              address_2: "Suite 400",
              address_city: "Orlando",
              address_state: "FL",
              address_zip: "32811",
              address_country: "USA",
              validate: true
            });
            if (!paymentMethod || !paymentMethod.id || !paymentMethod.customer_id) {
              status.textContent = "Unexpected response: missing payment method or customer ID. Review before retrying.";
              return;
            }
            // These IDs come from the response, not a Dashboard placeholder.
            status.textContent = `Card stored. Payment method: ${paymentMethod.id}; customer: ${paymentMethod.customer_id}. No payment was taken.`;
          } catch (error) {
            status.textContent = "Tokenization failed. Review the error and correct the details before retrying.";
            console.error("Tokenization failed:", error);
          } finally {
            pending = false;
            updateButton();
          }
        };
      } catch (error) {
        button.disabled = true;
        status.textContent = "Unable to load card fields. Check your public token and network connection, then reload.";
        console.error("Stax.js initialization failed:", error);
      }
    }
    initialize();
  </script>
</body>
</html>

On success, the page displays Card stored. Payment method: followed by the returned payment method ID and customer ID, ending with No payment was taken. If the card fields remain incomplete, the button stays disabled. If initialization or tokenization fails, the page displays an error; inspect the browser console, correct the cause, and avoid repeated requests that exceed the rate limit.

Understand compliance responsibilities

Stax.js sends sensitive card information directly from the browser to Stax using hosted card fields. This supports your Payment Card Industry Data Security Standard (PCI DSS) compliance efforts; it does not guarantee compliance or replace applicable requirements.

Treat required API fields and applicable compliance requirements separately from recommendations such as enabling validation and preventing duplicate submissions. This FAQ does not determine which compliance requirements apply to your integration. Consult your legal and compliance teams regarding specific requirements.

After tokenization succeeds, save the returned payment method ID and customer ID in your application's records for future use. Tokenization alone does not take a payment; when you use .pay(), confirm the returned invoice status is PAID before showing payment success.


Did this page help you?