# Move from ExtensionPay

> Keep your ExtPay code as it is. One command switches it to Toolaby and copies your plans; your subscribers move with their cards.

An extension that sells with ExtensionPay moves to Toolaby without its payment code being rewritten. `ExtPay('…')` keeps its methods and the shapes they answer with, and Toolaby answers them.

## Switch the extension

In the extension's folder, with the tool made on the dashboard:

```bash
npx -y toolaby@latest wire <tool-id> --from-extensionpay
```

`wire` moves ExtensionPay only when asked by name. Without `--from-extensionpay`, it stops when it finds ExtensionPay, says where, and writes nothing. The **Wire** button on the Set up page does not move it: it gives this command.

`wire` finds ExtensionPay the way it came into the project, and switches each one:

| The extension has                                                                                                              | `wire`                                                                                                                                                                         |
| ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `import ExtPay from 'extpay'`, or `require('extpay')`                                                                          | Points the line at `toolaby.js`: `import { ExtPay } from './toolaby.js'`                                                                                                       |
| ExtensionPay's own `ExtPay.js`, under a name containing `extpay` or `extensionpay`, loaded by `importScripts()` and `<script>` | Puts Toolaby's in its place. The `importScripts('ExtPay.js')` and `<script>` tags stay as they are                                                                             |
| `ExtPay.module.js` or `ExtPay.common.js`                                                                                       | Replaces it with one line that hands on Toolaby's                                                                                                                              |
| ExtensionPay built into a bundle, such as `dist/background.js`                                                                 | Changes nothing in it, and names it: switch the source it is built from, then build again                                                                                      |
| ExtensionPay's content script on extensionpay.com                                                                              | Takes it out of `manifest.json`, with its host permission. In a WXT, CRXJS or Plasmo project, whose build makes the manifest, it says to take it out of your manifest settings |
| A content security policy whose `connect-src` leaves Toolaby's address out                                                     | Adds Toolaby's address, which every call of Toolaby's needs                                                                                                                    |

`wire` adds no host permission, as for any extension: Toolaby needs the `storage` permission ExtensionPay already asked for, and its address under `externally_connectable`, which Chrome shows no one. So the switched extension's update asks your users nothing new, and Chrome does not switch it off. Where ExtensionPay's content script was there for `onPaid`, the permission warning it brought goes with it.

The rest of the code stays as it is. A use `wire` cannot be sure of, such as `import * as ep from 'extpay'`, is listed to change by hand. Remove the package with `npm uninstall extpay` when you like.

Wired again later, with `upgrade` or `wire`, an extension that has moved needs no flag: Toolaby's `ExtPay.js` is brought up to date with the other Toolaby files.

`wire` also puts Toolaby's background in front of yours, as it does for any extension. Your popup and side panel stay in front, as they were with ExtensionPay: your code says what is paid. The Toolaby popup is written beside them, for `toolaby.showPaywall()`. See [Command line](https://toolaby.app/docs/cli.md).

## Plans

`wire` reads the plans from ExtensionPay's public list for the extension, the one its `getPlans()` reads, and makes each on the tool, on Test. The extension is the one the first `ExtPay('…')` in your code names, with its id written out: an id held in a variable copies no plans. Each keeps its ExtensionPay nickname as its tier, which is what `openPaymentPage('pro')` finds it by. Rename a tier and change that call with it.

| ExtensionPay plan                           | On Toolaby                                                 |
| ------------------------------------------- | ---------------------------------------------------------- |
| `once`                                      | A lifetime plan                                            |
| `month` or `year`, every 1                  | A subscription, monthly or yearly                          |
| Billed every 3 months, or any count above 1 | Not made: Toolaby bills monthly or yearly. `wire` lists it |

A plan the tool already has by that name is left as it is. On Live, `wire` makes none: copy them from Test with **Set up → Copy to Live**. See [Pricing](https://toolaby.app/docs/pricing.md).

## Buyers

ExtensionPay keeps paying customers in your own Stripe account, the one it charged on. Its dashboard has no export; ExtensionPay [asks to be emailed](https://github.com/Glench/ExtPay/discussions/166) for one.

1. **Subscribers.** Copy your customers from that account to the one under **Configure → Payments**, in Stripe, then move their subscriptions on the tool's **Import** page. Each keeps their price, renewal day and card, and nobody is charged twice. Do this before you publish the switched extension. See [Move subscriptions from another Stripe account](https://toolaby.app/docs/move-subscriptions.md).
2. **One-time buyers.** Export the payments from your Stripe Dashboard as CSV, and keep one row per buyer's address. Rename the address column to `email`; other columns are ignored. Leave out failed and refunded payments. Import them on the tool's **Import** page as licences: up to 100 on Hobby, all of them on Pro. See [Migrate existing customers](https://toolaby.app/docs/migrate.md#from-a-file).
3. **Each buyer signs in** with the address they paid with, by Google or by an email link, and the extension unlocks. On another computer they sign in there too, as they did with ExtensionPay.

Keep ExtensionPay connected to your Stripe account until every user has the switched extension, and until the last old subscription has ended: the **Import** page says when. Disconnecting it is permanent.

## The calls, under Toolaby

| ExtPay                      | Toolaby answers                                                                                                                                                                       |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `startBackground()`         | Starts Toolaby's background, once. `wire` already does                                                                                                                                |
| `getUser()`                 | ExtensionPay's `User`: `paid`, `paidAt`, `email`, `installedAt`, `plan`, `subscriptionStatus` and `subscriptionCancelAt`, from the [User](https://toolaby.app/docs/reference/objects.md#user) Toolaby keeps |
| `getPlans()`                | ExtensionPay's `Plan` for each plan the tool sells. The nickname is the plan's id                                                                                                     |
| `openPaymentPage(nickname)` | The tool's checkout page, the plan chosen: by id, then by tier, then by name                                                                                                          |
| `openLoginPage()`           | Toolaby's sign-in                                                                                                                                                                     |
| `openTrialPage()`           | The tool's checkout page. A subscription plan with a free trial starts it there, at Stripe Checkout, which takes the card and charges it when the trial ends                          |
| `onPaid`                    | When the user becomes paid: a purchase, a trial that starts, or a sign-in that brought one                                                                                            |
| `onTrialStarted`            | When a free trial starts                                                                                                                                                              |

The trial is the plan's own, run on Stripe, and `paid` is true while it lasts. `trialStartedAt` is set so that ExtensionPay's usual check, `now - user.trialStartedAt < 7 days`, answers as Toolaby's trial does: now while the trial runs, a year before it ended once it has.

`ExtPay('…')` takes your ExtensionPay id and ignores it: the tool is the one `toolaby.config.js` names. In TypeScript, `ExtPay` and its types come from `toolaby.d.ts`.
