JS fields / iframe
Card inputs that live inside your checkout but outside your PCI scope: each sensitive field renders in a sandboxed, Card Vault-hosted iframe, so card data posts directly to the vault and never touches your page's JavaScript or your servers.
How it works
- You place three container elements where the card number, expiry, and CVV inputs should appear.
cv-fields.jsmounts a sandboxed iframe into each container, plus one invisible collection frame. The inputs render inside Card Vault's origin -- your page cannot read them.- On submit, the field iframes hand their values directly to the collection frame, which posts to Card Vault. Your page receives only the outcome -- a token and metadata, never card data.
Markup
<script src="https://cdn.cardvault.com/fields/1.0.0/cv-fields.js" integrity="sha384-Gr9ligBK5csUw/LxtPtaKnhJ4VkV0blw9qJDR+OYNSb01KZSQ0sSdt74HymZlQc5" crossorigin="anonymous"></script> <div id="card-number"></div> <div id="card-expiry"></div> <div id="card-cvv"></div> <button id="pay" disabled>Pay</button>
Create and mount
var fields = CV.fields.create({ publicKey: "cvpk_test_...", // publishable key -- safe in the browser fieldUrl: "https://<your field URL from the dashboard>", collectUrl: "https://<your collect URL from the dashboard>", fieldHeight: "38px", // optional (default 38px; width 100%) style: { borderRadius: "8px", color: "#222222" }, // optional: match your design onReady: function () { document.getElementById("pay").disabled = false; }, onSuccess: function (res) { /* res.token etc. -- send to YOUR server */ }, onDecline: function (ctx) { // ctx.code, ctx.message, ctx.ref -- declined by the issuer, or // ctx.code === "CARD_NOT_ACCEPTED" when your Card Policy refuses the card }, onChange: function (ctx) { // ctx.field, ctx.valid, ctx.empty, ctx.brand -- and for the card number: // ctx.accepted === false + ctx.message when your Card Policy refuses the card }, onError: function (ctx) { /* ctx.code, ctx.message */ }, onValidationFail: function (ctx) { // ctx.field ("pan" | "expiry" | "cvv") + ctx.fieldId -- highlight the input } }); fields.mount({ pan: "#card-number", expiry: "#card-expiry", cvv: "#card-cvv" });
Submit: vault only, or vault + charge
// Vault only: profile details ride along with the capture fields.submit({ ref: "BOOKING-4821", profile: { fullName: "Jamie Cardholder", email: "jamie@example.com" } }); // Vault + charge in one step fields.submit( { ref: "INV-2026-0042" }, { amount: 10.99, // DECIMAL DOLLARS here -- converted internally; // maximum $999,999.99 currency: "USD", vaultOnSuccess: true, // store the card if the charge approves transactionType: 0 // 0 = charge, 1 = pre-authorization } );
Submits are debounced (2 seconds) and refused until onReady has fired.
Outcomes arrive on your callbacks: onSuccess with the result (token +
card metadata, plus the transaction outcome when charging), onDecline
when the issuer says no -- or with code: "CARD_NOT_ACCEPTED" when your
Card Policy refuses the card, before anything is
charged or stored -- and onError for everything else.
API summary
CV.fields.create(options)-- returns an instance. Required:publicKey,fieldUrl,collectUrl(both URLs must be https; both come from your dashboard's integration page)..mount({ pan, expiry, cvv })-- selectors or elements; builds the sandboxed field iframes and hidden collection frame..submit(submitData, chargeData?)-- capture (and optionally charge).submitData:ref,profile, custom fields.chargeData:amount,currency,processorId,vaultOnSuccess,transactionType..reset()-- clear all fields..focus(field)-- move focus into a field ("pan", "expiry", "cvv")..destroy()-- unmount the iframes and release listeners..isReady()/.isSubmitting()-- state checks..setStyle(style)-- restyle the fields, e.g. on a theme switch. Thestyleoption and this method take an allow-list of input properties (fonts, sizes, colours, border, radius, padding, height, the valid / error indicator); see the JS fields showcase for the full list and a fully branded example.
Pin the script with integrity and crossorigin="anonymous".
Field events
onChange, onFocus, and onBlur fire as the
cardholder types (with field identity, never contents), so you can drive your own
inline styling. onValidationFail identifies exactly which field failed
(ctx.field, ctx.fieldId) with a display-ready reason --
highlight the right input without ever being able to read it.
Card Policy: refused cards
If you have set a Card Policy, the card number field checks each card as it is typed:
onChangefor the card number field carriesaccepted(falsewhen the card is refused) andmessage(your refusal text, otherwisenull). Use it to show the message and disable your pay button.- If a refused card is submitted,
onDeclinefires withcode: "CARD_NOT_ACCEPTED",messageandref. Nothing is charged or vaulted.
The as-you-type check applies your account-wide policy; the check at submit also applies any segment override and is the one that decides.