Skip to main content

Card

Methods​

These methods are available on an AdvancedReverePay instance for Card flows.

MethodDescriptionParametersReturns
checkValidityTriggers a validity check on all mounted inputs; calls onCheckValidity(validation). Only validates: it never tokenizes or calls onError.Noneboolean (internal); callback receives object
resetClears out all inputs (including optional email if configured).NoneNone
submitValidates the fields; if they are valid, tokenizes the card. Ends in exactly one onSuccess or onError. Ignored (with a console warning) while a submission is in progress.NoneNone
updateFieldsUpdates placeholders/values after initialization. Known limitation: cannot set empty string; does not work after reset() for some fields.FieldUpdateConfigNone
updateStyleApplies styles to mounted inputs. Pass null to reset to configured defaults.CSSProperties | nullNone
focusFieldSets focus to a specific field.FieldNameNone

How to call a method​

// Assume `reverePay` is your AdvancedReverePay instance
reverePay.checkValidity();
reverePay.submit();
reverePay.updateFields({
	cardHolderName: { value: 'John Doe' },
	postalCode: { value: '12345' },
	email: { value: 'john@doe.com' },
	cardNumber: { placeholder: '1234 1234 1234 1234' },
	cardCVV: { placeholder: 'CVV' }
});
reverePay.updateStyle({ backgroundColor: '#f59d9d' });
reverePay.focusField('cardNumber');
reverePay.reset();

Configuration​

All card options live under config.card. Its presence selects the card flow.

config: {
	card: {
		form: { id: 'ccForm' },
		fields: {
			cardNumber: { id: 'ccNumber' }
			// ...
		}
	}
}

Quick Reference​

OptionTypeDefaultDescription
card.form.idstringccFormContainer element ID for the payment form wrapper.
card.fields.cardNumber.idstringccNumberMount target for Card Number input.
card.fields.cardNumber.placeholderstring-Card Number input placeholder.
card.fields.cardNumber.allowedCardBrandsAllowableCardBrand[]All brandsLimits the accepted card brands. Other brands fail validation.
card.fields.cardNumber.onBrandChange(brand: AllowableCardBrand) => void-Fired when the detected card brand changes.
card.fields.cardExpiration.idstringccExpirationMount target for Expiration input.
card.fields.cardCVV.idstringccCvvMount target for CVV input.
card.fields.cardCVV.requiredbooleantrueMarks CVV as required.
card.fields.cardCVV.placeholderstring-CVV input placeholder.
card.fields.cardHolderName.idstringccHolderNameMount target for Cardholder Name input.
card.fields.cardHolderName.placeholderstring-Cardholder Name input placeholder.
card.fields.cardHolderName.valuestring-Initial Cardholder Name value.
card.fields.cardHolderName.maxLengthnumber128Max input length for Cardholder Name.
card.fields.cardHolderName.patternstringSee the patternRegex pattern for Cardholder Name.
card.fields.postalCode.idstringccPostalCodeMount target for Postal Code input.
card.fields.postalCode.placeholderstring-Postal Code input placeholder.
card.fields.postalCode.valuestring-Initial Postal Code value.
card.fields.postalCode.maxLengthnumber10Max input length for Postal Code.
card.fields.postalCode.patternstringSee the patternRegex pattern for Postal Code.
card.fields.postalCode.inputmode'text' | 'numeric' | string-Virtual keyboard hint (also accepted on cardHolderName).
card.fields.email.idstring-ID of your own email input element. Required when strictMode: true.
card.fields.email.requiredbooleanfalseMarks email as required.
card.fields.email.placeholderstring-Not applied at init. Set it on your own input, or use updateFields.
card.fields.email.valuestring-Default email value. Also mirrored to reverePay.email.
card.fields.*.cssCSSProperties{ color: '#f5f5f5' }Inline styles applied to the mounted input.
card.fields.*.disabledbooleanfalseDisables the input.
card.fields.*.readOnlybooleanfalseMakes the input read-only.
card.fields.*.sizenumber-Expected number of characters in the input.
card.fields.*.onInvalid(state: { message: string; validity: ValidityState }) => void-Called when the field fails a validity check.
card.fields.*.onCheckValidity(isValid: boolean) => void-Fired after a validity check with the field's validity.
card.fields.*.onReportValidity(isValid: boolean) => void-Fired after a validity report with the field's validity.
card.fields.*.onFocus / onBlur() => void-Fired when the input gains or loses focus.
card.fields.*.onInput / onChange() => void-Fired when the user types (onInput) or commits a change and leaves the field (onChange).
card.fields.*.onEnterKeyPress() => void-Fired when the user presses Enter in the input.

* is any of cardNumber, cardExpiration, cardCVV, cardHolderName and postalCode. The email field targets an element you own, so the per-field hooks and css don't apply to it. Keep its value in sync yourself, through the instance's email setter or updateFields({ email: { value } }).

AdvancedCardOptions​

type AdvancedCardOptions = {
	form?: { id?: string };
	fields?: {
		cardNumber?: FieldConfigBase & {
			placeholder?: string;
			allowedCardBrands?: AllowableCardBrand[];
			onBrandChange?: (brand: AllowableCardBrand) => void;
		};
		cardExpiration?: FieldConfigBase;
		cardCVV?: FieldConfigBase & { required?: boolean; placeholder?: string };
		cardHolderName?: FieldConfigBase &
			TextInputFieldOptions & {
				placeholder?: string;
				value?: string;
			};
		postalCode?: FieldConfigBase &
			TextInputFieldOptions & {
				placeholder?: string;
				value?: string;
			};
		email?: FieldConfigBase & { placeholder?: string; value?: string; required?: boolean };
	};
};

type TextInputFieldOptions = {
	pattern?: string;
	maxLength?: number;
	inputmode?: 'text' | 'numeric' | string;
};

type FieldConfigBase = {
	/** Container element ID. Each field has its own default. */
	id?: string;
	/** Fired when the input fails a validation check */
	onInvalid?: (state: { message: string; validity: ValidityState }) => void;
	/** Fired when the input loses focus */
	onBlur?: () => void;
	/** Fired when the user focuses the input */
	onFocus?: () => void;
	/** Fired when the user changes the input value */
	onInput?: () => void;
	/** Fired when the user navigates away from the input after changing it */
	onChange?: () => void;
	/** Fired when the user presses the enter key while focusing the input */
	onEnterKeyPress?: () => void;
	/** Fired after a validity check runs on the input */
	onCheckValidity?: (isValid: boolean) => void;
	/** Fired after a validity report runs on the input */
	onReportValidity?: (isValid: boolean) => void;
	css?: CSSProperties;
	/** If true, this input is disabled, preventing user input. */
	disabled?: boolean;
	/** If true, the input value cannot be edited by a user. */
	readOnly?: boolean;
	/** Expected number of characters in this input. */
	size?: number;
};

type CSSProperties = Partial<Record<keyof CSSStyleDeclaration, string | null>>;
  • Default IDs: form.id = 'ccForm', cardNumber.id = 'ccNumber', cardExpiration.id = 'ccExpiration', cardCVV.id = 'ccCvv', cardHolderName.id = 'ccHolderName', postalCode.id = 'ccPostalCode'.

Per-field Callbacks​

Each card field can have its own validation and event callbacks (not email).

onCheckValidity: (isValid: boolean) => void​

Example:

const reverePay = new AdvancedReverePay({
	merchantId: 'yourMerchantId',
	publicAPIKey: 'yourPublicAPIKey',
	config: {
		sandbox: true,
		card: {
			fields: {
				cardNumber: {
					id: 'ccNumber',
					allowedCardBrands: ['visa', 'mastercard'],
					onBrandChange: (brand) => console.log('Detected brand:', brand),
					onCheckValidity: (isValid) => {
						console.log('Card number is valid:', isValid);
					}
				},
				cardHolderName: {
					id: 'ccHolderName',
					onInvalid: ({ message }) => {
						console.log('Cardholder name validation failed:', message);
					}
				},
				postalCode: {
					id: 'ccPostalCode',
					onBlur: () => {
						// Update UI when the user leaves the field
					}
				}
			}
		}
	},
	onSuccess: (res) => console.log('SUCCESS', res),
	onError: (status, validation, err) => console.log('ERROR', status, validation, err)
});

onInvalid: (state: { message: string; validity: ValidityState }) => void​

Called when the field fails a validity check. message is the field's validation message and validity is its ValidityState.

onReportValidity: (isValid: boolean) => void​

Called when validity is reported for the field.

onFocus, onBlur, onInput, onChange, onEnterKeyPress: () => void​

Called on the corresponding user interaction with the field.

FieldName​

export type FieldName =
	'cardNumber' | 'cardExpiration' | 'cardCVV' | 'cardHolderName' | 'postalCode' | 'email';

FieldUpdateConfig​

export type FieldUpdateConfig = {
	/** Placeholder only: card number and CVV values can never be set programmatically. */
	cardNumber?: { placeholder?: string };
	cardCVV?: { placeholder?: string };
	cardHolderName?: { placeholder?: string; value?: string };
	postalCode?: { placeholder?: string; value?: string };
	email?: { placeholder?: string; value?: string };
};

CSSProperties​

updateStyle accepts any valid subset of CSS style keys as strings (e.g., backgroundColor, color, fontSize). Pass null to revert to configured defaults.

Example (TypeScript)​

import { AdvancedReverePay } from '@revere_payments/tokenizer';
import type { SuccessResponse, ErrorResponse, Validation } from '@revere_payments/tokenizer/types';

const reverePay = new AdvancedReverePay({
	merchantId: 'yourMerchantId',
	publicAPIKey: 'yourPublicAPIKey',
	config: {
		sandbox: true,
		card: {
			form: { id: 'ccForm' },
			fields: {
				cardHolderName: { id: 'ccHolderName' },
				postalCode: { id: 'ccPostalCode' },
				cardNumber: { id: 'ccNumber' },
				cardExpiration: { id: 'ccExpiration' },
				cardCVV: { id: 'ccCvv', required: true },
				email: { id: 'email', required: false }
			}
		}
	},
	onSuccess: (res: SuccessResponse) => console.log('SUCCESS', res),
	onError: (status: number, validation: Validation, err?: ErrorResponse) => {
		console.log('ERROR', status, validation, err);
	},
	onCheckValidity: (validation: Validation) => console.log('VALID', validation),
	onLoaded: () => console.log('loaded')
});

Response Types​

For detailed information about response types, see Response Types.

Postal code default pattern​

'^(?!.*(--|  |- | -))[A-Za-z0-9](?:[A-Za-z0-9\\- ]{0,8}[A-Za-z0-9])?$'

Holdername default pattern​

'^\\s*[^0-9\\s]+(?:\\s+[^0-9\\s]+)+\\s*$'

Playgrounds​