Frameworks
React
Use the hosted script to open a checkout from a JSX attribute in Vite or Create React App. To open one from a hook, use the React package.
Add the script
Install the SDK + use data attributes
The SDK auto-discovers any element with the canonical data attributes — even ones React renders later.
// public/index.html — load the SDK once, before </body>: // <script async src="https://YOUR-ORG.plandalf.dev/js/plandalf-sdk.js"></script> // Then use the data attributes anywhere in your tree. export function BuyButton() { return ( <button data-plandalf-present="YOUR-CHECKOUT" > Buy Now </button> ); }Make the first open instant (optional)
Paste this under the SDK script tag on the pages that hold the trigger. It fetches the checkout UI (about 1.2 MB) in the background while the page sits idle, so the click only pays for creating the session. Leave it off pages with no checkout: visitors download it whether or not they buy. In a React app, call sdk.preload('checkout') from the ready callback in an effect instead.
<script> // Optional: fetch the checkout UI while the page is idle, so the first click opens at once. window.plandalf = window.plandalf || function () { (window.plandalf.q = window.plandalf.q || []).push(arguments); }; plandalf('ready', (sdk) => sdk.preload('checkout')); </script>
For programmatic control: plandalf.present('YOUR-CHECKOUT') returns a FlowHandle (a Promise, plus .events and .close()).
In a Vite app, the HTML file is index.html at the project root; in Create React App it's public/index.html. Paste the script before </body>:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>My app</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
<script async src="https://YOUR-ORG.plandalf.dev/js/plandalf-sdk.js"></script>
</body>
</html>
Keep it a plain script, not type="module", and don't import it from your bundle.
Open a checkout from a button
JSX passes data-* attributes straight through, so the attribute works on any element:
export function BuyButton() {
return <button data-plandalf-present="YOUR-CHECKOUT">Buy Now</button>;
}
From your own click handler
This helper queues calls made before the script loads, so you can call it at any time:
type Plandalf = ((...args: unknown[]) => void) & { q?: unknown[][] };
declare global {
interface Window {
plandalf?: Plandalf;
}
}
export function plandalf(...args: unknown[]): void {
if (typeof window === "undefined") return; // nothing to do on the server
// Hold calls made before the script loads; it runs them when it arrives.
window.plandalf ??= function (...a: unknown[]) {
(window.plandalf!.q ??= []).push(a);
} as Plandalf;
window.plandalf(...args);
}
import { plandalf } from "./lib/plandalf";
export function UpgradeButton() {
return <button onClick={() => plandalf("present", "YOUR-CHECKOUT")}>Upgrade</button>;
}
To wait for the result, call plandalf("ready", callback): the callback gets the SDK, and its present() returns a handle you can await. See Open a checkout from code.
Show a checkout on the page
Render an empty element with data-plandalf-mount. The script finds it when React adds it to the page:
export function Checkout() {
return <div data-plandalf-mount="YOUR-CHECKOUT" style={{ minHeight: 480 }} />;
}
Show a deadline timer
Render an empty element with your deadline timer's slug. The script draws the live countdown inside it. To charge the deadline timer's current price, add data-plandalf-apply-promo with the same slug to your buy button.
<div data-plandalf-promo="YOUR-PROMO" />
<button data-plandalf-present="YOUR-CHECKOUT" data-plandalf-apply-promo="YOUR-PROMO">Buy Now</button>
See Countdowns.
The @plandalf/react package
To open checkouts with React hooks, install the package and wrap your app in <PlandalfProvider>. Set apiBase to your organization's Plandalf address.
npm install @plandalf/react
import { createRoot } from "react-dom/client";
import { PlandalfProvider } from "@plandalf/react";
import App from "./App";
createRoot(document.getElementById("root")!).render(
<PlandalfProvider apiBase="https://YOUR-ORG.plandalf.dev">
<App />
</PlandalfProvider>,
);
In a child component, take const { present } = usePresent() and call present('YOUR-CHECKOUT') from your click handler. See React components and hooks for the full button example.
Check it's working
Run the app
If you used the hosted script, type
typeof window.plandalfin the browser console. Look for"function".Click your button
Plandalf should display your checkout over the page.
Make a test purchase
Add
localhostand your preview domain in Plandalf under Settings → Advanced → Test domains. Checkouts there use Stripe test cards. See Test mode.
If it isn't working
- Calling
window.plandalf.present()straight away can run before the script has loaded. Use the helper above, which queues the call. - If your app sends a Content Security Policy, allow
https://*.plandalf.devandhttps://js.stripe.cominscript-src,connect-srcandframe-src. - Add
data-debug="true"to the script tag and the console logs each step the script takes.
See Troubleshooting.