FloPayElements
Manages the creation and lifecycle of payment elements in the @flopay/js SDK.
FloPayElements
Manages the creation and lifecycle of payment elements. Each FloPayElements instance is bound to a single provider adapter and tracks all created elements for cleanup.
class FloPayElements {
constructor(provider: PaymentProviderAdapter, options?: ElementOptions)
}Typically created via flopay.elements() rather than instantiated directly.
create
Creates a new element of the given type. If an element of that type already exists in the provider, it is reused. Otherwise, any existing element of that type is destroyed first.
async create(
type: ElementType,
options?: ElementOptions
): Promise<MountedElement>| Parameter | Type | Required | Description |
|---|---|---|---|
type | ElementType | Yes | The element type ('payment', 'card', 'cardNumber', 'cardExpiry', 'cardCvc', 'address'). |
options | ElementOptions | No | Configuration options merged with the base options from the constructor. |
Returns: Promise<MountedElement>
const elements = flopay.elements({ appearance: { theme: 'flat' } });
const card = await elements.create('card');
card.mount(document.getElementById('card-container')!);getElement
Returns a previously created element by type, or null if not yet created.
getElement(type: ElementType): MountedElement | null| Parameter | Type | Required | Description |
|---|---|---|---|
type | ElementType | Yes | The element type to look up. |
Returns: MountedElement | null
const existing = elements.getElement('card');
if (existing) {
existing.mount(container);
}submit
Submits all mounted elements for validation. This does NOT confirm the payment -- call flopay.confirmPayment() for that.
async submit(): Promise<{ error?: FloPayError }>Returns: Promise<{ error?: FloPayError }>
destroy
Destroys all created elements and clears the internal map.
destroy(): void