Submit a headless payment
Submit a payment using card data or a wallet trigger collected from your own UI.
The checkout.headless() method submits a payment using card data or a wallet trigger collected from your own UI. This method doesn't render a form.
const result = await checkout.headless(type, data?, billingDetails?, options?)Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | Yes | The payment method type. See the supported values below. |
data | object | Conditional | Required for card and ideal. Not required for wallet and redirect methods. Pass undefined when you only need a later argument. |
billingDetails | object | No | Billing address sent with card payments ({ line1, line2?, city, state?, country, postalCode }), where country is a two-letter country code. |
options | object | No | saveSourceForFutureUse (boolean, for card payments), forceRedirect (boolean, for APM redirects, navigates the whole page to the provider instead of opening it in a modal or a new tab), and onValidateSession (Apple Pay and Google Pay only, described in Validate a session). |
Supported type values:
| Value | Description | data required |
|---|---|---|
'card' | Credit or debit card | Yes |
'applepay' | Apple Pay | No |
'googlepay' | Google Pay | No |
'ideal' | iDEAL bank redirect | Yes ({ bic: string }) |
'giropay' | giropay bank redirect | No |
Other enabled payment methods use the paymentMethodType value that checkout.getPaymentMethods() returns, with any fields it lists passed as data.
When type is 'card', the data object accepts:
| Field | Type | Required | Description |
|---|---|---|---|
number | string | Yes | Card number, no spaces or dashes. |
cvv | string | Yes | Card security code. Not required in payout sessions. |
expirationMonth | string | Yes | Two-digit month, for example '12'. |
expirationYear | string | Yes | Two-digit year, for example '28'. |
name | string | No | Cardholder name as it appears on the card. |
Returns
A promise that resolves with the result.
For a payment session, the result is the payment, the same PaymentResult object described on pay.checkout(). The SDK also calls onSuccess, or onPending when the payment is pending.
For a tokenization session with type: 'card', the result is a token object:
{
"token": { "id": "tok_card_685104577720095744" },
"type": "token"
}If the payment fails, the SDK calls onFailure and the promise rejects with a { message, data } object. Always wrap the call in try/catch.
Example
// Card payment
try {
const payment = await checkout.headless('card', {
number: '4111111111111111',
cvv: '123',
expirationMonth: '12',
expirationYear: '28',
name: 'Jane Smith',
})
} catch (error) {
console.log('Payment failed:', error.message)
}
// Card payment with a billing address, saving the card for future use
await checkout.headless(
'card',
{ number: '4111111111111111', cvv: '123', expirationMonth: '12', expirationYear: '28' },
{ line1: '1 Main St', city: 'New York', state: 'NY', country: 'US', postalCode: '10001' },
{ saveSourceForFutureUse: true }
)
// Apple Pay
await checkout.headless('applepay')
// iDEAL
await checkout.headless('ideal', { bic: 'SNSBNL2A' })