Arc Pay JavaScript SDK
Browser and server SDK for Arc Pay integrations.
Install
npm install @thavguard/arc-pay
Browser SDK
import { ArcPay } from "@thavguard/arc-pay/js";
const arcpay = await ArcPay.load("pk_test_...");
const elements = arcpay.elements();
ArcPay.load() takes the publishable key as the first argument. Sandbox/live is
inferred from the key prefix (pk_test_ or pk_live_). Hosted Fields are served
from https://sdk.arcpay.space and tokenize against the Arc Pay public API
configured for that iframe app.
Script tag builds
dist/cdn/arcpay.global.js is the full browser bundle (window.ArcPay.ArcPay, confirmPayment,
3DS actions, customer transfers). If a page only mounts Hosted Fields, load
dist/cdn/arcpay.fields.global.js instead: the same ArcPay.ArcPay.load(...) and
ArcPay.ArcPayError, about 38% smaller gzipped (7.5 KB instead of 12.1 KB). Bundler users
need neither: the package is side-effect free and tree-shakes.
React Bindings
import { ArcPayProvider, useArcPay } from "@thavguard/arc-pay/react";
Server SDK
import { createArcPayClient } from "@thavguard/arc-pay/server";
const client = createArcPayClient({
secretKey: "sk_test_...",
timeoutMs: 30_000,
maxNetworkRetries: 1,
});
Amounts are integer minor units. Never pass card PAN or CVV to server APIs; use Hosted Fields for browser card entry.
Browser pages using Hosted Fields must allow frames from https://sdk.arcpay.space
and API connections to https://api.arcpay.space. If your Content Security
Policy also governs telemetry, allow connections to your configured Sentry ingest
host or disable browser telemetry at your application layer.
Card data never goes to the API host. When card data is posted straight from the
page (for example the customer-transfer session client), the page must also
allow the card-entry origin in connect-src. The host comes from the
card_entry_url in the ticket response: https://cards.arcpay.space in
production, https://dev-cards.arcpay.space:30444 on dev and
https://debug-cards.arcpay.space:30444 on debug. Hosted Fields keep card data
inside the https://sdk.arcpay.space iframe, so the merchant page needs only
the frame-src and API connect-src entries above.
Hosted Fields performs a browser settings check against Arc Pay API before
mounting fields. That check is internal to the SDK; merchants should configure
CSP for the public origins above, not call the settings endpoint directly.
Client-side validation can reject a card before any request with the local
codes invalid_card_number, invalid_cvv, invalid_expiry and card_expired
(expiry month already past); these are raised by the SDK, not returned by the API.
Tokenization is two requests from https://sdk.arcpay.space: a ticket request to the
public API (POST /payments/{id}/card-entry-ticket, no card data, authenticated
with the publishable key), then the card itself straight to the card-entry
endpoint named in the ticket response (X-Card-Entry-Ticket and Content-Type
headers only). Card data never reaches the public API host or the merchant page.
Hosted Fields formats buyer input inside the secure iframe: card numbers are
grouped with spaces and expiry dates are displayed as MM/YY. The tokenization
request strips those separators before sending PAN and expiry to Arc Pay, so
merchant code should not read, mirror, or reformat card details outside the
iframe.
Hosted Fields appearance
Hosted Fields are secure iframe inputs. The merchant page owns layout and
container styling: labels, wrappers, spacing, borders, shadows, error text, and
the submit button should be regular merchant CSS. Arc Pay only styles the input
text inside each iframe through a typed, allowlisted appearance contract.
const elements = arcpay.elements({
appearance: {
variables: {
fontFamily: "Inter, system-ui, sans-serif",
fontSize: "16px",
lineHeight: "24px",
colorText: "#111827",
colorPlaceholder: "#9ca3af",
colorDanger: "#dc2626",
caretColor: "#111827",
border: "0",
borderRadius: "6px",
boxShadow: "none",
height: "44px",
padding: "10px 12px",
outline: "none",
},
rules: {
focus: { "font-weight": "600" },
invalid: { color: "#dc2626" },
complete: { color: "#047857" },
},
},
});
const card = elements.create("card", {
placeholder: "1234 1234 1234 1234",
appearance: {
rules: {
base: { "font-weight": "500" },
},
},
});
card.mount("#card");
For full merchant-owned layout control, use split Hosted Fields. Each field is a
separate secure iframe, so merchant CSS controls the outer grid, spacing,
labels, and wrappers independently:
const elements = arcpay.elements({ appearance });
const cardNumber = elements.create("cardNumber", {
placeholder: "1234 1234 1234 1234",
});
const cardExpiry = elements.create("cardExpiry", { placeholder: "MM/YY" });
const cardCvv = elements.create("cardCvv", { placeholder: "CVV" });
cardNumber.mount("#card-number");
cardExpiry.mount("#card-expiry");
cardCvv.mount("#card-cvv");
const token = await elements.tokenize(paymentId, idempotencyKey);
The caller owns idempotencyKey: generate one key for each payment and
tokenization attempt, then pass that same key when replaying an unresolved
request. If the outcome is unknown (for example, a timeout), reconcile the
payment before deciding what to do next; a retryable error must replay with the
same key and must not silently start a fresh authorization. Generate a new key
only for an explicitly new payment attempt or a different paymentId.
Do not mix card with split fields in one Elements instance. In split mode,
PAN, expiry, and CVV are still kept inside Arc Pay iframes and synchronized only
over the Arc Pay same-origin channel for tokenization; merchant JavaScript
receives readiness, focus, validation, brand, and tokenization result events,
not raw card data. Split fields require browser BroadcastChannel support.
The channel is restricted to the Arc Pay iframe origin and the current top-level
site partition; merchant-provided MessagePorts are never used for field values.
Fonts and numerals
Hosted Fields run in their own origin with font-src 'self', so @font-face
rules and font URLs from the merchant page cannot reach them. Fonts are
therefore served by Arc Pay: reference a bundled family by name in
fontFamily / font-family and add a fallback stack.
Bundled families: Geologica and Inter (Latin, Latin Extended, Cyrillic,
Cyrillic Extended; variable weight 100-900). Both have tabular numerals. Only
the subsets a field actually needs are downloaded, and the digit subset is
fetched before ready so numbers are not first painted in a fallback font.
const elements = arcpay.elements({
appearance: {
variables: {
fontFamily: "Geologica, system-ui, sans-serif",
fontWeight: "400",
fontVariantNumeric: "tabular-nums", // fixed-width digits while typing
},
rules: {
// any allowlisted property is also available per state
focus: { "font-feature-settings": '"tnum" 1' },
},
},
});
font-variant-numeric, font-feature-settings and color-scheme are part of the allowlist
(HostedFieldsStyleProperty). The arcpay theme enables tabular-nums by
default; the default theme "none" leaves numerals untouched. Style values
that load resources (url(...), image-set(...), @import) or exceed 512
characters are dropped.
Hosted Fields options
Every option below is optional, can be set for all fields in
arcpay.elements({...}) and overridden per field in elements.create(field, {...}),
and can be changed later with element.update({...}). Invalid values throw an
ArcPayError (invalid_hosted_fields_option) before anything is mounted.
| Option |
Default |
Effect |
locale |
"auto" |
"ru", "en" (region tags such as ru-RU are accepted) or the browser language for default texts, errors and help. |
texts.placeholders / texts.labels |
localized |
Per input: cardNumber, cardExpiry, cardCvv. |
texts.errors |
localized |
issue.message and the screen-reader error by issue code (HOSTED_FIELD_ISSUE_CODES). |
layout |
10px / 74px / 64px |
Composite card only: gap, expiryWidth, cvvWidth (0 or px, rem, em, %). |
minHeight |
"44px" |
Minimum iframe height. |
mountTimeoutMs |
10000 |
Wait for the iframe handshake before loaderror (iframe_ready_timeout); 3000-120000. Raise it for slow networks. |
disabled, readOnly |
false |
Standard input states; style them with rules.disabled. |
autofocus |
false |
Focus the field once it is ready. |
autoAdvance |
false |
Move to the next field once one is complete and valid (composite and split). |
showBrandIcon |
false |
Neutral brand badge inside the number input (Visa, Mastercard, Mir, Amex, Maestro, UnionPay, JCB, Discover, Diners). |
maskCvv |
true |
false shows the security code as digits. |
expiryYearFormat |
"YY" |
"YYYY" displays and accepts MM/YYYY. |
const elements = arcpay.elements({
locale: "ru",
showBrandIcon: true,
autoAdvance: true,
texts: { errors: { card_number_invalid: "Проверьте номер карты" } },
});
const card = elements.create("card", { layout: { gap: "8px", cvvWidth: "5rem" } });
card.on("submit", () => pay()); // Enter pressed inside a field; no card data
card.update({ disabled: true });
Appearance gains rules.disabled, rules.hover and rules.autofill (browser
autofill no longer paints its own background over your style) and
theme: "arcpay-dark". issue.message and help.message follow locale; use
issue.code for logic.
New element events: loading (mounted, waiting for the handshake), submit and
escape (Enter/Escape inside a field). The factory emits tokenizing,
tokenized and tokenizeerror through elements.on(...), and
elements.tokenize(paymentId, idempotencyKey, { timeoutMs }) accepts
1000-120000 ms (default 30000).
Behaviour that now applies to everyone: a lone month digit 2-9 becomes 0X/,
Backspace can delete past the / and spaces, the security code length follows
the brand (Amex 4, other known brands 3; split mode checks it at tokenize()),
Amex numbers must be 15 digits, expiry years more than 20 years ahead are
rejected (card_expiry_too_far), and a placeholder given to a split
cardExpiry / cardCvv element is now honored.
Dark and tinted checkouts
The secure iframe never paints a background of its own: html and body inside it
are transparent, and only the input takes colors from appearance. For a dark
checkout use theme: "arcpay-dark" (or set colorText, colorPlaceholder and
colorBackground yourself) and declare the same scheme on your page
(html { color-scheme: dark }) or pass "color-scheme": "dark" in rules.base:
when the embedding page and the iframe disagree about the color scheme, browsers
paint an opaque backdrop behind the iframe.
Narrow containers and local development
The composite card element shrinks its expiry and code columns below 340px so a
16-digit number stays readable; explicit layout values are never overridden. For
very small widths the split fields (separate iframes) give you full control.
Hosted Fields are served with a strict frame-ancestors policy per merchant
origin, and the edge refuses http://localhost and http://127.0.0.1 as parent
origins in every environment. Develop against an https:// origin (for example a
local TLS proxy or a staging host) and add it to the allowed origins of the test
merchant.
appearance.theme defaults to "none" so Arc Pay branding is not imposed on
merchant checkout pages. theme: "arcpay" is available for demos and quick
starts. Supported iframe properties are limited to input-level text, color,
caret, placeholder, opacity, background, border, outline, shadow, padding,
height, and box sizing. This supports flat, bordered, and underline-only fields
without cropping the iframe or breaking text centering. Container CSS such as
margin, position, transform, z-index, and background images is intentionally
dropped. The exported HostedFieldsStyleProperty and HostedFieldsStyleBlock
types expose the same allowlist to TypeScript integrations. Use element change
events (isEmpty, isComplete, isValid, brand, lastFour) to style your
own wrappers.
@thavguard/arc-pay/server intentionally does not expose tokenizeCard().
Tokenization belongs to Hosted Fields. Direct browser calls with a publishable
key are only for explicitly approved raw-card forms; those forms handle
cardholder data in the merchant environment and require the applicable PCI DSS
controls before live traffic. Keep sk_* keys on your backend for payment
creation, execution, capture, void, refund, saved-card charges, payment links,
and checkout sessions.
Mutating server-client methods require an explicit { idempotencyKey }:
createPayment, createCardSetup, executePayment, capturePayment, voidPayment,
createRefund, chargeSavedCard, completeThreeDSMethod, createLink,
cancelLink, and createCheckoutSession. Missing idempotency raises
ArcPayError with code="missing_idempotency_key" before any HTTP request is
sent.
The server client sends User-Agent: ArcPay-JS/<version> and retries transient
network/API failures only when the request is safe to retry: GET requests or
mutating requests with an explicit idempotency key. Arc Pay timeout responses
are not retried automatically because they mean the payment is pending
confirmation; keep the same order waiting, poll GET /payments/{id}, and rely
on webhooks or reconciliation. Configure timeoutMs, maxNetworkRetries, and
retryDelayMs on the client when your backend needs stricter operational
limits.
H2H card payments require HTTPS success_url and fail_url on
createPayment. Arc Pay stores those URLs on the payment and redirects the
buyer back to the stored merchant URL after ACS authentication. Treat the browser
return as navigation only; confirm the final status through webhooks or
GET /payments/{id}.
H2H card execution returns a standardized next_action when the buyer must do
something in the browser. The shape is bank-agnostic: integrations branch only
on next_action.type, next_action.three_ds.phase, and Arc Pay payment
statuses. Do not branch on Sber, PSB, Alfa, Tinkoff, or any other adapter field.
browser_info is optional on the wire: every field may be omitted and Arc Pay
fills defaults and normalizes the values server-side (see the H2H guide).
collectBrowserInfo() still gathers the real browser values, which gives the
issuer the best frictionless decision.