@whop/checkout
Version:
Embed Whop checkout on any website
141 lines (134 loc) • 4.94 kB
text/typescript
import * as React from 'react';
import React__default, { MutableRefObject, ReactNode } from 'react';
import { WhopCheckoutSubmitDetails, WhopCheckoutState, WhopEmbeddedCheckoutStyleOptions, WhopEmbeddedCheckoutPrefillOptions } from '../util.mjs';
declare const accentColorValues: readonly ["tomato", "red", "ruby", "crimson", "pink", "plum", "purple", "violet", "iris", "cyan", "teal", "jade", "green", "grass", "brown", "blue", "orange", "indigo", "sky", "mint", "yellow", "amber", "lime", "lemon", "magenta", "gold", "bronze", "gray"];
type AccentColor = (typeof accentColorValues)[number];
interface WhopCheckoutEmbedControls {
submit: (opts?: WhopCheckoutSubmitDetails) => void;
getEmail: (timeout?: number) => Promise<string>;
setEmail: (email: string, timeout?: number) => Promise<void>;
}
interface WhopCheckoutEmbedThemeOptions {
/**
* **Optional** - The accent color you want to use in the embed.
*
* defaults to `blue`
*/
accentColor?: AccentColor;
}
interface WhopCheckoutEmbedProps {
/**
* **Required** - The plan id you want to checkout.
*/
planId: string;
/**
* **Optional** - A ref to the embed controls.
*
* This can be used to submit the checkout form.
*/
ref?: MutableRefObject<WhopCheckoutEmbedControls | null>;
/**
* **Optional** - The theme you want to use for the checkout.
*
* Possible values are `light`, `dark` or `system`.
*
* @default "system"
*/
theme?: "light" | "dark" | "system";
/**
* **Optional** - The session id to use for the checkout.
*
* This can be used to attach metadata to a checkout by first creating a session through the API and then passing the session id to the checkout element.
*/
sessionId?: string;
/**
* **Optional** - Turn on to hide the price in the embedded checkout form.
*
* @default false
*/
hidePrice?: boolean;
/**
* **Optional** - Set to `true` to skip the final redirect and keep the top frame loaded.
*
* @default false
*/
skipRedirect?: boolean;
/**
* **Optional** - A callback function that will be called when the checkout is complete.
*/
onComplete?: (
/** The plan id of the plan that was purchased. */
plan_id: string,
/** The receipt id of the purchase. */
receipt_id?: string) => void;
/**
* **Optional** - A callback function that will be called when the checkout state changes.
*/
onStateChange?: (
/** The new state of the checkout. */
state: WhopCheckoutState) => void;
/**
* **Optional** - The UTM parameters to add to the checkout URL.
*
* **Note** - The keys must start with `utm_`
*/
utm?: Record<string, string | string[]>;
/**
* **Optional** - The styles to apply to the checkout embed.
*/
styles?: WhopEmbeddedCheckoutStyleOptions;
/**
* **Optional** - The prefill options to apply to the checkout embed.
*
* Used to prefill the email in the embedded checkout form.
* This setting can be helpful when integrating the embed into a funnel that collects the email prior to payment already.
*/
prefill?: WhopEmbeddedCheckoutPrefillOptions;
/**
* **Optional** - The theme options to apply to the checkout embed.
*/
themeOptions?: WhopCheckoutEmbedThemeOptions;
/**
* **Optional** - Set to `true` to hide the submit button in the embedded checkout form.
*
* @default false
*/
hideSubmitButton?: boolean;
/**
* **Optional** - Set to `true` to hide the terms and conditions in the embedded checkout form.
*
* @default false
*/
hideTermsAndConditions?: boolean;
/**
* **Optional** - Set to `true` to hide the email input in the embedded checkout form.
*
* @default false
*/
hideEmail?: boolean;
/**
* **Optional** - Set to `true` to disable the email input in the embedded checkout form.
*
* @default false
*/
disableEmail?: boolean;
}
/**
* This component can be used to embed whop checkout in your react app:
*
* ```tsx
* import { WhopCheckoutEmbed } from "@whop/react/checkout";
*
* export default function Home() {
* return <WhopCheckoutEmbed planId="plan_XXXXXXXXX" />;
* }
* ```
*/
declare const WhopCheckoutEmbed: React__default.ForwardRefExoticComponent<Omit<WhopCheckoutEmbedProps & {
/**
* **Optional** - The fallback content to show while the checkout is loading.
*/
fallback?: ReactNode;
}, "ref"> & React__default.RefAttributes<WhopCheckoutEmbedControls>>;
declare function useCheckoutEmbedControls(): React.RefObject<WhopCheckoutEmbedControls>;
export { WhopCheckoutEmbed, type WhopCheckoutEmbedProps, type WhopCheckoutEmbedThemeOptions, WhopEmbeddedCheckoutPrefillOptions, WhopEmbeddedCheckoutStyleOptions, useCheckoutEmbedControls };