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:
| Parameter | Type | Required | Description |
|---|---|---|---|
mode | 'secure' | Yes | Mounts the card inputs in Pay.com-hosted iframes. |
inputs.number | SecureFieldInputOpts | Yes | The card number input. |
inputs.expiry | SecureFieldInputOpts | Yes | The expiration input. |
inputs.cvv | SecureFieldInputOpts | No | The security code input. |
inputs.name | SecureFieldInputOpts | No | The cardholder name input. |
style | SecureFieldStyle | No | Styles for every input. See Style the fields. |
fonts | { cssSrc: string }[] | No | Web fonts for the inputs. Only https://fonts.googleapis.com URLs are accepted. |
inheritStyleFrom | string | HTMLElement | No | One 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
container | string | HTMLElement | Yes | A CSS selector or element. The iframe fills it, and you draw everything around it, such as the label and the error text. |
style | SecureFieldStyle | No | Layered over the top-level style, with the same allowlist. |
placeholder | string | No | The input's placeholder. |
ariaLabel | string | No | The input's accessible name. Defaults to a name such as "Card number". |
Returns
A handle with these methods:
| Method | Description |
|---|---|
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')