> Move code written for the first Plandalf SDK to the current one: renamed methods and attributes, gates instead of paywall dispatch, and the new event names.

Source: https://plandalf.com/docs/help/migrate-from-v1

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

Before

Now

Notes

`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](https://plandalf.com/docs/developers/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 button

`data-plandalf-apply-promo`

Still 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](https://plandalf.com/docs/developers/promos-from-code#countdown).

`promo(slug)` as a one-off lookup

`plandalf.promo(slug)` handle

It 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](https://plandalf.com/docs/get-started/test-mode).

`onComplete`, `onClose`, `onError`

`await plandalf.present(…)`

The callbacks still run for now.

`preload('checkout')`

Nothing

The SDK downloads the checkout when the page is idle. `data-prefetch="false"` turns that off.

`plandalf('init', { publicKey })`

Nothing

The SDK uses the host it loaded from. No public key is needed.

Orders

Invoices

The dashboard, webhooks (`invoice.paid` and the rest) and the SDK's `purchase` event all use invoices.

## New event names

Before

Now

`flow:start`

`start`

`pay:complete`

`purchase`

`flow:complete`, DOM `plandalf:flow-complete`

`complete`, DOM `plandalf:complete`

`flow:cancel`, DOM `plandalf:flow-cancel`

`cancel`, DOM `plandalf:cancel`

See [Events](https://plandalf.com/docs/developers/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

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

### Now

```js
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](https://plandalf.com/docs/developers/gates).

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

```js
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](https://plandalf.com/docs/developers/react).

## 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](https://plandalf.com/docs/get-started/test-mode), 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](https://plandalf.com/docs/api/webhooks).
    

Something wrong or missing? Email [hello@plandalf.com](mailto:hello@plandalf.com).
