# CLI

`paylynks` sets up an app for payments in one command.

```bash
npx paylynks init
```

Until the package is on npm, run it from PayLynks directly:

```bash
npx https://paylynks.io/downloads/paylynks-cli.tgz init
```

## init

1. Shows the files it will add and asks to continue.
2. Opens `https://paylynks.io/cli` in your browser with a code. Sign in, check the code matches, pick the company, approve. (If your project already has `PAYLYNKS_SECRET_KEY`, it uses that and skips sign-in.)
3. Creates new **test** API keys and writes them to your env file: `.env.local` for Next.js, `supabase/functions/.env` for Vite/React and Supabase, `.env` for Express. The keys are minted at that moment and returned once; they're never printed or stored by PayLynks in plain text. The env file is added to `.gitignore` if it isn't already covered.
4. Detects your framework and writes starter files. For Next.js (App Router, with or without `src/`):
   - `app/api/paylynks/checkout/route.ts`
   - `components/PayLynksCheckout.tsx`
   - `app/checkout/page.tsx`
   - `app/api/paylynks/webhook/route.ts`

   For Vite/React it writes `src/PayLynksCheckout.jsx`, and if there's a `supabase/` folder, `supabase/functions/paylynks-checkout/index.ts`.
5. Never overwrites an existing file unless you pass `--force`.

Options: `--secret-key sk_test_… ` to skip the browser (CI, agents), `--framework nextjs|react|supabase|node|html`, `--force`, `--yes`, `--no-browser`, `--dir <path>`.

## webhooks add

After you deploy, register your webhook URL and save its signing secret to `.env.local`:

```bash
npx paylynks webhooks add https://your-app.com/api/paylynks/webhook
```

Use `npx paylynks webhooks test <endpoint_id>` to send a signed test event.

## Other commands

- `npx paylynks login` — sign in again and write fresh test keys to your env file.
- `npx paylynks webhooks list` — list your endpoints.
- `npx paylynks docs [page]` — print a docs page as markdown (no page: the llms.txt index).

Revoke keys the CLI created under **Developers → API keys** in the dashboard.
