This document provides a reference implementation and explanation of how to use Atlas Interpreter on a checkout form to securely tokenize card data and submit transactions to the Expitrans Atlas API.
gw:token-ready and gw:token-error events and perform a tokenized payment submission.Filename: checkout.html
Purpose: Demonstrates how to build a fully functional checkout form integrated with the Atlas payment gateway using token-based transactions.
<script src="https://[gateway_url]/atlas/gateway.js"></script>
This script securely mounts the payment card input fields and handles token generation. It triggers the gw:token-ready event once a card token is successfully created. On validation or tokenization failure, it emits gw:token-error and a client-side token-null event for form validation failures.
The gateway_url should be set depending on your environment:
| Environment | Gateway URL |
|---|---|
| Sandbox | develop.expitrans.com |
| Production | secure.troute.io |
When integrating, always confirm which environment you are pointing to before submitting live transactions.
Script include: Load gateway.js from the Atlas-hosted domain for your environment (develop.expitrans.com or secure.troute.io). Do not self-host the interpreter in production.
The checkout form (#payment-form) includes required and optional fields for billing, shipping, and transaction details.
[
{"productname": "Widget A", "description": "Blue widget", "qty": 2, "unitprice": 5.00},
{"productname": "Service B", "description": "Setup fee", "qty": 1, "unitprice": 25.00}
]
| Field | Name | Description |
|---|---|---|
#gw-token | token | Populated automatically when the card token is generated |
#gw-merchant | merchant | Merchant identifier |
#gw-login | x_login | Gateway login ID |
#gw-trankey | x_tran_key | Gateway transaction key |
#gw-transtype | transtype | Optional. Transaction type (e.g., AUTH_CAPTURE, AUTH_ONLY). Defaults server-side to AUTH_CAPTURE. |
loginInput.value = "DEMO";
trankeyInput.value = "PASSWORD";
x_tran_key should be securely stored on the server and never exposed in client-side JavaScript.
<div id="gateway-card-container"></div>
When the card is successfully tokenized, the script dispatches:
window.dispatchEvent(new CustomEvent('gw:token-ready', { detail: { token } }));
On failure, the script dispatches:
window.dispatchEvent(new CustomEvent('gw:token-error', { detail: { status, error } }));
window.dispatchEvent(new CustomEvent('token-null', { detail: { message: 'Input validation failed.' } }));
Atlas mounts card fields using consistent class names. You can style them to fit your brand while preserving usability and validation feedback.
| Element | Class | Description |
|---|---|---|
| Wrapper | .gw-field | Block wrapper for each card input |
| Input | .gw-input | Text inputs for card number, exp month/year, CVC |
| Error | .gw-error | Inline error message under each field and form-level |
| Messages wrapper | .gw-field-messages | Form-level message container used for general errors |
| Card number input | .gw-card-number | Specific input for card number (numeric only) |
| Exp month input | .gw-exp-month | Two-digit month (01–12) |
| Exp year input | .gw-exp-year | Two-digit year (YY) |
| CVC input | .gw-cvc | 3–4 digit card code |
| Container | #gateway-card-container | Mount point where the fields are injected |
Example CSS:
.gw-field { margin: 8px 0; }
.gw-field label { display: block; font-weight: 600; margin-bottom: 6px; }
.gw-input { box-sizing: border-box; width: 280px; padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 14px; }
.gw-input:focus { outline: none; border-color: #0066cc; box-shadow: 0 0 0 3px rgba(0,102,204,0.15); }
.gw-error { color: #b00020; display: block; margin-top: 4px; font-size: 12px; }
.gw-field-messages .gw-error { margin-top: 8px; }
.gw-row { display: flex; gap: 16px; flex-wrap: wrap; }
.gw-row .gw-field { flex: 1 1 140px; min-width: 140px; }
Visibility control: The interpreter toggles error visibility via the hidden attribute and inline display style to ensure consistency across themes. Avoid overriding these directly; instead customize colors, spacing, and focus states.
When gw:token-ready is triggered:
fetch('https://[gateway_url]/atlas/transact_token.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-App-Source': 'domain.com/checkout.html'
},
body: JSON.stringify(payload)
});
When gw:token-error or token-null is triggered, surface validation or tokenization errors inline on the page without alerts.
{
"token": "string",
"amount": "10.00",
"merchant": "TWINOAKSPLACE",
"x_login": "DEMO",
"x_tran_key": "PASSWORD",
"transtype": "AUTH_CAPTURE",
"billing": {
"first_name": "John",
"last_name": "Doe",
"address": "123 Street",
"city": "Los Angeles",
"state": "CA",
"zip": "90001",
"country": "USA",
"email": "john@example.com",
"notes": "Optional notes here",
"company": "Acme Inc",
"phone": "+1-555-555-5555",
"shipping_first_name": "Jane",
"shipping_last_name": "Doe",
"shipping_address": "456 Avenue",
"shipping_city": "Los Angeles",
"shipping_state": "CA",
"shipping_zip": "90002",
"shipping_country": "USA",
"shipping_phone": "+1-555-555-0000",
"shipping_email": "jane@example.com",
"surcharge_amount": "0.50",
"tax_amount": "0.75",
"shipping_amount": "5.00",
"discount_amount": "1.00",
"customer_id": "CUST-123",
"subscription_id": "SUB-456",
"custom_fields_1": "Blue",
"custom_fields_2": "Promo-2025",
"custom_fields_3": "Department-7",
"custom_fields_4": "",
"custom_fields_5": "",
"custom_fields_6": "",
"custom_fields_7": "",
"custom_fields_8": "",
"custom_fields_9": "",
"custom_fields_10": "",
"line_items": "[{\"productname\":\"Widget A\",\"description\":\"Blue widget\",\"qty\":2,\"unitprice\":5.00}]"
}
}
URL: https://[gateway_url]/atlas/transact_token.php
Method: POST
Content-Type: application/json
X-App-Source: domain.com/checkout.html
X-App-Source header to match your actual domain or app name, e.g. 'shop.example.com/checkout'.
The Atlas endpoint validates the token, processes the transaction, and returns a response. Responses may be JSON or Authorize.Net–style CSV. Parse JSON when available and fall back to raw text if needed for diagnostics.
The script handles:
data.error).token-null) and tokenization failures (via gw:token-error).<div id="result"></div>
gw:token-ready fires → script prepares the transaction payload./transact_token.php.X-App-Source in your backend logs for traceability.