@whop/checkout
Version:
Embed Whop checkout on any website
83 lines (76 loc) • 3.16 kB
text/typescript
type WhopCheckoutState = "loading" | "ready" | "disabled";
type WhopCheckoutMessage = {
event: "resize";
height: number;
} | {
event: "center";
} | {
event: "complete";
receipt_id?: string;
plan_id: string;
} | {
event: "state";
state: WhopCheckoutState;
} | {
event: "get-email-result";
email: string;
event_id: string;
} | {
event: "set-email-result";
ok: true;
error?: never;
event_id: string;
} | {
event: "set-email-result";
ok: false;
error: string;
event_id: string;
};
declare function isWhopCheckoutMessage(event: MessageEvent<unknown>): event is MessageEvent<WhopCheckoutMessage>;
declare global {
interface Window {
wco?: {
injected: true;
listening: boolean;
frames: Map<HTMLIFrameElement, () => void>;
identifiedFrames: Map<string, HTMLIFrameElement>;
submit: (
identifier: string,
data?: {
email?: string;
},
) => void;
getEmail: (identifier: string, timeout?: number) => Promise<string>;
setEmail: (
identifier: string,
email: string,
timeout?: number,
) => Promise<void>;
};
}
interface HTMLElementEventMap {
"checkout:submit": CustomEvent<WhopCheckoutSubmitDetails>;
}
}
type WhopCheckoutSubmitDetails = Record<never, never>;
declare function onWhopCheckoutMessage(iframe: HTMLIFrameElement, callback: (message: WhopCheckoutMessage) => void): () => void;
declare function setEmail(frame: HTMLIFrameElement, email: string, timeout?: number): Promise<void>;
declare function getEmail(frame: HTMLIFrameElement, timeout?: number): Promise<string>;
declare function submitCheckoutFrame(frame: HTMLIFrameElement, _data?: WhopCheckoutSubmitDetails): void;
interface WhopEmbeddedCheckoutStyleOptions {
container?: {
paddingTop?: number | string;
paddingBottom?: number | string;
paddingY?: number | string;
};
}
interface WhopEmbeddedCheckoutPrefillOptions {
email?: string;
}
interface WhopEmbeddedCheckoutThemeOptions {
accentColor?: string;
}
declare function getEmbeddedCheckoutIframeUrl(planId: string, theme?: "light" | "dark" | "system", sessionId?: string, origin?: string, hidePrice?: boolean, skipRedirect?: boolean, utm?: Record<string, string | string[]>, styles?: WhopEmbeddedCheckoutStyleOptions, prefill?: WhopEmbeddedCheckoutPrefillOptions, themeOptions?: WhopEmbeddedCheckoutThemeOptions, hideSubmitButton?: boolean, hideTermsAndConditions?: boolean, hideEmail?: boolean, disableEmail?: boolean): string;
declare const EMBEDDED_CHECKOUT_IFRAME_SANDBOX_LIST: string[];
declare const EMBEDDED_CHECKOUT_IFRAME_ALLOW_STRING = "document-domain; execution-while-not-rendered; execution-while-out-of-viewport; payment; paymentRequest; sync-script;";
export { EMBEDDED_CHECKOUT_IFRAME_ALLOW_STRING, EMBEDDED_CHECKOUT_IFRAME_SANDBOX_LIST, type WhopCheckoutMessage, type WhopCheckoutState, type WhopCheckoutSubmitDetails, type WhopEmbeddedCheckoutPrefillOptions, type WhopEmbeddedCheckoutStyleOptions, type WhopEmbeddedCheckoutThemeOptions, getEmail, getEmbeddedCheckoutIframeUrl, isWhopCheckoutMessage, onWhopCheckoutMessage, setEmail, submitCheckoutFrame };