Frameworks
Vue
Use the hosted script to open checkouts from attributes in your Vue templates. For composables and a gate component, use the Vue package.
Add the script
These are the steps your checkout's Share screen shows for Vue. Copy the snippets from there and they already hold your script address and checkout slug.
Install the SDK
index.html, before </body>:
<script async src="https://YOUR-ORG.plandalf.dev/js/plandalf-sdk.js"></script>Add the trigger button
Use the canonical attribute in any component. The SDK's MutationObserver picks up newly mounted elements automatically.
<template> <button data-plandalf-present="YOUR-CHECKOUT" class="btn-primary" > Buy Now </button> </template>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>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>My app</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
<script async src="https://YOUR-ORG.plandalf.dev/js/plandalf-sdk.js"></script>
</body>
</html>
Using Nuxt? See the Nuxt guide.
Open a checkout from a button
Add the attribute to any element in a template:
<template>
<button data-plandalf-present="YOUR-CHECKOUT">Buy Now</button>
</template>
From your own click handler
Use the global window.plandalf. Queue the call with the stub, so it works even before the script has loaded:
<script setup lang="ts">
function upgrade() {
const w = window as any;
w.plandalf = w.plandalf || function () { (w.plandalf.q = w.plandalf.q || []).push(arguments); };
w.plandalf("present", "YOUR-CHECKOUT");
}
</script>
<template>
<button @click="upgrade">Upgrade</button>
</template>
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 Vue adds it to the page:
<template>
<div data-plandalf-mount="YOUR-CHECKOUT" style="min-height: 480px"></div>
</template>
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"></div>
<button data-plandalf-present="YOUR-CHECKOUT" data-plandalf-apply-promo="YOUR-PROMO">Buy Now</button>
See Countdowns.
The @plandalf/vue package
For Vue 3.5 or later, install the package to use Plandalf from your components.
npm install @plandalf/vue
import { createApp } from 'vue';
import { createPlandalf } from '@plandalf/vue';
import App from './App.vue';
createApp(App)
.use(createPlandalf({ apiBase: 'https://YOUR-ORG.plandalf.dev' }))
.mount('#app');
Import the composables you need from @plandalf/vue and call them in <script setup>.
- Get
presentfromusePresent(). Callpresent('YOUR-CHECKOUT')when the buyer clicks. - Use
usePromo(slug)to read the current tier and seconds remaining. To show the countdown, takeconst { el } = useCountdown(slug)and add<div ref="el"></div>to your template. - Use
useGate(name, flow, check)to check access and offer a checkout to buyers who need it. - Use
useUser()to set the buyer's token anduseReferral()to read the visitor's referral. UseusePlandalf()for the SDK itself.
You can also import PlandalfGate from the package. Give <PlandalfGate> a name, a checkout slug in flow and your access check in :check. Put the protected content in the default slot. Use #loading while Plandalf checks access and #fallback="{ trigger }" for an upgrade button that calls trigger().
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 staging site in Plandalf under Settings → Advanced → Test domains. Checkouts there use Stripe test cards. See Test mode.
If it isn't working
- Check that the attribute value matches the slug on the Share screen. A bound value (
:data-plandalf-present="slug") works too, as long as it's set when the element renders. - 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.
