createToken() and createBankToken() both throw an OzError when tokenization fails. Wrap calls in a try/catch and inspect .errorCode to decide how to respond.
OzError
OzError properties
Error Codes
Session key expiry is handled automatically. When a session key expires or is consumed between initialization and the user clicking Pay, the SDK silently fetches a fresh key and retries once. You will only receive an
auth error if the refresh itself fails (e.g. your session endpoint is down or returns an error). The proactive refresh — triggered once sessionLimit successful submissions are reached — also prevents expiry from surfacing under normal usage.Recommended Pattern
SDK-Level Errors
TheseOzError instances are thrown before any network request is made. They represent setup or usage mistakes caught during integration — fix them in code, don’t surface them to the user.
Initialization errors
These come fromOzVault.create(). If you’re using the React provider, they appear in initError.
Tokenization errors
These come fromcreateToken() / createBankToken().
Element errors
These are developer errors — TypeScript types and the error messages above are the full diagnostic.
Load Errors
If the vault fails to load (network issue, blocked by CSP, etc.), useonLoadError in OzVault.create():
loaderror event with the element type and error message:
React: initError
In React,OzVault.create() is called inside the <OzElements> provider. If it fails (e.g. your session endpoint is unreachable or returns an error), useOzElements().initError will be non-null:
Error Normalization Helpers
The SDK exports three standalone functions that map raw API error strings to user-friendly messages.OzError.message from createToken() and createBankToken() is already normalized — the SDK calls these functions internally. You only need to call them yourself when you receive raw error strings from a different source (e.g. your backend forwarding a vault or OzuraPay API response).normalizeVaultError
Maps raw vault/tokenize error strings to user-facing messages for card flows.
normalizeBankVaultError
Maps raw vault/tokenize error strings to user-facing messages for bank/ACH flows.
normalizeCardSaleError
Maps raw OzuraPay APIcardSale error strings to user-facing messages. Use this when your backend processes a charge via the OzuraPay API and needs to display the error to the user.
normalizeVaultErrorandnormalizeBankVaultError— return the originalrawstring unchanged when no pattern matches.normalizeCardSaleError— short unrecognized strings (under 100 characters) are returned as-is; long opaque server strings (100+ characters) are replaced with"Payment processing failed. Please try again or contact support."An empty input returns"Payment processing failed. Please try again."
Next Steps
API Reference
Full OzError type definition and all SDK types.
Card Elements
createToken() full reference.