Card
Methods
These methods are available on an AdvancedReverePay instance for Card flows.
| Method | Description | Parameters | Returns |
|---|---|---|---|
checkValidity | Triggers a validity check on all mounted inputs; calls onCheckValidity(validation). Only validates: it never tokenizes or calls onError. | None | boolean (internal); callback receives object |
reset | Clears out all inputs (including optional email if configured). | None | None |
submit | Validates 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. | None | None |
updateFields | Updates placeholders/values after initialization. Known limitation: cannot set empty string; does not work after reset() for some fields. | FieldUpdateConfig | None |
updateStyle | Applies styles to mounted inputs. Pass null to reset to configured defaults. | CSSProperties | null | None |
focusField | Sets focus to a specific field. | FieldName | None |
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
| Option | Type | Default | Description |
|---|---|---|---|
card.form.id | string | ccForm | Container element ID for the payment form wrapper. |
card.fields.cardNumber.id | string | ccNumber | Mount target for Card Number input. |
card.fields.cardNumber.placeholder | string | - | Card Number input placeholder. |
card.fields.cardNumber.allowedCardBrands | AllowableCardBrand[] | All brands | Limits 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.id | string | ccExpiration | Mount target for Expiration input. |
card.fields.cardCVV.id | string | ccCvv | Mount target for CVV input. |
card.fields.cardCVV.required | boolean | true | Marks CVV as required. |
card.fields.cardCVV.placeholder | string | - | CVV input placeholder. |
card.fields.cardHolderName.id | string | ccHolderName | Mount target for Cardholder Name input. |
card.fields.cardHolderName.placeholder | string | - | Cardholder Name input placeholder. |
card.fields.cardHolderName.value | string | - | Initial Cardholder Name value. |
card.fields.cardHolderName.maxLength | number | 128 | Max input length for Cardholder Name. |
card.fields.cardHolderName.pattern | string | See the pattern | Regex pattern for Cardholder Name. |
card.fields.postalCode.id | string | ccPostalCode | Mount target for Postal Code input. |
card.fields.postalCode.placeholder | string | - | Postal Code input placeholder. |
card.fields.postalCode.value | string | - | Initial Postal Code value. |
card.fields.postalCode.maxLength | number | 10 | Max input length for Postal Code. |
card.fields.postalCode.pattern | string | See the pattern | Regex pattern for Postal Code. |
card.fields.postalCode.inputmode | 'text' | 'numeric' | string | - | Virtual keyboard hint (also accepted on cardHolderName). |
card.fields.email.id | string | - | ID of your own email input element. Required when strictMode: true. |
card.fields.email.required | boolean | false | Marks email as required. |
card.fields.email.placeholder | string | - | Not applied at init. Set it on your own input, or use updateFields. |
card.fields.email.value | string | - | Default email value. Also mirrored to reverePay.email. |
card.fields.*.css | CSSProperties | { color: '#f5f5f5' } | Inline styles applied to the mounted input. |
card.fields.*.disabled | boolean | false | Disables the input. |
card.fields.*.readOnly | boolean | false | Makes the input read-only. |
card.fields.*.size | number | - | 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)
- 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
- TypeScript
- JavaScript
- Javascript - UMD