Validate a session
Run an async check before a payment attempt starts and return false to block it.
onValidateSession is an async callback that runs before a payment attempt
starts. Return true to continue or false to block the payment.
- Universal checkout (
checkout.universal()): Runs for every payment method when the customer submits the form or selects a wallet or alternative payment method. - Headless checkout (
checkout.headless()): Runs only forapplepayandgooglepay. For cards and APMs, run validation before callingcheckout.headless().
Callback signature
The callback receives a ValidateSessionData object and returns a promise that
resolves to a boolean.
type ValidateSessionData = {
paymentMethodType: string
fundingType?: 'prepaid' | 'debit' | 'credit' | null
walletResponse?: ApplePayPayment | GooglePayPaymentData
}
type OnValidateSession = (data: ValidateSessionData) => Promise<boolean>Parameters
The ValidateSessionData object has these fields:
| Parameter | Type | Description |
|---|---|---|
paymentMethodType | string | Payment method being validated (card, click_to_pay, googlepay, applepay, paypal, or an APM identifier such as paysafecard or skrill). |
fundingType | 'prepaid' | 'debit' | 'credit' | null | Card funding type when available. In Universal checkout, included only if you registered a checkout.EVENT_TYPES.CARD_FUNDING_TYPE_UPDATE listener with checkout.on(). In Headless checkout, included for Apple Pay and Google Pay. |
walletResponse | ApplePayPayment | GooglePayPaymentData | Raw native wallet response for Apple Pay and Google Pay only. |
Returns
Promise<boolean>. Return true to allow the payment or false to block it.
In Universal checkout, throwing an error also blocks the payment. In Headless
checkout, returning false calls onFailure and rejects checkout.headless().
Example
Pass onValidateSession in checkout.universal() options or as the 4th
argument of checkout.headless(). Pay.com() doesn't accept it.
checkout.universal({
container: '#pay-com-checkout',
onValidateSession: async ({ paymentMethodType, fundingType, walletResponse }) => {
if (paymentMethodType === 'card') {
return validateCardFundingType(fundingType)
}
if (paymentMethodType === 'applepay' || paymentMethodType === 'googlepay') {
return validateWalletPayment(walletResponse)
}
return isPaymentMethodAllowed(paymentMethodType)
}
})onValidateSession replaces the deprecated apmsOnClickValidation option. If
both are passed, only onValidateSession runs.
Next steps
checkout.universal(): All Universal checkout options.checkout.headless(): Submit payments from a custom UI.- Configuration: Checkout display toggles and payment method selection.