PurseHeadlessCheckoutPaymentElement
Interface for managing and interacting with a payment partner's UI component.
Provides methods to render, configure, and handle events from payment UIs like credit card forms or digital wallet buttons.
Example
const paymentElement = method.getPaymentElement();
paymentElement.setOptions({
hostedForm: {
panPlaceholder: 'Enter your card number',
cvvPlaceholder: 'Enter your CVV'
}
});
paymentElement.appendTo('#payment-form');
paymentElement.on('formValid', () => {
console.log('Payment UI form is valid');
});
Methods
appendTo()
appendTo(container): void;
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.
Parameters
Parameter | Type | Description |
---|
container | string | Element | CSS selector (e.g., '#payment-form') or HTML element to render the UI into |
Returns
void
Throws
If the container element cannot be found or is invalid
Example
paymentElement.appendTo('#payment-form');
const container = document.getElementById('payment-form');
paymentElement.appendTo(container);
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()) {
}
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');
\});
***
### remove()
```ts
remove(): void;
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
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
Parameter | Type | Description |
---|
options? | Options | Configuration options for the payment UI See Options for available customization options |
Returns
void
Example
paymentElement.setOptions({
hostedForm: {
panPlaceholder: 'Enter your card number',
cvvPlaceholder: 'Enter your CVV'
}
});
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');
}