Stax.js
Initialize Stax.js with your sandbox Web Payments Token and understand tokenization and embedded reCAPTCHA protection.
Stax.js
Add browser-based payment collection to your platform.
Initialize Stax.js in your website to prepare for collecting and tokenizing payment information (replacing sensitive payment details with a token you can use for future payments).
This guide is for developers integrating Stax.js, Stax’s browser-side JavaScript library. Stax.js sends sensitive payment information from your customer’s browser to Stax rather than through your servers. You can use payment tokens for one-time payments, recurring payments, or later charges to a stored payment method.
Prepare your sandbox credentials
- Sign in to your Stax sandbox account so you can test the integration before using it for live payments.
- In Stax Pay, open Apps > API Keys and copy your Web Payments Token (public key). Use this public key in your browser code, not a private API key.
1. Load Stax.js
Add the following script tag inside the <head> element of your HTML file. Load it before the initialization code in the next step so the StaxJs constructor is available.
<script src="https://staxjs.staxpayments.com/staxjs-captcha.js"></script>2. Initialize Stax.js
Add the following HTML inside the <body> element of the same file. Replace the illustrative fact_test_123 value with the Web Payments Token you copied. The dummy value is not a usable credential.
Use an empty options object ({}) for this initialization-only example; it does not configure payment fields or process a payment.
<p id="stax-status" role="status">Initializing Stax.js…</p>
<script>
// Copy your public Web Payments Token from Stax Pay > Apps > API Keys.
const webPaymentsToken = "fact_test_123";
const statusElement = document.getElementById("stax-status");
try {
if (!webPaymentsToken.trim() || webPaymentsToken === "fact_test_123") {
throw new Error("Replace the example token with your sandbox Web Payments Token.");
}
if (typeof StaxJs !== "function") {
throw new Error("Stax.js did not load. Check the script request in your browser's Network panel.");
}
const staxjs = new StaxJs(webPaymentsToken, {});
statusElement.textContent = "Stax.js instance created. No payment has been processed.";
} catch (error) {
statusElement.textContent = error instanceof Error
? error.message
: "Stax.js initialization failed. Check your browser console for details.";
console.error("Stax.js initialization failed:", error);
}
</script>Open the file in your browser. After you replace the dummy token and the constructor completes without an error, the page displays:
Stax.js instance created. No payment has been processed.This message confirms local instance creation, not credential validation or payment readiness. If you leave the dummy token unchanged or omit the token, the page asks you to replace it. If the library fails to load, check the script request in your browser’s Network panel and confirm the loading tag precedes the initialization code.
Next, follow Tokenizing a Credit Card to configure payment fields and create a payment token.
Understand embedded reCAPTCHA protection
Stax.js embeds Google’s reCAPTCHA technology into its payment form to help detect automated abuse before payment information is tokenized. The script used above includes this protection; this guide does not require a separate reCAPTCHA setup step.
This protection supports your compliance efforts; it does not guarantee fraud prevention or replace your Payment Card Industry Data Security Standard (PCI DSS) compliance responsibilities. Consult your compliance or legal team about the requirements that apply to your integration.
Updated 5 days ago
