Skip to Content
Docs

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

ParameterTypeRequiredDescription
typestringYesThe payment method type. See the supported values below.
dataobjectConditionalRequired for card and ideal. Not required for wallet and redirect methods. Pass undefined when you only need a later argument.
billingDetailsobjectNoBilling address sent with card payments ({ line1, line2?, city, state?, country, postalCode }), where country is a two-letter country code.
optionsobjectNosaveSourceForFutureUse (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:

ValueDescriptiondata required
'card'Credit or debit cardYes
'applepay'Apple PayNo
'googlepay'Google PayNo
'ideal'iDEAL bank redirectYes ({ bic: string })
'giropay'giropay bank redirectNo

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:

FieldTypeRequiredDescription
numberstringYesCard number, no spaces or dashes.
cvvstringYesCard security code. Not required in payout sessions.
expirationMonthstringYesTwo-digit month, for example '12'.
expirationYearstringYesTwo-digit year, for example '28'.
namestringNoCardholder 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' })
Was this page helpful?