@foxy.io/sdk
Version:
Universal SDK for a full server-side and a limited in-browser access to Foxy hAPI.
70 lines (69 loc) • 2.55 kB
TypeScript
import type { PaymentCardEmbedConfig } from './types';
/**
* A convenience wrapper for the payment card embed iframe. You don't have to use
* this class to embed the payment card iframe, but it provides a more convenient
* way to interact with the iframe and listen to its events.
*
* @example
* const embed = new PaymentCardEmbed({
* url: 'https://embed.foxy.io/v1.html?template_set_id=123'
* });
*
* await embed.mount(document.body);
* console.log('Token:', await embed.tokenize());
*/
export declare class PaymentCardEmbed {
/**
* An event handler that is triggered when Enter is pressed in the card form.
* This feature is not available for template sets configured with the `stripe_connect`
* hosted payment gateway due to the limitations of Stripe.js.
*/
onsubmit: (() => void) | null;
private __tokenizationRequests;
private __iframeMessageHandler;
private __iframeLoadHandler;
private __mountingTask;
private __channel;
private __iframe;
private __config;
private __url;
constructor({ url, ...config }: {
url: string;
} & PaymentCardEmbedConfig);
/**
* Updates the configuration of the payment card embed.
* You can change style, translations, language and interactivity settings.
* To change the URL of the payment card embed, you need to create a new instance.
* You are not required to provide the full configuration object, only the properties you want to change.
*
* @param config - The new configuration.
*/
configure(config: PaymentCardEmbedConfig): void;
/**
* Requests the tokenization of the card data.
*
* @returns A promise that resolves with the tokenized card data.
*/
tokenize(): Promise<string>;
/**
* Safely removes the embed iframe from the parent node,
* closing the message channel and cleaning up event listeners.
*/
unmount(): void;
/**
* Mounts the payment card embed in the given root element. If the embed is already mounted,
* it will be unmounted first.
*
* @param root - The root element to mount the embed in.
* @returns A promise that resolves when the embed is mounted.
*/
mount(root: Element): Promise<void>;
/**
* Clears the card data from the embed.
* No-op if the embed is not mounted.
*/
clear(): void;
protected _createMessageChannel(): MessageChannel;
protected _createIframe(root: Element): HTMLIFrameElement;
protected _createId(): string;
}