PurseHeadlessCheckoutHostedFields
Extends
Properties
detectedBrands
detectedBrands: Readable<CardScheme[]>;
selectedBrand
selectedBrand: Readable<CardScheme | null>;
supportedBrands
supportedBrands: Readable<CardScheme[]>;
Methods
hasUI()
Checks if the payment partner provides a visual UI component.
Use this to determine if you need to allocate space in your layout for the payment UI.
Some payment methods (like redirect-based flows) might not have a UI component.
Returns
boolean
true if the payment method has a UI component to display, false otherwise
Example
if (paymentElement.hasUI()) {
}
Inherited from
PurseHeadlessCheckoutPaymentElement.hasUI
on()
on<K>(eventName, callback): void;
Registers an event listener for payment UI events.
Listen for events like 'ready', 'change', 'blur', 'focus', etc.
Type Parameters
Parameters
| Parameter | Type | Description |
|---|
eventName | K | Name of the event to listen for |
callback | PaymentElementEventsCallback[K] | Function to be called when the event occurs |
Returns
void
Example
paymentElement.on('formValid', () => {
console.log('Payment UI form is valid');
});
Inherited from
PurseHeadlessCheckoutPaymentElement.on
remove()
Removes the payment UI from the DOM and cleans up any associated resources.
Call this when the payment UI is no longer needed or when switching payment methods.
Returns
void
Example
Inherited from
PurseHeadlessCheckoutPaymentElement.remove
render()
Renders the payment UI into the specified container element.
The container can be either a CSS selector string or a direct reference to an HTML element.
Returns
void
Example
setOptions()
setOptions(options?): void;
Configures the appearance and behavior of the payment UI.
Use this to customize the look and feel of the payment form to match your application's design.
Parameters
Returns
void
Example
paymentElement.setOptions({
hostedForm: {
panPlaceholder: 'Enter your card number',
cvvPlaceholder: 'Enter your CVV'
}
});
Inherited from
PurseHeadlessCheckoutPaymentElement.setOptions
setSelectedBrand()
setSelectedBrand(brand): void;
When the card is "co-branded" the user is allowed to set the selected brand.
Parameters
| Parameter | Type | Description |
|---|
brand | CardScheme | The brand to set as selected |
Returns
void
Example
hostedFields.setSelectedBrand('VISA');
Throws
PurseHeadlessCheckoutError NOT_SUPPORTED_BRAND when the provided brand is not in the supported brands list.
Throws
PurseHeadlessCheckoutError BRAND_NOT_BELONGS_TO_DETECTED when brands are detected and the provided brand is not in the detected list.
validateUi()
validateUi(): Promise<boolean | CreditCardValidateUiResult>;
Force the payment UI to validate the form fields.
For credit cards, this checks if all required fields are filled and valid.
For other payment methods, this verifies if the UI is in a valid state for submission.
Returns
Promise<boolean | CreditCardValidateUiResult>
A promise that resolves to:
- boolean: true if validation passed, false if failed
- CreditCardValidateUiResult: detailed validation results for credit card forms
Example
const isValid = await paymentElement.validateUi();
if (isValid) {
console.log('Payment form is valid');
} else {
console.error('Payment form is invalid');
}
Inherited from
PurseHeadlessCheckoutPaymentElement.validateUi