Skip to Content
Docs

Mount secure card fields

Mount each card input in its own Pay.com iframe inside your own layout, and get a handle to restyle, focus, clear, or disable the inputs.

The checkout.fields() method mounts the card inputs as secure fields. Each input is a Pay.com iframe in a container you choose, so the card never exists on your page. Calling fields() again replaces the fields already mounted. For how to lay out, style, and listen to the fields, see Secure card fields.

const fields = checkout.fields(options)

Parameters

checkout.fields() takes these parameters:

ParameterTypeRequiredDescription
mode'secure'YesMounts the card inputs in Pay.com-hosted iframes.
inputs.numberSecureFieldInputOptsYesThe card number input.
inputs.expirySecureFieldInputOptsYesThe expiration input.
inputs.cvvSecureFieldInputOptsNoThe security code input.
inputs.nameSecureFieldInputOptsNoThe cardholder name input.
styleSecureFieldStyleNoStyles for every input. See Style the fields.
fonts{ cssSrc: string }[]NoWeb fonts for the inputs. Only https://fonts.googleapis.com URLs are accepted.
inheritStyleFromstring | HTMLElementNoOne of your own inputs, by selector or element. Its computed values for the allowlisted properties become the base style, under style.

Each input (SecureFieldInputOpts) takes:

ParameterTypeRequiredDescription
containerstring | HTMLElementYesA CSS selector or element. The iframe fills it, and you draw everything around it, such as the label and the error text.
styleSecureFieldStyleNoLayered over the top-level style, with the same allowlist.
placeholderstringNoThe input's placeholder.
ariaLabelstringNoThe input's accessible name. Defaults to a name such as "Card number".

Returns

A handle with these methods:

MethodDescription
update(options)Updates field appearance (style, fonts, inheritStyleFrom, and each input's style, placeholder, and ariaLabel). Containers are fixed when the fields mount.
focus(field)Moves focus to 'number', 'expiry', 'cvv', or 'name'.
clear()Empties the fields.
setDisabled(disabled)Disables or enables every input.

Pay

To pay with the card in the fields, call checkout.submit() or checkout.pay({ method: 'card' }). Both resolve with the payment, and reject when it fails, as checkout.submit() does for Universal checkout.

Without a name input, pass the cardholder name your page collects as checkout.submit({ cardholderName }).

const payment = await checkout.submit({ cardholderName: 'Jane Smith' })

Events

The fields emit fields_ready, field_change, field_focus, field_blur, and form_validation_update, which you listen for with checkout.on(). Their payloads carry the field's name and state, never what was typed. See Listen for events for each payload.

Errors

Setup errors don't throw. If inputs.number or inputs.expiry is missing, or a container matches nothing, fields() returns a handle that does nothing.

Example

const fields = checkout.fields({
  mode: 'secure',
  inputs: {
    number: { container: '#card-number' },
    expiry: { container: '#card-expiry' },
    cvv: { container: '#card-cvv', placeholder: 'CVV' },
  },
  style: {
    base: { fontSize: 16, padding: '10px 12px' },
    invalid: { color: '#c62828' },
  },
})

fields.focus('number')
Was this page helpful?