# paddle

Paddle Billing, a merchant of record (Paddle is the seller, and owes the
tax), over its HTTP API: no package. The whole of it is
[docs/paddle.md](../../docs/paddle.md).

```toml
[packages]
paddle = "../mote/extensions/paddle"
```

```text
use "pkg:paddle/paddle.mote"        // the API
use "pkg:paddle/webhooks.mote"      // POST /paddle/webhook, PaddleSubscriptionKept, the hooks

PaddleButton price="pri_…" label="Go Pro"
fn paddlePaid(t: PaddleTransaction): bool
paddleActive(user, "")
```

Settings: `PADDLE_KEY` (a secret), `PADDLE_LIVE=1` for live (unset: the
sandbox), `PADDLE_WEBHOOK_SECRET` (a secret) with webhooks.mote,
`PADDLE_PRICES`. Optional: `PADDLE_WEBHOOK_TOLERANCE`, `PADDLE_CHECKOUT`,
`PADDLE_API`.

| File | |
|---|---|
| `paddle.mote` | Products and prices (every page), customers (made once or found), transactions and their checkout links, invoices, subscriptions (change and preview with a proration mode, cancel at the end or now and take it back, pause, resume), refunds as adjustments, the portal; `paddleBuy`, `paddleManage`, `PaddleButton`. |
| `webhooks.mote` | `Paddle-Signature` checked, each event kept once, a job that reads each subscription again into `PaddleSubscriptionKept` and calls the hooks. |
| `tests.mote` | Its tests: `use "pkg:paddle/tests.mote"`, then `mote test`. |

**Covered**: what a small SaaS sells through Paddle week to week: a
checkout for a price, the subscription it makes kept by events, plan and
seat changes with a preview, cancel and undo, pause, a refund request, the
portal, the invoice.

**Left out on purpose**: the checkout page itself (Paddle.js on the
program's default payment link: a page of `extern script`); making
products and prices from code (done in Paddle's dashboard); discounts made
from code (a `discount` id is taken); reports, payouts and the business's
balance (Paddle's dashboard); Paddle Classic (the older API, another shape
altogether). Lemon Squeezy, another merchant of record, is not here yet.

**Not yet run against the real Paddle**: only against a stand-in
(`tests/all.sh real_svc_paddle`).
