# Quick start

> Your first payment in five minutes — first without code, then with two calls and a webhook.

Everything here works in **test mode**: test networks, test coins, nothing real moves. Switch to live when it feels right.

> **Note:** Rather see it? [The same, step by step in pictures](https://pay.perly.io/integrate).

## Without code: a payment link

1. **Sign up** — [Start free](https://pay.perly.io/login) with your email. No password — we send a code.
2. **Connect a wallet** — Dashboard → Wallets. Add the public key from your Ledger or Trezor. See [Wallets](https://pay.perly.io/docs/wallets.md).
3. **Make a product** — Dashboard → Products. A name and a price is enough.
4. **Make a link** — Dashboard → Links → New. Copy the `/l/…` address.
5. **Pay it** — Open the link, pick a coin, and press **Simulate payment**. The invoice turns **Paid** and a receipt is sent.

> **Note:** That's a real checkout. Share the same kind of link in live mode and buyers pay straight to your wallet.

## With code: two calls

Get a test key in Dashboard → Developers. It starts with `sk_test_`. Keep it on your server.

**Node**

```bash
npm install perly-pay
```

**PHP**

```bash
composer require perly/perly-pay
```

**Node**

```js
import { PerlyPay } from "perly-pay";

const pay = new PerlyPay(process.env.PERLY_PAY_SECRET_KEY); // sk_test_…

// 1. Make an invoice (amounts in cents)
const invoice = await pay.invoices.create({
  amount: 2400,
  currency: "USD",
  description: "1,000 API credits",
  customer: { email: "ada@example.com" },
  metadata: { orderId: "1042" },
});

// 2. Send the buyer to pay it
redirect(invoice.url); // https://pay.perly.io/i/<uuid>
```

**PHP**

```php
$perly = new \Perly\Pay\PerlyPay(getenv('PERLY_PAY_SECRET_KEY')); // sk_test_…

// 1. Make an invoice (amounts in cents)
$invoice = $perly->invoices->create([
    'amount' => 2400,
    'currency' => 'USD',
    'description' => '1,000 API credits',
    'customer' => ['email' => 'ada@example.com'],
    'metadata' => ['orderId' => '1042'],
]);

// 2. Send the buyer to pay it
header('Location: ' . $invoice['url'], true, 303);
```

**curl**

```bash
curl https://pay.perly.io/api/v1/invoices \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"amount":2400,"currency":"USD","description":"1,000 API credits"}'
```

The buyer picks bitcoin or a stablecoin, scans, pays. The money goes to an address made from **your** key.

## Know when it's paid: a webhook

Add an endpoint in Dashboard → Developers → Webhooks and copy its `whsec_…` secret. Then check every delivery's signature before you trust it.

**Node**

```js
app.post("/webhooks/perly", express.raw({ type: "application/json" }), (req, res) => {
  const event = pay.webhooks.verify(
    req.body,                                // the raw bytes, not parsed JSON
    req.header("Perly-Signature"),
    process.env.PERLY_PAY_WEBHOOK_SECRET,
  ); // throws if the signature is wrong or old

  if (event.type === "invoice.fulfilled") {
    ship(event.data.object.metadata.orderId);
  }
  res.sendStatus(200);
});
```

**PHP**

```php
$event = \Perly\Pay\Webhook::verify(
    file_get_contents('php://input'),            // the raw body, not json_decode'd
    $_SERVER['HTTP_PERLY_SIGNATURE'] ?? null,
    getenv('PERLY_PAY_WEBHOOK_SECRET'),
); // throws if the signature is wrong or old

if ($event['type'] === 'invoice.fulfilled') {
    ship($event['data']['object']['metadata']['orderId']);
}
http_response_code(200);
```

Both SDKs, what they cover and how they retry: [SDKs](https://pay.perly.io/docs/sdks.md).

> **Note:** Ship on `invoice.fulfilled`, not on `invoice.paid`: fulfilled comes once, after screening. See [Webhooks](https://pay.perly.io/docs/webhooks.md).

## Go live

- Connect your **live** wallet keys (mainnet).
- Make a live key (`sk_live_…`) and a live webhook endpoint.
- Test mode stays as it is, beside live. The two never mix.
