Skip to main content
Card elements let you embed secure card input fields in your own page. Each field runs in a cross-origin iframe — raw card data never exists in your JavaScript or reaches your server.

Field Types


Creating and Mounting

OzVault.create() is the async static factory — call it once when your checkout loads. It resolves once the session is initialized; mount elements immediately after. The vault is ready to tokenize once onReady fires (or vault.isReady === true). Gate your submit button on both vault readiness and field readiness.
Each mounted field renders as a 46 px tall iframe. The SDK sets that height automatically — you don’t need to set a height on the wrapper <div>. Just make sure the wrapper has visible width and is not hidden with overflow: hidden or height: 0, or the field will be invisible. You can also pass element options at creation time:

createElement Options


Tokenizing

Call createToken() after the user has filled all fields. The SDK transmits the field values directly to the Ozura Vault API — raw data never passes through your code.

createToken options

TokenResponse

cvcSession is always present on a successful tokenization. The SDK validates this field before resolving createToken() — if it is absent the promise rejects with an OzError (errorCode: 'server'), which would indicate a vault misconfiguration. Always forward both token and cvcSession to your charge endpoint:
cvcSession lifecycle. The cvcSession is a short-lived vault credential that allows your server to retrieve the CVC value during a cardSale call. It shares the parent session TTL (default 30 minutes). It is safe to briefly persist it server-side — e.g. in a Redis key with a short TTL, or in a signed server-session — between the tokenization call and the charge call (seconds to minutes is fine). Do not store it long-term or log it. The vault invalidates the CVC credential after it is consumed by cardSale, so it is single-use.

BillingDetails

The SDK normalizes state to its standard 2-letter abbreviation for US and Canadian addresses. Full names (e.g. "California", "British Columbia") and 2-letter codes are both accepted. For country: 'US', the state must be a valid US state, territory (PR, GU, VI, AS, MP), or military address code (AE, AP, AA) — other values are rejected. For country: 'CA', the state must be a valid Canadian province code.
cardSale requires more billing fields than tokenize-only. The OzuraPay API enforces minLength: 1 on billing fields — passing an empty string "" causes a validation error even if the field is technically optional. The SDK strips absent optional fields automatically (omits the key rather than sending ""). However, in practice cardSale typically requires email, phone, and a full address to process the charge. If any of these are missing, the OzuraPay API will return a validation error.Recommendation: For charge flows, collect email, phone, and full address from the customer and pass them in BillingDetails. For tokenize-only flows (no charging), billing can be omitted entirely — or if you want billing details echoed back in TokenResponse.billing, pass at minimum { firstName, lastName }.

Events

Each element emits events you can listen to with .on():
The expiry onChange event includes month and year values. These are parsed from the masked expiry input and delivered to your handler for display purposes (e.g. showing the detected expiry date). If your PCI scope requires zero cardholder data on the merchant page, do not read or log these fields.

Gating the submit button

The vault and each field iframe load independently. Gate your submit button on both:
  • Vault readiness — the onReady callback (fires when the vault is ready to tokenize)
  • Field readiness — each field’s 'ready' event (fires when the iframe loaded and is interactive) plus change events for completion

Teardown

When the checkout component unmounts, call vault.destroy() to remove all iframes and listeners. In vanilla JS use a cancel flag to handle the async nature of OzVault.create():

Auto-Advance Focus

Elements automatically advance focus from one field to the next on completion:
  • When card number is complete and valid → focus moves to expiry
  • When expiry is complete and valid → focus moves to CVV
This is built-in and requires no configuration.

Card Brand Detection

The cardNumber element detects the card brand as the user types and emits it via change:

Imperatively Managing Elements


Full End-to-End Example (Vanilla JS + Express)

onReady can fire while OzVault.create() is still pending. Vault initialization runs multiple steps in parallel. The onReady callback can fire while await OzVault.create(...) is still in progress — meaning vault is undefined inside the callback. Never reference vault inside onReady. Declare your readiness flags before calling create() so they exist when the callback runs. See the example below for the correct pattern.
A complete working example: HTML page with card fields, Express backend with /api/oz-session and /api/charge routes, and the full tokenize → charge flow.

Frontend (HTML + JS)

Backend (Express)

This example serves the SDK locally to avoid CDN CORS issues on localhost. In production, use the CDN URL or your bundler — remove the /oz-elements.esm.js static route. See Installation → CDN for details.

Test Cards

These cards are for testing the vault tokenization flow — they are Luhn-valid and accepted by the vault in test mode. Use them to confirm your fields mount, tokenize, and return a token correctly.
Testing a full charge with OzuraPay? Use the cards on the Test Credentials page instead — those are calibrated for OzuraPay’s sandbox, where the outcome (approve / decline) is determined by the charge amount, not the card number.
Testing your integration? Use the test pub key on localhost — see Installation → Local Development for setup details and test card numbers above.

Next Steps

Styling

Customize colors, fonts, and states.

React Components

OzElements provider and pre-built components.

Error Handling

Handle tokenization errors gracefully.

Server SDK

Process the token with cardSale() on your backend.