PlandalfDocsSign inStart free trial

Help

Migrate from Plandalf v1

If your site or app was built on the first Plandalf SDK, some names have changed and the paywall dispatcher has been replaced by gates. This page lists every change and the code to replace. Most changes are a rename.

Renamed methods, attributes and options

BeforeNowNotes
setUser(token)plandalf.identify(token)The old name still works for now. identify() takes only a signed token and resolves true or false. See Identify buyers.
resetUser()plandalf.reset()The old name still works for now.
data-plandalf-checkout="…"data-plandalf-present="…"The old attribute no longer does anything.
data-plandalf-mount="checkout" with data-plandalf-template="…"data-plandalf-mount="…"Put the checkout slug in data-plandalf-mount. The old pair still works for now.
data-plandalf-countdown="…"data-plandalf-promo="…"The old attribute no longer does anything.
data-plandalf-promo on a buy buttondata-plandalf-apply-promoStill works, with a console warning. data-plandalf-promo on its own element shows the countdown.
countdown()plandalf('promo', slug, { target })Or <div data-plandalf-promo>. See Deadline timers from code.
promo(slug) as a one-off lookupplandalf.promo(slug) handleIt now stays live: it checks the deadline timer every second and redirects to the tier's page unless you pass redirect: false.
?ref= in links?pf_ref=?ref= is still read when you haven't set data-config-ref.
mode: 'slideout' (how it opens)frame: 'slideout'mode now means test or live.
environment: 'test'mode: 'test'For hosted links, use the test link on the Share screen; ?mode=test added by hand isn't enough. See Test mode.
onComplete, onClose, onErrorawait plandalf.present(…)The callbacks still run for now.
preload('checkout')NothingThe SDK downloads the checkout when the page is idle. data-prefetch="false" turns that off.
plandalf('init', { publicKey })NothingThe SDK uses the host it loaded from. No public key is needed.
OrdersInvoicesThe dashboard, webhooks (invoice.paid and the rest) and the SDK's purchase event all use invoices.

New event names

BeforeNow
flow:startstart
pay:completepurchase
flow:complete, DOM plandalf:flow-completecomplete, DOM plandalf:complete
flow:cancel, DOM plandalf:flow-cancelcancel, DOM plandalf:cancel

See Events for what each one carries.

Replace paywall dispatch with a gate

The first SDK opened paywalls with isWorkflowActive() and dispatch(), then told you about the result through a global checkout-success event. The current SDK has neither. A gate does the same job in one call: it runs your access check, opens the checkout when the check fails, then checks again with fresh data.

Before

// first SDK
const sdk = window.plandalf;
if (sdk.isWorkflowActive("automation")) {
  sdk.dispatch("automation");
}
sdk.on("checkout-success", () => refreshBilling());

Now

plandalf('ready', () => {
  plandalf.addGate('automation', 'automation-add-on', (fresh = billing) => fresh.features.automation === true);
});

async function enableAutomation() {
  const { access, status } = await plandalf.gate('automation', async () => {
    billing = await fetch('/api/billing').then((r) => r.json()); // your server's current view
    return billing;
  });
  if (access) await turnOnAutomation();
  else if (status === 'purchased') showPending(); // paid, but your server hasn't caught up yet
}

Your own code still decides what each user has paid for, and your server still checks it before doing the work. See Gates.

For a plain upgrade button with nothing to gate, await the checkout instead:

const result = await plandalf.present('upgrade-to-pro');
if (result.status === 'complete') await refreshBilling();

React

useGate(), <Gate> and usePresent() are in @plandalf/react 2.0, which isn't on npm yet; npm's 1.1.6 has only the older iframe embeds. Until 2.0 is published, use the hosted script and the code above from a React effect or click handler. See React package.

Move over one piece at a time

  1. Load the current script

    Copy the script tag from a checkout's Share screen. It loads from your organization's own host.

  2. Rename

    Search your code and page builder for the old names in the tables above and replace them.

  3. Replace each dispatcher

    Turn one dispatch() into a gate, test it with a test card on a test domain, then do the next.

  4. Check your listeners

    Anything listening for checkout-success or the old event names won't hear anything. Move it to the gate's result, the checkout's result or the new events. For your server, use webhooks.