PlandalfDocsSign inStart free trial

Frameworks

Astro

Add the Plandalf script to your base layout once, then any element on your Astro pages can open a checkout. It works in .astro files and in React, Vue or Svelte islands.

Add the script

Paste the script before </body> in the layout every page uses. Copy your script address from your checkout's Share screen (pick HTML).

---
const { title } = Astro.props;
---
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>{title}</title>
  </head>
  <body>
    <slot />
    <script is:inline async src="https://YOUR-ORG.plandalf.dev/js/plandalf-sdk.js"></script>
  </body>
</html>

is:inline tells Astro to leave the tag as it is, so it loads the script from Plandalf instead of bundling it.

Open a checkout from a button

Add the attribute to any element. It needs no JavaScript of its own, so it works in plain .astro files:

<button data-plandalf-present="YOUR-CHECKOUT">Buy Now</button>

From your own code

Queue the call with the stub, so it works before the script has loaded:

<button id="upgrade">Upgrade</button>
<script>
  const w = window as any;
  w.plandalf = w.plandalf || function () { (w.plandalf.q = w.plandalf.q || []).push(arguments); };
  document.querySelector("#upgrade")?.addEventListener("click", () => w.plandalf("present", "YOUR-CHECKOUT"));
</script>

See Open a checkout from code.

Show a checkout on the page

Add an empty element with data-plandalf-mount:

<div data-plandalf-mount="YOUR-CHECKOUT" style="min-height: 480px"></div>

Show a deadline timer

Add 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"></div>
<button data-plandalf-present="YOUR-CHECKOUT" data-plandalf-apply-promo="YOUR-PROMO">Buy Now</button>

See Countdowns.

Use a package in an island

In an interactive island, you can use @plandalf/react, @plandalf/vue or @plandalf/svelte. Set up the provider or context inside each island that uses the package. Astro islands have separate component trees, so they don't share framework context.

Check it's working

  1. Open the page

    If you used the hosted script, type typeof window.plandalf in the browser console. Look for "function".

  2. Click your button

    Plandalf should display your checkout over the page.

  3. Make a test purchase

    Add localhost and your staging site in Plandalf under Settings → Advanced → Test domains. Checkouts there use Stripe test cards. See Test mode.

If it isn't working

  • With view transitions (<ClientRouter />), Astro swaps the page body when you navigate, and buttons on the new page may not open. Add data-astro-reload to links that lead to pages that sell, so those pages load in full.
  • Without is:inline, Astro may try to bundle the script. Keep the attribute.
  • Add data-debug="true" to the script tag and the console logs each step the script takes.

See Troubleshooting.