# API reference

> Every endpoint and object, with each call in curl and Node.

**Base URL:** `https://pay.perly.io/api/v1` (v1.0.0)

Authenticate with your secret key as a bearer token: `sk_test_…` works in test mode, `sk_live_…` in live. The key decides the mode. A key stops working when the team member who made it leaves or may no longer manage keys: make your server's key as an owner, or make a new one then.

Send an `Idempotency-Key` with every POST: a retry with the same key returns the first answer for 24 hours. The SDKs do it for you.

An error answers `{ "error": { "type", "code", "message", "param" } }` with a 4xx or 5xx. A call from a place Perly Pay can't be used, your own server's included, gets `451` with code `region_blocked` ([Sanctions and risk](https://pay.perly.io/sanctions)). Amounts in fiat are integers in cents; on-chain amounts are integer strings in the asset's smallest unit.

**curl**

```bash
curl https://pay.perly.io/api/v1/invoices \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

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

const pay = new PerlyPay(process.env.PERLY_PAY_SECRET_KEY);
```

**PHP**

```php
// composer require perly/perly-pay
use Perly\Pay\PerlyPay;

$perly = new PerlyPay(getenv('PERLY_PAY_SECRET_KEY'));
```

The calls below use these clients: `pay` (Node) and `$perly` (PHP). See [SDKs](https://pay.perly.io/docs/sdks.md).

## Invoices

### List invoices

`GET /invoices`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `limit (query)` | `integer` | How many objects to return, 1–100. Default 10. |
| `cursor (query)` | `string` | `next_cursor` from the previous page. |
| `status (query)` | `string` |   |
| `customer (query)` | `string` | A customer id, `cus_…`. |
| `subscription (query)` | `string` | A subscription id, `sub_…`. |

**Returns:** a page of `Invoice`

**curl**

```bash
curl "https://pay.perly.io/api/v1/invoices?status=paid&limit=10" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const invoices = await pay.invoices.list({
  status: "paid",
  limit: 10,
});
```

**PHP**

```php
$invoices = $perly->invoices->list([
    'status' => 'paid',
    'limit' => 10,
]);
```

### Create an invoice

`POST /invoices`

Lines are prices (`{ price, quantity }`) or your own (`{ description, amount, quantity }`), in one currency. For a single amount, `amount` + `description` is short for one line. `customer` is an id or `{ email }`. A price line may carry its own `description` ("Seat #12"), and `discount` takes an amount off this invoice alone. The buyer pays at `url`, choosing bitcoin or a stablecoin there. Live mode: a new invoice is refused with 403 `bill_overdue` while a Perly Pay bill is unpaid past its 14 days, until it is paid in the dashboard's Billing; invoices already made are still paid.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `line_items` | `object[]` |   |
| `amount` | `integer` | One amount instead of line_items in minor units (cents), an integer. |
| `description` | `string` | With `amount`: what it is for. |
| `currency` | `"USD" \| "EUR"` | For lines without a price. Default: your account's currency. |
| `customer` | `string \| object` | A customer id, or `{ email }` to find or make one. |
| `customer_email` | `string` | Without `customer`: finds or makes the customer by email. |
| `coupon` | `string` |   |
| `discount` | `integer` | A one-off amount off this invoice (a credit you owe the buyer; not with `coupon`) in minor units (cents), an integer. |
| `subscription` | `string` | A subscription id, `sub_…`. |
| `return_url` | `string` | Where the buyer's page sends them back. |
| `expires_in_minutes` | `integer` | Until when a rail may be chosen. |
| `locale` | `string` |   |
| `metadata` | `map` | Your own key–value pairs (≤ 50 keys, values ≤ 500 characters). On an update they are merged in; an empty value removes its key. |

**Returns:** `Invoice`

**curl**

```bash
curl https://pay.perly.io/api/v1/invoices \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "line_items": [
      {
        "price": "price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
        "quantity": 1
      }
    ],
    "customer_email": "ada@example.com",
    "metadata": {
      "order_id": "1042"
    }
  }'
```

**Node**

```js
const invoice = await pay.invoices.create({
  line_items: [
    {
      price: "price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
      quantity: 1,
    },
  ],
  customer_email: "ada@example.com",
  metadata: { order_id: "1042" },
});
```

**PHP**

```php
$invoice = $perly->invoices->create([
    'line_items' => [
        [
            'price' => 'price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50',
            'quantity' => 1,
        ],
    ],
    'customer_email' => 'ada@example.com',
    'metadata' => ['order_id' => '1042'],
]);
```

### Retrieve an invoice

`GET /invoices/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |

**Returns:** `Invoice`

**curl**

```bash
curl https://pay.perly.io/api/v1/invoices/inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const invoice = await pay.invoices.retrieve("inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$invoice = $perly->invoices->retrieve('inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Cancel an invoice

`POST /invoices/{id}/cancel`

Only while nothing has arrived. Money that arrives later is still seen (the address stays watched) and lands in review.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Returns:** `Invoice`

**curl**

```bash
curl https://pay.perly.io/api/v1/invoices/inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50/cancel \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{}'
```

**Node**

```js
const invoice = await pay.invoices.cancel("inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$invoice = $perly->invoices->cancel('inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

## Test mode

### Simulate a payment (test mode only)

`POST /invoices/{id}/simulate`

Test keys only. `full` pays the amount due: the invoice turns paid and is fulfilled — entitlements, license keys, a receipt, and the events your webhooks get. `short` sends half (underpaid), `over` a tenth more (overpaid); those two need the buyer's chain and asset chosen first. For `full`, an invoice with no chain yet gets one: `chain` and `asset` if given, else the first stablecoin offered (refund terms count as accepted).

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `outcome` | `"full" \| "short" \| "over"` | Default full. |
| `chain` | `string` |   |
| `asset` | `"BTC" \| "USDC" \| "USDT"` |   |

**Returns:** `Invoice`

**curl**

```bash
curl https://pay.perly.io/api/v1/invoices/inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50/simulate \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"outcome":"full"}'
```

**Node**

```js
const invoice = await pay.invoices.simulate("inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50", {
  outcome: "full",
});
```

**PHP**

```php
$invoice = $perly->invoices->simulate('inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50', [
    'outcome' => 'full',
]);
```

## Checkout sessions

### List checkout sessions

`GET /checkout_sessions`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `limit (query)` | `integer` | How many objects to return, 1–100. Default 10. |
| `cursor (query)` | `string` | `next_cursor` from the previous page. |
| `status (query)` | `"open" \| "complete" \| "expired"` |   |
| `customer (query)` | `string` | A customer id, `cus_…`. |

**Returns:** a page of `CheckoutSession`

**curl**

```bash
curl "https://pay.perly.io/api/v1/checkout_sessions?limit=10" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const checkoutSessions = await pay.checkoutSessions.list({
  limit: 10,
});
```

**PHP**

```php
$checkoutSessions = $perly->checkoutSessions->list([
    'limit' => 10,
]);
```

### Create a checkout session

`POST /checkout_sessions`

A cart of 1–20 prices in one currency. Send the buyer to `url`, or open it in an overlay with pay.js (`data-session="cs_…"`). The buyer comes back to `return_url` after paying, `cancel_url` if they leave. Live mode: a new session is refused with 403 `bill_overdue` while a Perly Pay bill is unpaid past its 14 days.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `line_items` — required | `object[]` |   |
| `return_url` | `string` | An http(s) URL. |
| `cancel_url` | `string` | An http(s) URL. |
| `customer` | `string` | A customer id, `cus_…`. |
| `customer_email` | `string` |   |
| `coupon` | `string` | A coupon code. |
| `expires_in_minutes` | `integer` | Default 1440 (24 hours). |
| `metadata` | `map` | Your own key–value pairs (≤ 50 keys, values ≤ 500 characters). On an update they are merged in; an empty value removes its key. |

**Returns:** `CheckoutSession`

**curl**

```bash
curl https://pay.perly.io/api/v1/checkout_sessions \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "line_items": [
      {
        "price": "price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
        "quantity": 1
      }
    ],
    "return_url": "https://shop.example/thanks",
    "cancel_url": "https://shop.example/cart",
    "metadata": {
      "order_id": "1042"
    }
  }'
```

**Node**

```js
const session = await pay.checkoutSessions.create({
  line_items: [
    {
      price: "price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
      quantity: 1,
    },
  ],
  return_url: "https://shop.example/thanks",
  cancel_url: "https://shop.example/cart",
  metadata: { order_id: "1042" },
});
```

**PHP**

```php
$session = $perly->checkoutSessions->create([
    'line_items' => [
        [
            'price' => 'price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50',
            'quantity' => 1,
        ],
    ],
    'return_url' => 'https://shop.example/thanks',
    'cancel_url' => 'https://shop.example/cart',
    'metadata' => ['order_id' => '1042'],
]);
```

### Retrieve a checkout session

`GET /checkout_sessions/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |

**Returns:** `CheckoutSession`

**curl**

```bash
curl https://pay.perly.io/api/v1/checkout_sessions/cs_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const session = await pay.checkoutSessions.retrieve("cs_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$session = $perly->checkoutSessions->retrieve('cs_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Expire a checkout session

`POST /checkout_sessions/{id}/expire`

The buyer can no longer pay it. Only an open session.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Returns:** `CheckoutSession`

**curl**

```bash
curl https://pay.perly.io/api/v1/checkout_sessions/cs_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50/expire \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{}'
```

**Node**

```js
const session = await pay.checkoutSessions.expire("cs_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$session = $perly->checkoutSessions->expire('cs_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Open a checkout session's page

`GET /embed/checkout_sessions/{id}` — no key needed

Public. Redirects (302) to the session's hosted checkout. pay.js uses it; `origin` (your page's origin) marks it as embedded so the page can talk back to pay.js.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `origin (query)` | `string` |   |

**Errors**

- `302` — A redirect (Location) to the page.

**curl**

```bash
curl https://pay.perly.io/api/v1/embed/checkout_sessions/cs_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50
```

## Products

### List products

`GET /products`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `limit (query)` | `integer` | How many objects to return, 1–100. Default 10. |
| `cursor (query)` | `string` | `next_cursor` from the previous page. |
| `active (query)` | `"true" \| "false"` |   |

**Returns:** a page of `Product`

**curl**

```bash
curl "https://pay.perly.io/api/v1/products?limit=10" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const products = await pay.products.list({
  limit: 10,
});
```

**PHP**

```php
$products = $perly->products->list([
    'limit' => 10,
]);
```

### Create a product

`POST /products`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `name` — required | `string` |   |
| `description` | `string` |   |
| `image_url` | `string` |   |
| `issues_license` | `boolean` | Issue a license key with every purchase. |
| `license_activation_limit` | `integer` | Instances a key may be active on. |
| `active` | `boolean` |   |
| `metadata` | `map` | Your own key–value pairs (≤ 50 keys, values ≤ 500 characters). On an update they are merged in; an empty value removes its key. |

**Returns:** `Product`

**curl**

```bash
curl https://pay.perly.io/api/v1/products \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Pro plan",
    "description": "Everything in Pro, for a year."
  }'
```

**Node**

```js
const product = await pay.products.create({
  name: "Pro plan",
  description: "Everything in Pro, for a year.",
});
```

**PHP**

```php
$product = $perly->products->create([
    'name' => 'Pro plan',
    'description' => 'Everything in Pro, for a year.',
]);
```

### Retrieve a product

`GET /products/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |

**Returns:** `Product`

**curl**

```bash
curl https://pay.perly.io/api/v1/products/prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const product = await pay.products.retrieve("prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$product = $perly->products->retrieve('prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Update a product

`POST /products/{id}`

Set `active: false` to stop selling it; products are never deleted (invoices point at them).

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `name` | `string` |   |
| `description` | `string \| null` |   |
| `image_url` | `string \| null` |   |
| `issues_license` | `boolean` | Issue a license key with every purchase. |
| `license_activation_limit` | `integer \| null` | Instances a key may be active on. |
| `active` | `boolean` |   |
| `metadata` | `map` | Your own key–value pairs (≤ 50 keys, values ≤ 500 characters). On an update they are merged in; an empty value removes its key. |

**Returns:** `Product`

**curl**

```bash
curl https://pay.perly.io/api/v1/products/prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"description":"Everything in Pro, for a year, with support."}'
```

**Node**

```js
const product = await pay.products.update("prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50", {
  description: "Everything in Pro, for a year, with support.",
});
```

**PHP**

```php
$product = $perly->products->update('prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50', [
    'description' => 'Everything in Pro, for a year, with support.',
]);
```

## Prices

### List prices

`GET /prices`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `limit (query)` | `integer` | How many objects to return, 1–100. Default 10. |
| `cursor (query)` | `string` | `next_cursor` from the previous page. |
| `product (query)` | `string` | A product id, `prod_…`. |
| `model (query)` | `"one_time" \| "pay_what_you_want" \| "fixed_term" \| "subscription" \| "lifetime" \| "credit_pack"` |   |
| `active (query)` | `"true" \| "false"` |   |

**Returns:** a page of `Price`

**curl**

```bash
curl "https://pay.perly.io/api/v1/prices?limit=10" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const prices = await pay.prices.list({
  limit: 10,
});
```

**PHP**

```php
$prices = $perly->prices->list([
    'limit' => 10,
]);
```

### Create a price

`POST /prices`

Every model: one_time, pay_what_you_want (with a minimum), fixed_term (N days of access), subscription (interval, trial, grace, prepay), lifetime (optional cap and cohort tiers), credit_pack. Amounts are immutable; make a new price to change one.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `product` — required | `string` | A product id, `prod_…`. |
| `currency` | `"USD" \| "EUR"` | USD or EUR. Default: your account's currency. |
| `nickname` | `string` |   |
| `refunds` | `object` | Refund terms the buyer accepts at checkout. |
| `metadata` | `map` | Your own key–value pairs (≤ 50 keys, values ≤ 500 characters). On an update they are merged in; an empty value removes its key. |
| `model` — required | `"one_time"` |   |
| `unit_amount` — required | `integer` | Amount in minor units (cents), an integer. |

**Returns:** `Price`

**curl**

```bash
curl https://pay.perly.io/api/v1/prices \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "product": "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
    "model": "one_time",
    "unit_amount": 4900,
    "currency": "USD"
  }'
```

**Node**

```js
const price = await pay.prices.create({
  product: "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  model: "one_time",
  unit_amount: 4900,
  currency: "USD",
});
```

**PHP**

```php
$price = $perly->prices->create([
    'product' => 'prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50',
    'model' => 'one_time',
    'unit_amount' => 4900,
    'currency' => 'USD',
]);
```

### Retrieve a price

`GET /prices/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |

**Returns:** `Price`

**curl**

```bash
curl https://pay.perly.io/api/v1/prices/price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const price = await pay.prices.retrieve("price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$price = $perly->prices->retrieve('price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Update a price

`POST /prices/{id}`

Nickname, active, refund terms (`refunds` replaces them whole; what you leave out takes its default) and metadata. Amounts and the model never change.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `nickname` | `string \| null` |   |
| `active` | `boolean` |   |
| `refunds` | `object` | Refund terms the buyer accepts at checkout. |
| `metadata` | `map` | Your own key–value pairs (≤ 50 keys, values ≤ 500 characters). On an update they are merged in; an empty value removes its key. |

**Returns:** `Price`

**curl**

```bash
curl https://pay.perly.io/api/v1/prices/price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"nickname":"Launch price"}'
```

**Node**

```js
const price = await pay.prices.update("price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50", {
  nickname: "Launch price",
});
```

**PHP**

```php
$price = $perly->prices->update('price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50', [
    'nickname' => 'Launch price',
]);
```

## Customers

### List customers

`GET /customers`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `limit (query)` | `integer` | How many objects to return, 1–100. Default 10. |
| `cursor (query)` | `string` | `next_cursor` from the previous page. |
| `email (query)` | `string` |   |
| `external_id (query)` | `string` |   |

**Returns:** a page of `Customer`

**curl**

```bash
curl "https://pay.perly.io/api/v1/customers?limit=10" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const customers = await pay.customers.list({
  limit: 10,
});
```

**PHP**

```php
$customers = $perly->customers->list([
    'limit' => 10,
]);
```

### Create a customer

`POST /customers`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `email` | `string` |   |
| `name` | `string` |   |
| `external_id` | `string` | Your own id for this buyer (unique). |
| `country` | `string` | ISO 3166-1 alpha-2. |
| `locale` | `string` |   |
| `metadata` | `map` | Your own key–value pairs (≤ 50 keys, values ≤ 500 characters). On an update they are merged in; an empty value removes its key. |

**Returns:** `Customer`

**curl**

```bash
curl https://pay.perly.io/api/v1/customers \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "ada@example.com",
    "name": "Ada Lovelace",
    "external_id": "user_42"
  }'
```

**Node**

```js
const customer = await pay.customers.create({
  email: "ada@example.com",
  name: "Ada Lovelace",
  external_id: "user_42",
});
```

**PHP**

```php
$customer = $perly->customers->create([
    'email' => 'ada@example.com',
    'name' => 'Ada Lovelace',
    'external_id' => 'user_42',
]);
```

### Retrieve a customer

`GET /customers/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |

**Returns:** `Customer`

**curl**

```bash
curl https://pay.perly.io/api/v1/customers/cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const customer = await pay.customers.retrieve("cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$customer = $perly->customers->retrieve('cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Update a customer

`POST /customers/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `email` | `string \| null` |   |
| `name` | `string \| null` |   |
| `external_id` | `string` | Your own id for this buyer (unique). |
| `country` | `string` | ISO 3166-1 alpha-2. |
| `locale` | `string` |   |
| `metadata` | `map` | Your own key–value pairs (≤ 50 keys, values ≤ 500 characters). On an update they are merged in; an empty value removes its key. |

**Returns:** `Customer`

**curl**

```bash
curl https://pay.perly.io/api/v1/customers/cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"name":"Ada King"}'
```

**Node**

```js
const customer = await pay.customers.update("cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50", {
  name: "Ada King",
});
```

**PHP**

```php
$customer = $perly->customers->update('cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50', [
    'name' => 'Ada King',
]);
```

## Subscriptions

### List subscriptions

`GET /subscriptions`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `limit (query)` | `integer` | How many objects to return, 1–100. Default 10. |
| `cursor (query)` | `string` | `next_cursor` from the previous page. |
| `status (query)` | `string` |   |
| `customer (query)` | `string` | A customer id, `cus_…`. |
| `price (query)` | `string` | A price id, `price_…`. |

**Returns:** a page of `Subscription`

**curl**

```bash
curl "https://pay.perly.io/api/v1/subscriptions?status=active&limit=10" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const subscriptions = await pay.subscriptions.list({
  status: "active",
  limit: 10,
});
```

**PHP**

```php
$subscriptions = $perly->subscriptions->list([
    'status' => 'active',
    'limit' => 10,
]);
```

### Create a subscription

`POST /subscriptions`

Renewed by invoice: the customer pays each period themselves. Without a trial the first invoice opens now (`latest_invoice`); the subscription turns active when it is paid.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `customer` — required | `string` | A customer id, `cus_…`. |
| `price` — required | `string` | A subscription price. |
| `quantity` | `integer` |   |
| `coupon` | `string` |   |
| `trial_days` | `integer` | Default: the price's. |
| `metadata` | `map` | Your own key–value pairs (≤ 50 keys, values ≤ 500 characters). On an update they are merged in; an empty value removes its key. |

**Returns:** `Subscription`

**curl**

```bash
curl https://pay.perly.io/api/v1/subscriptions \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": "cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
    "price": "price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50"
  }'
```

**Node**

```js
const subscription = await pay.subscriptions.create({
  customer: "cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  price: "price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
});
```

**PHP**

```php
$subscription = $perly->subscriptions->create([
    'customer' => 'cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50',
    'price' => 'price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50',
]);
```

### Retrieve a subscription

`GET /subscriptions/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |

**Returns:** `Subscription`

**curl**

```bash
curl https://pay.perly.io/api/v1/subscriptions/sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const subscription = await pay.subscriptions.retrieve("sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$subscription = $perly->subscriptions->retrieve('sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Update a subscription

`POST /subscriptions/{id}`

`price`: change plan — an upgrade applies now (prorated), a downgrade at the period end (`pending_price`). `cancel_at_period_end`: stop renewing, or take that back.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `price` | `string` | A price id, `price_…`. |
| `cancel_at_period_end` | `boolean` |   |
| `metadata` | `map` | Your own key–value pairs (≤ 50 keys, values ≤ 500 characters). On an update they are merged in; an empty value removes its key. |

**Returns:** `Subscription`

**curl**

```bash
curl https://pay.perly.io/api/v1/subscriptions/sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"cancel_at_period_end":true}'
```

**Node**

```js
const subscription = await pay.subscriptions.update("sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50", {
  cancel_at_period_end: true,
});
```

**PHP**

```php
$subscription = $perly->subscriptions->update('sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50', [
    'cancel_at_period_end' => true,
]);
```

### Cancel a subscription

`POST /subscriptions/{id}/cancel`

Now, or with `at_period_end: true` when the paid period runs out.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `at_period_end` | `boolean` |   |

**Returns:** `Subscription`

**curl**

```bash
curl https://pay.perly.io/api/v1/subscriptions/sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50/cancel \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"at_period_end":true}'
```

**Node**

```js
const subscription = await pay.subscriptions.cancel("sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50", {
  at_period_end: true,
});
```

**PHP**

```php
$subscription = $perly->subscriptions->cancel('sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50', [
    'at_period_end' => true,
]);
```

### Pause a subscription

`POST /subscriptions/{id}/pause`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Returns:** `Subscription`

**curl**

```bash
curl https://pay.perly.io/api/v1/subscriptions/sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50/pause \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{}'
```

**Node**

```js
const subscription = await pay.subscriptions.pause("sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$subscription = $perly->subscriptions->pause('sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Resume a paused subscription

`POST /subscriptions/{id}/resume`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Returns:** `Subscription`

**curl**

```bash
curl https://pay.perly.io/api/v1/subscriptions/sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50/resume \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{}'
```

**Node**

```js
const subscription = await pay.subscriptions.resume("sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$subscription = $perly->subscriptions->resume('sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Invoice several periods ahead

`POST /subscriptions/{id}/prepay`

Opens one invoice for `periods` periods (up to the price's `prepay_max_periods`); paying it moves the period on.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `periods` — required | `integer` |   |

**Returns:** `Invoice`

**curl**

```bash
curl https://pay.perly.io/api/v1/subscriptions/sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50/prepay \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"periods":3}'
```

**Node**

```js
const invoice = await pay.subscriptions.prepay("sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50", {
  periods: 3,
});
```

**PHP**

```php
$invoice = $perly->subscriptions->prepay('sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50', [
    'periods' => 3,
]);
```

## Payment links

### List payment links

`GET /payment_links`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `limit (query)` | `integer` | How many objects to return, 1–100. Default 10. |
| `cursor (query)` | `string` | `next_cursor` from the previous page. |
| `active (query)` | `"true" \| "false"` |   |
| `price (query)` | `string` | A price id, `price_…`. |

**Returns:** a page of `PaymentLink`

**curl**

```bash
curl "https://pay.perly.io/api/v1/payment_links?limit=10" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const paymentLinks = await pay.paymentLinks.list({
  limit: 10,
});
```

**PHP**

```php
$paymentLinks = $perly->paymentLinks->list([
    'limit' => 10,
]);
```

### Create a payment link

`POST /payment_links`

A page at /l/\<slug> that sells one price. Share it anywhere, or open it with pay.js.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `price` — required | `string` | A price id, `price_…`. |
| `quantity` | `integer` |   |
| `adjustable_quantity` | `boolean` |   |
| `allow_coupons` | `boolean` |   |
| `collect_name` | `boolean` |   |
| `success_url` | `string` | Where the buyer goes after paying. |
| `slug` | `string` | Default: random. |
| `donation` | `object` | Makes the link a donation page. The price must be pay_what_you_want. |
| `metadata` | `map` | Your own key–value pairs (≤ 50 keys, values ≤ 500 characters). On an update they are merged in; an empty value removes its key. |

**Returns:** `PaymentLink`

**curl**

```bash
curl https://pay.perly.io/api/v1/payment_links \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "price": "price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
    "adjustable_quantity": true
  }'
```

**Node**

```js
const paymentLink = await pay.paymentLinks.create({
  price: "price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  adjustable_quantity: true,
});
```

**PHP**

```php
$paymentLink = $perly->paymentLinks->create([
    'price' => 'price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50',
    'adjustable_quantity' => true,
]);
```

### Retrieve a payment link

`GET /payment_links/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |

**Returns:** `PaymentLink`

**curl**

```bash
curl https://pay.perly.io/api/v1/payment_links/plink_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const paymentLink = await pay.paymentLinks.retrieve("plink_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$paymentLink = $perly->paymentLinks->retrieve('plink_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Update a payment link

`POST /payment_links/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `active` | `boolean` |   |
| `quantity` | `integer` |   |
| `adjustable_quantity` | `boolean` |   |
| `allow_coupons` | `boolean` |   |
| `collect_name` | `boolean` |   |
| `success_url` | `string \| null` | An http(s) URL. |
| `donation` | `object` | Replaces the donation page's settings (the link becomes one if it was not). |
| `metadata` | `map` | Your own key–value pairs (≤ 50 keys, values ≤ 500 characters). On an update they are merged in; an empty value removes its key. |

**Returns:** `PaymentLink`

**curl**

```bash
curl https://pay.perly.io/api/v1/payment_links/plink_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"active":false}'
```

**Node**

```js
const paymentLink = await pay.paymentLinks.update("plink_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50", {
  active: false,
});
```

**PHP**

```php
$paymentLink = $perly->paymentLinks->update('plink_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50', [
    'active' => false,
]);
```

## Coupons

### List coupons

`GET /coupons`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `limit (query)` | `integer` | How many objects to return, 1–100. Default 10. |
| `cursor (query)` | `string` | `next_cursor` from the previous page. |
| `active (query)` | `"true" \| "false"` |   |
| `code (query)` | `string` |   |

**Returns:** a page of `Coupon`

**curl**

```bash
curl "https://pay.perly.io/api/v1/coupons?limit=10" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const coupons = await pay.coupons.list({
  limit: 10,
});
```

**PHP**

```php
$coupons = $perly->coupons->list([
    'limit' => 10,
]);
```

### Create a coupon

`POST /coupons`

Give `percent_off`, or `amount_off` with its `currency`.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `code` — required | `string` | What the buyer types. Case does not matter. |
| `percent_off` | `integer` |   |
| `amount_off` | `integer` | Amount off in minor units (cents), an integer. |
| `currency` | `"USD" \| "EUR"` | USD or EUR. |
| `duration` | `"once" \| "repeating" \| "forever"` | For subscriptions: once (default), repeating, forever. |
| `duration_periods` | `integer` | With duration `repeating`. |
| `max_redemptions` | `integer` |   |
| `products` | `string[]` | Only these products. Empty: every product. |
| `expires_at` | `string` |   |

**Returns:** `Coupon`

**curl**

```bash
curl https://pay.perly.io/api/v1/coupons \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"code":"WELCOME10","percent_off":10}'
```

**Node**

```js
const coupon = await pay.coupons.create({
  code: "WELCOME10",
  percent_off: 10,
});
```

**PHP**

```php
$coupon = $perly->coupons->create([
    'code' => 'WELCOME10',
    'percent_off' => 10,
]);
```

### Retrieve a coupon

`GET /coupons/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |

**Returns:** `Coupon`

**curl**

```bash
curl https://pay.perly.io/api/v1/coupons/cpn_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const coupon = await pay.coupons.retrieve("cpn_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$coupon = $perly->coupons->retrieve('cpn_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Update a coupon

`POST /coupons/{id}`

Turn it off, move its end, or change how many may use it. What it takes off never changes.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `active` | `boolean` |   |
| `expires_at` | `string \| null` |   |
| `max_redemptions` | `integer \| null` |   |

**Returns:** `Coupon`

**curl**

```bash
curl https://pay.perly.io/api/v1/coupons/cpn_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"max_redemptions":100}'
```

**Node**

```js
const coupon = await pay.coupons.update("cpn_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50", {
  max_redemptions: 100,
});
```

**PHP**

```php
$coupon = $perly->coupons->update('cpn_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50', [
    'max_redemptions' => 100,
]);
```

## Entitlements

### Check access

`GET /entitlements/check`

One call: may this customer use this product now? Name the customer by `customer`, `customer_email` or `customer_external_id`, and the product by `product` (or `price`).

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `customer (query)` | `string` | A customer id, `cus_…`. |
| `customer_email (query)` | `string` |   |
| `customer_external_id (query)` | `string` |   |
| `product (query)` | `string` | A product id, `prod_…`. |
| `price (query)` | `string` | A price id, `price_…`. |

**Returns:** `EntitlementCheck`

**curl**

```bash
curl "https://pay.perly.io/api/v1/entitlements/check?customer_email=ada%40example.com&product=prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const entitlementCheck = await pay.entitlements.check({
  customer_email: "ada@example.com",
  product: "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
});
```

**PHP**

```php
$entitlementCheck = $perly->entitlements->check([
    'customer_email' => 'ada@example.com',
    'product' => 'prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50',
]);
```

### List entitlements

`GET /entitlements`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `limit (query)` | `integer` | How many objects to return, 1–100. Default 10. |
| `cursor (query)` | `string` | `next_cursor` from the previous page. |
| `customer (query)` | `string` | A customer id, `cus_…`. |
| `product (query)` | `string` | A product id, `prod_…`. |
| `subscription (query)` | `string` | A subscription id, `sub_…`. |

**Returns:** a page of `Entitlement`

**curl**

```bash
curl "https://pay.perly.io/api/v1/entitlements?limit=10" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const entitlements = await pay.entitlements.list({
  limit: 10,
});
```

**PHP**

```php
$entitlements = $perly->entitlements->list([
    'limit' => 10,
]);
```

### Retrieve an entitlement

`GET /entitlements/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |

**Returns:** `Entitlement`

**curl**

```bash
curl https://pay.perly.io/api/v1/entitlements/ent_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const entitlement = await pay.entitlements.retrieve("ent_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$entitlement = $perly->entitlements->retrieve('ent_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Spend credits

`POST /entitlements/{id}/consume`

Spends credits from one credit pack, atomically. Refused when fewer are left. `action` labels the spend for your reports; with an `Idempotency-Key` a retry never spends twice. To spend from a customer's packs together, use POST /credits/consume.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `credits` — required | `integer` |   |
| `action` | `string` | Your label for what the credits paid for. |

**Returns:** `Entitlement`

**curl**

```bash
curl https://pay.perly.io/api/v1/entitlements/ent_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50/consume \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"credits":1,"action":"chat"}'
```

**Node**

```js
const entitlement = await pay.entitlements.consume("ent_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50", {
  credits: 1,
  action: "chat",
});
```

**PHP**

```php
$entitlement = $perly->entitlements->consume('ent_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50', [
    'credits' => 1,
    'action' => 'chat',
]);
```

## Credits

### Retrieve a credit balance

`GET /credits/balance`

What a customer has left to spend — on one product's credit packs (`product`), or on all of them — with the buyer's own `top_up_url`: a stable page where they choose a pack and pay. Show it, or send it when `low`.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `customer (query)` | `string` | A customer id, `cus_…`. |
| `customer_email (query)` | `string` |   |
| `customer_external_id (query)` | `string` |   |
| `product (query)` | `string` | A product id, `prod_…`. |

**Returns:** `CreditBalance`

**curl**

```bash
curl "https://pay.perly.io/api/v1/credits/balance?customer_external_id=user_42&product=prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const creditBalance = await pay.credits.balance({
  customer_external_id: "user_42",
  product: "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
});
```

**PHP**

```php
$creditBalance = $perly->credits->balance([
    'customer_external_id' => 'user_42',
    'product' => 'prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50',
]);
```

### Spend credits

`POST /credits/consume`

Spends `credits` from the customer's packs — of `product`, or of any — oldest first, atomically, never below zero. Refused with `insufficient_credits` (409) when fewer are left; nothing is spent then. Send an `Idempotency-Key`: a retry with it returns the first spend and never spends twice, however late it comes. Crossing the product's low-balance threshold sends `credits.low`; reaching zero, `credits.depleted`.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `customer` | `string` | A customer id, `cus_…`. |
| `customer_email` | `string` |   |
| `customer_external_id` | `string` |   |
| `credits` — required | `integer` |   |
| `product` | `string` | A product id, `prod_…`. |
| `action` | `string` | Your label for what the credits paid for (`chat`, `image.hd`, `api/search`). Shows in your dashboard by action. |

**Returns:** `CreditUsage`

**curl**

```bash
curl https://pay.perly.io/api/v1/credits/consume \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"customer_external_id":"user_42","credits":1,"action":"chat"}'
```

**Node**

```js
const creditUsage = await pay.credits.consume({
  customer_external_id: "user_42",
  credits: 1,
  action: "chat",
});
```

**PHP**

```php
$creditUsage = $perly->credits->consume([
    'customer_external_id' => 'user_42',
    'credits' => 1,
    'action' => 'chat',
]);
```

### List credit spends

`GET /credits/usage`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `limit (query)` | `integer` | How many objects to return, 1–100. Default 10. |
| `cursor (query)` | `string` | `next_cursor` from the previous page. |
| `customer (query)` | `string` | A customer id, `cus_…`. |
| `product (query)` | `string` | A product id, `prod_…`. |
| `action (query)` | `string` | Your label for what the credits paid for (`chat`, `image.hd`, `api/search`). Shows in your dashboard by action. |

**Returns:** a page of `CreditUsage`

**curl**

```bash
curl "https://pay.perly.io/api/v1/credits/usage?customer=cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50&action=chat&limit=10" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const credits = await pay.credits.usage({
  customer: "cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  action: "chat",
  limit: 10,
});
```

**PHP**

```php
$credits = $perly->credits->usage([
    'customer' => 'cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50',
    'action' => 'chat',
    'limit' => 10,
]);
```

## License keys

### Validate a license key

`POST /license_keys/validate` — no key needed

Public: call it from your app with the license key and your `product`, no secret key. `product` is required (`parameter_missing` without it): a key of any other product or account answers `wrong_product`. With `instance` (an activation id) or `instance_name`, also checks that this instance is activated.

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `key` — required | `string` | XXXXX-XXXXX-XXXXX-XXXXX |
| `product` | `string` | Your product, `prod_…`. Required unless you call with your secret key: a key for any other product, or from another account, is refused. |
| `merchant` | `string` | Your account's slug. Only needed if two accounts ever share a key (practically never). |
| `livemode` | `boolean` | Optional: `true` accepts only a live key, `false` only a test-mode one. Your product's own mode either way. |
| `instance` | `string` | An activation id, `act_…`. |
| `instance_name` | `string` | Your name for the machine or site, e.g. a hostname. |

**Returns:** `LicenseCheck`

**curl**

```bash
curl https://pay.perly.io/api/v1/license_keys/validate \
  -H "Content-Type: application/json" \
  -d '{
    "key": "PERLY-8KQ2-X7LM-4N9P",
    "product": "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50"
  }'
```

**Node**

```js
const licenseCheck = await pay.licenseKeys.validate({
  key: "PERLY-8KQ2-X7LM-4N9P",
  product: "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
});
```

**PHP**

```php
$licenseCheck = $perly->licenseKeys->validate([
    'key' => 'PERLY-8KQ2-X7LM-4N9P',
    'product' => 'prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50',
]);
```

### Activate a license key on an instance

`POST /license_keys/activate` — no key needed

Public, with the license key and your `product` (required). Activating the same `instance_name` again returns its activation. Refused (`limit_reached`) when the key is active on as many instances as it allows.

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `key` — required | `string` | XXXXX-XXXXX-XXXXX-XXXXX |
| `product` | `string` | Your product, `prod_…`. Required unless you call with your secret key: a key for any other product, or from another account, is refused. |
| `merchant` | `string` | Your account's slug. Only needed if two accounts ever share a key (practically never). |
| `livemode` | `boolean` | Optional: `true` accepts only a live key, `false` only a test-mode one. Your product's own mode either way. |
| `instance_name` — required | `string` | Your name for the machine or site, e.g. a hostname. |

**Returns:** `LicenseCheck`

**curl**

```bash
curl https://pay.perly.io/api/v1/license_keys/activate \
  -H "Content-Type: application/json" \
  -d '{
    "key": "PERLY-8KQ2-X7LM-4N9P",
    "product": "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
    "instance_name": "ada-laptop"
  }'
```

**Node**

```js
const licenseCheck = await pay.licenseKeys.activate({
  key: "PERLY-8KQ2-X7LM-4N9P",
  product: "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  instance_name: "ada-laptop",
});
```

**PHP**

```php
$licenseCheck = $perly->licenseKeys->activate([
    'key' => 'PERLY-8KQ2-X7LM-4N9P',
    'product' => 'prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50',
    'instance_name' => 'ada-laptop',
]);
```

### Deactivate a license key on an instance

`POST /license_keys/deactivate` — no key needed

Public, with the license key and your `product` (required). Frees a seat: give the activation id (`instance`) or the `instance_name`.

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `key` — required | `string` | XXXXX-XXXXX-XXXXX-XXXXX |
| `product` | `string` | Your product, `prod_…`. Required unless you call with your secret key: a key for any other product, or from another account, is refused. |
| `merchant` | `string` | Your account's slug. Only needed if two accounts ever share a key (practically never). |
| `livemode` | `boolean` | Optional: `true` accepts only a live key, `false` only a test-mode one. Your product's own mode either way. |
| `instance` | `string` |   |
| `instance_name` | `string` | Your name for the machine or site, e.g. a hostname. |

**Returns:** `LicenseCheck`

**curl**

```bash
curl https://pay.perly.io/api/v1/license_keys/deactivate \
  -H "Content-Type: application/json" \
  -d '{
    "key": "PERLY-8KQ2-X7LM-4N9P",
    "product": "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
    "instance_name": "ada-laptop"
  }'
```

**Node**

```js
const licenseCheck = await pay.licenseKeys.deactivate({
  key: "PERLY-8KQ2-X7LM-4N9P",
  product: "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  instance_name: "ada-laptop",
});
```

**PHP**

```php
$licenseCheck = $perly->licenseKeys->deactivate([
    'key' => 'PERLY-8KQ2-X7LM-4N9P',
    'product' => 'prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50',
    'instance_name' => 'ada-laptop',
]);
```

### List license keys

`GET /license_keys`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `limit (query)` | `integer` | How many objects to return, 1–100. Default 10. |
| `cursor (query)` | `string` | `next_cursor` from the previous page. |
| `customer (query)` | `string` | A customer id, `cus_…`. |
| `product (query)` | `string` | A product id, `prod_…`. |
| `status (query)` | `"active" \| "suspended" \| "revoked" \| "expired"` |   |

**Returns:** a page of `LicenseKey`

**curl**

```bash
curl "https://pay.perly.io/api/v1/license_keys?limit=10" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const licenseKeys = await pay.licenseKeys.list({
  limit: 10,
});
```

**PHP**

```php
$licenseKeys = $perly->licenseKeys->list([
    'limit' => 10,
]);
```

### Retrieve a license key

`GET /license_keys/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |

**Returns:** `LicenseKey`

**curl**

```bash
curl https://pay.perly.io/api/v1/license_keys/lic_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const licenseKey = await pay.licenseKeys.retrieve("lic_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$licenseKey = $perly->licenseKeys->retrieve('lic_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Revoke a license key

`POST /license_keys/{id}/revoke`

For good: validation answers `revoked` from now on.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Returns:** `LicenseKey`

**curl**

```bash
curl https://pay.perly.io/api/v1/license_keys/lic_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50/revoke \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{}'
```

**Node**

```js
const licenseKey = await pay.licenseKeys.revoke("lic_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$licenseKey = $perly->licenseKeys->revoke('lic_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

## Buyer portal

### Create a buyer-portal link

`POST /portal_sessions`

A one-hour link where your customer sees their subscriptions, receipts and license keys. Make one when they click "Billing" in your app and redirect them to `url`.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `customer` — required | `string` | A customer id, `cus_…`. |
| `return_url` | `string` | Where "Back" goes. |

**Returns:** `PortalSession`

**curl**

```bash
curl https://pay.perly.io/api/v1/portal_sessions \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": "cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
    "return_url": "https://shop.example/account"
  }'
```

**Node**

```js
const portalSession = await pay.portalSessions.create({
  customer: "cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  return_url: "https://shop.example/account",
});
```

**PHP**

```php
$portalSession = $perly->portalSessions->create([
    'customer' => 'cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50',
    'return_url' => 'https://shop.example/account',
]);
```

## Payments

### List payments

`GET /payments`

Transfers seen on chain into addresses we handed out, newest first.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `limit (query)` | `integer` | How many objects to return, 1–100. Default 10. |
| `cursor (query)` | `string` | `next_cursor` from the previous page. |
| `invoice (query)` | `string` | A invoice id, `inv_…`. |
| `asset (query)` | `"BTC" \| "USDC" \| "USDT"` |   |

**Returns:** a page of `Payment`

**curl**

```bash
curl "https://pay.perly.io/api/v1/payments?limit=10" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const payments = await pay.payments.list({
  limit: 10,
});
```

**PHP**

```php
$payments = $perly->payments->list([
    'limit' => 10,
]);
```

### Retrieve a payment

`GET /payments/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |

**Returns:** `Payment`

**curl**

```bash
curl https://pay.perly.io/api/v1/payments/pay_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const payment = await pay.payments.retrieve("pay_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$payment = $perly->payments->retrieve('pay_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

## Refunds

### Quote a refund

`GET /refunds/quote`

What a refund of this invoice would be now: the amount left, today's network fee, what you would send.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `invoice (query)` — required | `string` | A invoice id, `inv_…`. |

**Returns:** `RefundQuote`

**curl**

```bash
curl "https://pay.perly.io/api/v1/refunds/quote?invoice=inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const refundQuote = await pay.refunds.quote({
  invoice: "inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
});
```

**PHP**

```php
$refundQuote = $perly->refunds->quote([
    'invoice' => 'inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50',
]);
```

### List refunds

`GET /refunds`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `limit (query)` | `integer` | How many objects to return, 1–100. Default 10. |
| `cursor (query)` | `string` | `next_cursor` from the previous page. |
| `invoice (query)` | `string` | A invoice id, `inv_…`. |
| `status (query)` | `"requested" \| "awaiting_address" \| "ready_to_send" \| "sent" \| "confirmed" \| "canceled"` |   |

**Returns:** a page of `Refund`

**curl**

```bash
curl "https://pay.perly.io/api/v1/refunds?limit=10" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const refunds = await pay.refunds.list({
  limit: 10,
});
```

**PHP**

```php
$refunds = $perly->refunds->list([
    'limit' => 10,
]);
```

### Open a refund

`POST /refunds`

Starts a refund in the asset that was paid. We email the buyer a link to give an address; the link is never returned, since whoever holds it decides where the money goes. With no email on the invoice, the owner makes one in the dashboard. When the address is checked, the refund is `ready_to_send` with `amount_to_send`. Refused with `sanctioned_sender` when money on the invoice came from an address on a sanctions list, or one the coin's issuer froze: sending it back may itself be prohibited, so nothing refunds it — leave it and talk to a lawyer.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `invoice` — required | `string` | A invoice id, `inv_…`. |
| `amount` | `string` | In the paid asset's smallest unit. Default: everything still refundable. |
| `reason` | `string` |   |

**Returns:** `Refund`

**curl**

```bash
curl https://pay.perly.io/api/v1/refunds \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"invoice":"inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50"}'
```

**Node**

```js
const refund = await pay.refunds.create({
  invoice: "inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
});
```

**PHP**

```php
$refund = $perly->refunds->create([
    'invoice' => 'inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50',
]);
```

### Retrieve a refund

`GET /refunds/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |

**Returns:** `Refund`

**curl**

```bash
curl https://pay.perly.io/api/v1/refunds/re_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const refund = await pay.refunds.retrieve("re_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$refund = $perly->refunds->retrieve('re_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Record the refund's transaction

`POST /refunds/{id}/mark_sent`

After you sent `amount_to_send` to `refund_address`. We read that transaction on the network: it must pay the refund address the amount to send. Then the refund is `sent` (or `confirmed`, with its receipt, when already deep). This is the only way a refund moves on: a transfer we merely see at the address may be someone else's, so it never counts by itself.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `txid` — required | `string` | The transaction hash. |

**Returns:** `Refund`

**curl**

```bash
curl https://pay.perly.io/api/v1/refunds/re_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50/mark_sent \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "txid": "0x9f1c3e5a7b2d4f6081a3c5e7f9b1d3f5a7c9e1b3d5f7a9c1e3b5d7f9a1c3e5b7"
  }'
```

**Node**

```js
const refund = await pay.refunds.markSent("re_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50", {
  txid: "0x9f1c3e5a7b2d4f6081a3c5e7f9b1d3f5a7c9e1b3d5f7a9c1e3b5d7f9a1c3e5b7",
});
```

**PHP**

```php
$refund = $perly->refunds->markSent('re_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50', [
    'txid' => '0x9f1c3e5a7b2d4f6081a3c5e7f9b1d3f5a7c9e1b3d5f7a9c1e3b5d7f9a1c3e5b7',
]);
```

## Receipts

### List receipts

`GET /receipts`

One for every fulfilled payment and every confirmed refund, newest first.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `limit (query)` | `integer` | How many objects to return, 1–100. Default 10. |
| `cursor (query)` | `string` | `next_cursor` from the previous page. |
| `invoice (query)` | `string` | A invoice id, `inv_…`. |
| `kind (query)` | `"payment" \| "refund"` |   |

**Returns:** a page of `Receipt`

**curl**

```bash
curl "https://pay.perly.io/api/v1/receipts?limit=10" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const receipts = await pay.receipts.list({
  limit: 10,
});
```

**PHP**

```php
$receipts = $perly->receipts->list([
    'limit' => 10,
]);
```

### Retrieve a receipt

`GET /receipts/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |

**Returns:** `Receipt`

**curl**

```bash
curl https://pay.perly.io/api/v1/receipts/rcpt_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const receipt = await pay.receipts.retrieve("rcpt_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$receipt = $perly->receipts->retrieve('rcpt_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Download a receipt as PDF

`GET /receipts/{id}/pdf`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `locale (query)` | `string` |   |

**Returns:** `application/pdf`

**curl**

```bash
curl https://pay.perly.io/api/v1/receipts/rcpt_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50/pdf \
  -H "Authorization: Bearer sk_test_…" \
  -o receipt.pdf
```

**Node**

```js
const pdf = await pay.receipts.pdf("rcpt_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$pdf = $perly->receipts->pdf('rcpt_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

## Events

### List events

`GET /events`

What happened in the last 30 days, newest first. `type` filters (`invoice.paid`, or `invoice.*`).

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `limit (query)` | `integer` | How many objects to return, 1–100. Default 10. |
| `cursor (query)` | `string` | `next_cursor` from the previous page. |
| `type (query)` | `string` |   |
| `object (query)` | `string` | Only events about this object (`inv_…`, `sub_…`). |

**Returns:** a page of `Event`

**curl**

```bash
curl "https://pay.perly.io/api/v1/events?type=invoice.fulfilled&limit=10" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const events = await pay.events.list({
  type: "invoice.fulfilled",
  limit: 10,
});
```

**PHP**

```php
$events = $perly->events->list([
    'type' => 'invoice.fulfilled',
    'limit' => 10,
]);
```

### Retrieve an event

`GET /events/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |

**Returns:** `Event`

**curl**

```bash
curl https://pay.perly.io/api/v1/events/evt_1042 \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const event = await pay.events.retrieve("evt_1042");
```

**PHP**

```php
$event = $perly->events->retrieve('evt_1042');
```

## Webhook endpoints

### List webhook endpoints

`GET /webhook_endpoints`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `limit (query)` | `integer` | How many objects to return, 1–100. Default 10. |
| `cursor (query)` | `string` | `next_cursor` from the previous page. |

**Returns:** a page of `WebhookEndpoint`

**curl**

```bash
curl "https://pay.perly.io/api/v1/webhook_endpoints?limit=10" \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const webhookEndpoints = await pay.webhookEndpoints.list({
  limit: 10,
});
```

**PHP**

```php
$webhookEndpoints = $perly->webhookEndpoints->list([
    'limit' => 10,
]);
```

### Create a webhook endpoint

`POST /webhook_endpoints`

The response carries `secret` — the only time you see it. Keep it to verify `Perly-Signature`.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `url` — required | `string` |   |
| `enabled_events` | `"*" \| string[]` | Event types to send, or `["*"]` for every one. |
| `description` | `string` |   |

**Returns:** `WebhookEndpoint`

**curl**

```bash
curl https://pay.perly.io/api/v1/webhook_endpoints \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://shop.example/webhooks/perly",
    "enabled_events": [
      "invoice.fulfilled",
      "refund.confirmed"
    ]
  }'
```

**Node**

```js
const webhookEndpoint = await pay.webhookEndpoints.create({
  url: "https://shop.example/webhooks/perly",
  enabled_events: ["invoice.fulfilled", "refund.confirmed"],
});
```

**PHP**

```php
$webhookEndpoint = $perly->webhookEndpoints->create([
    'url' => 'https://shop.example/webhooks/perly',
    'enabled_events' => ['invoice.fulfilled', 'refund.confirmed'],
]);
```

### Retrieve a webhook endpoint

`GET /webhook_endpoints/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |

**Returns:** `WebhookEndpoint`

**curl**

```bash
curl https://pay.perly.io/api/v1/webhook_endpoints/we_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const webhookEndpoint = await pay.webhookEndpoints.retrieve("we_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$webhookEndpoint = $perly->webhookEndpoints->retrieve('we_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Update a webhook endpoint

`POST /webhook_endpoints/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `url` | `string` |   |
| `enabled_events` | `"*" \| string[]` | Event types to send, or `["*"]` for every one. |
| `description` | `string \| null` |   |
| `disabled` | `boolean` | Stop sending without deleting it. |

**Returns:** `WebhookEndpoint`

**curl**

```bash
curl https://pay.perly.io/api/v1/webhook_endpoints/we_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "enabled_events": [
      "invoice.fulfilled",
      "invoice.expired",
      "refund.confirmed"
    ]
  }'
```

**Node**

```js
const webhookEndpoint = await pay.webhookEndpoints.update("we_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50", {
  enabled_events: ["invoice.fulfilled", "invoice.expired", "refund.confirmed"],
});
```

**PHP**

```php
$webhookEndpoint = $perly->webhookEndpoints->update('we_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50', [
    'enabled_events' => ['invoice.fulfilled', 'invoice.expired', 'refund.confirmed'],
]);
```

### Delete a webhook endpoint

`DELETE /webhook_endpoints/{id}`

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |

**Returns:** `Deleted`

**curl**

```bash
curl -X DELETE https://pay.perly.io/api/v1/webhook_endpoints/we_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50 \
  -H "Authorization: Bearer sk_test_…"
```

**Node**

```js
const deleted = await pay.webhookEndpoints.del("we_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$deleted = $perly->webhookEndpoints->delete('we_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Roll the signing secret

`POST /webhook_endpoints/{id}/roll_secret`

A new secret from now on; the old one stops at once. The response carries the new `secret`.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Returns:** `WebhookEndpoint`

**curl**

```bash
curl https://pay.perly.io/api/v1/webhook_endpoints/we_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50/roll_secret \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{}'
```

**Node**

```js
const webhookEndpoint = await pay.webhookEndpoints.rollSecret("we_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50");
```

**PHP**

```php
$webhookEndpoint = $perly->webhookEndpoints->rollSecret('we_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50');
```

### Claim a delivery

`POST /webhook_endpoints/{id}/claim`

Takes this endpoint's delivery of `event` once and answers the event. A second claim answers 409 `already_claimed`; an event never sent to this endpoint answers 404 `not_delivered`. For apps that cannot verify `Perly-Signature` themselves, and against replays.

**Parameters**

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `Idempotency-Key (header)` | `string` | Any unique string (a UUID). A retry with the same key returns the first response for 24 hours. |

**Body**

| Name | Type | Description |
| --- | --- | --- |
| `event` — required | `string` | The delivered event's `id`. |

**Returns:** `Event`

**curl**

```bash
curl https://pay.perly.io/api/v1/webhook_endpoints/we_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50/claim \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{"event":"evt_1042"}'
```

**Node**

```js
const event = await pay.webhookEndpoints.claim("we_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50", {
  event: "evt_1042",
});
```

**PHP**

```php
$event = $perly->webhookEndpoints->claim('we_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50', [
    'event' => 'evt_1042',
]);
```

## Objects

What the API answers with. Lists wrap them as `{ "object": "list", "data": […], "has_more", "next_cursor" }`; pass `next_cursor` back as `cursor`.

### Customer

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` | `cus_…` |
| `object` — required | `"customer"` |   |
| `livemode` — required | `boolean` |   |
| `email` — required | `string \| null` |   |
| `name` — required | `string \| null` |   |
| `external_id` — required | `string \| null` | Your own id for this buyer. |
| `country` — required | `string \| null` |   |
| `locale` — required | `string \| null` |   |
| `metadata` — required | `map` |   |
| `created` — required | `string` | ISO 8601 |

```json
{
  "id": "cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "object": "customer",
  "livemode": false,
  "email": "ada@example.com",
  "name": "Pro plan",
  "external_id": "user_42",
  "country": "PT",
  "locale": "en",
  "metadata": {
    "order_id": "1042"
  },
  "created": "2026-10-19T09:41:00Z"
}
```

### Product

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` | `prod_…` |
| `object` — required | `"product"` |   |
| `livemode` — required | `boolean` |   |
| `name` — required | `string` |   |
| `description` — required | `string \| null` |   |
| `image_url` — required | `string \| null` |   |
| `issues_license` — required | `boolean` |   |
| `license_activation_limit` — required | `integer \| null` |   |
| `active` — required | `boolean` |   |
| `metadata` — required | `map` |   |
| `created` — required | `string` | ISO 8601 |
| `updated` — required | `string` | ISO 8601 |

```json
{
  "id": "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "object": "product",
  "livemode": false,
  "name": "Pro plan",
  "description": "Everything in Pro, for a year.",
  "image_url": "https://shop.example/thanks",
  "issues_license": true,
  "license_activation_limit": 1,
  "active": true,
  "metadata": {
    "order_id": "1042"
  },
  "created": "2026-10-19T09:41:00Z",
  "updated": "2026-10-19T09:41:00Z"
}
```

### Price

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` | `price_…` |
| `object` — required | `"price"` |   |
| `livemode` — required | `boolean` |   |
| `product` — required | `string` | `prod_…` |
| `model` — required | `"one_time" \| "pay_what_you_want" \| "fixed_term" \| "subscription" \| "lifetime" \| "credit_pack"` |   |
| `currency` — required | `"USD" \| "EUR"` |   |
| `nickname` — required | `string \| null` |   |
| `active` — required | `boolean` |   |
| `unit_amount` — required | `integer \| null` | Null for pay-what-you-want and tiered lifetime prices. |
| `custom_amount` — required | `object \| null` |   |
| `term_days` — required | `integer \| null` |   |
| `recurring` — required | `object \| null` |   |
| `lifetime` — required | `object \| null` |   |
| `credits` — required | `integer \| null` |   |
| `refunds` — required | `object` |   |
| `metadata` — required | `map` |   |
| `created` — required | `string` | ISO 8601 |

```json
{
  "id": "price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "object": "price",
  "livemode": false,
  "product": "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "model": "one_time",
  "currency": "USD",
  "nickname": "Launch price",
  "active": true,
  "unit_amount": 4900,
  "custom_amount": {
    "minimum": 4900,
    "suggested": 4900
  },
  "term_days": 14,
  "recurring": {
    "interval": "day",
    "interval_days": 14,
    "trial_days": 14,
    "grace_days": 14,
    "prepay_max_periods": 1,
    "keep_renewal_price": true
  },
  "lifetime": {
    "quantity_cap": 1,
    "tiers": [
      {
        "id": "tier_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
        "position": 1,
        "name": "Pro plan",
        "seats": 1,
        "unit_amount": 4900
      }
    ]
  },
  "credits": 1,
  "refunds": {
    "allowed": true,
    "window_days": 14,
    "network_fee_payer": "buyer"
  },
  "metadata": {
    "order_id": "1042"
  },
  "created": "2026-10-19T09:41:00Z"
}
```

### Coupon

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` | `cpn_…` |
| `object` — required | `"coupon"` |   |
| `livemode` — required | `boolean` |   |
| `code` — required | `string` |   |
| `percent_off` — required | `integer \| null` |   |
| `amount_off` — required | `integer \| null` | Minor units (cents). |
| `currency` — required | `"USD" \| "EUR" \| null` |   |
| `duration` — required | `"once" \| "repeating" \| "forever"` |   |
| `duration_periods` — required | `integer \| null` |   |
| `max_redemptions` — required | `integer \| null` |   |
| `times_redeemed` — required | `integer` |   |
| `products` — required | `string[]` | Empty means every product. |
| `expires_at` — required | `string \| null` | ISO 8601 |
| `active` — required | `boolean` |   |
| `created` — required | `string` | ISO 8601 |

```json
{
  "id": "cpn_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "object": "coupon",
  "livemode": false,
  "code": "WELCOME10",
  "percent_off": 0,
  "amount_off": 0,
  "currency": "USD",
  "duration": "once",
  "duration_periods": 1,
  "max_redemptions": 1,
  "times_redeemed": 1,
  "products": [
    "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50"
  ],
  "expires_at": "2026-10-19T09:41:00Z",
  "active": true,
  "created": "2026-10-19T09:41:00Z"
}
```

### PaymentLink

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` | `plink_…` |
| `object` — required | `"payment_link"` |   |
| `livemode` — required | `boolean` |   |
| `url` — required | `string` |   |
| `slug` — required | `string` |   |
| `price` — required | `string` | `price_…` |
| `quantity` — required | `integer` |   |
| `adjustable_quantity` — required | `boolean` |   |
| `allow_coupons` — required | `boolean` |   |
| `collect_name` — required | `boolean` |   |
| `success_url` — required | `string \| null` |   |
| `active` — required | `boolean` |   |
| `donation` — required | `object \| null` | A donation page (on a pay_what_you_want price); null for an ordinary link. |
| `metadata` — required | `map` |   |
| `created` — required | `string` | ISO 8601 |

```json
{
  "id": "plink_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "object": "payment_link",
  "livemode": false,
  "url": "https://pay.perly.io/l/pro-plan",
  "slug": "pro-plan",
  "price": "price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "quantity": 1,
  "adjustable_quantity": true,
  "allow_coupons": true,
  "collect_name": true,
  "success_url": "https://shop.example/thanks",
  "active": true,
  "donation": {
    "amounts": [
      4900
    ],
    "goal": 4900,
    "ask_message": true,
    "latest_donors": 1,
    "thanks_note": null
  },
  "metadata": {
    "order_id": "1042"
  },
  "created": "2026-10-19T09:41:00Z"
}
```

### CheckoutSession

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` | `cs_…` |
| `object` — required | `"checkout_session"` |   |
| `livemode` — required | `boolean` |   |
| `url` — required | `string` | Send the buyer here, or open it with pay.js. |
| `status` — required | `"open" \| "complete" \| "expired"` |   |
| `currency` — required | `"USD" \| "EUR"` |   |
| `line_items` — required | `object[]` |   |
| `subtotal` — required | `integer` | Minor units (cents). |
| `discount` — required | `integer` | Minor units (cents). |
| `total` — required | `integer` | Minor units (cents). |
| `customer` — required | `string \| null` | `cus_…` |
| `customer_email` — required | `string \| null` |   |
| `coupon` — required | `string \| null` | `cpn_…` |
| `payment_link` — required | `string \| null` | `plink_…` |
| `return_url` — required | `string \| null` |   |
| `cancel_url` — required | `string \| null` |   |
| `invoice` — required | `string \| null` | `inv_…` |
| `expires_at` — required | `string` | ISO 8601 |
| `metadata` — required | `map` |   |
| `created` — required | `string` | ISO 8601 |

```json
{
  "id": "cs_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "object": "checkout_session",
  "livemode": false,
  "url": "https://pay.perly.io/c/cs_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "status": "open",
  "currency": "USD",
  "line_items": [
    {
      "id": "csl_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
      "price": "price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
      "quantity": 1,
      "custom_amount": 4900,
      "unit_amount": 4900,
      "amount": 4900
    }
  ],
  "subtotal": 4900,
  "discount": 0,
  "total": 4900,
  "customer": "cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "customer_email": "ada@example.com",
  "coupon": "cpn_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "payment_link": "plink_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "return_url": "https://shop.example/thanks",
  "cancel_url": "https://shop.example/cart",
  "invoice": "inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "expires_at": "2026-10-19T09:41:00Z",
  "metadata": {
    "order_id": "1042"
  },
  "created": "2026-10-19T09:41:00Z"
}
```

### Invoice

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` | `inv_…` |
| `object` — required | `"invoice"` |   |
| `livemode` — required | `boolean` |   |
| `url` — required | `string` | The buyer's payment page. |
| `status` — required | `string` |   |
| `kind` — required | `"checkout" \| "payment_link" \| "subscription" \| "manual" \| "api" \| "plan"` |   |
| `number` — required | `string \| null` |   |
| `customer` — required | `string \| null` | `cus_…` |
| `customer_email` — required | `string \| null` |   |
| `customer_name` — required | `string \| null` |   |
| `description` — required | `string \| null` |   |
| `currency` — required | `"USD" \| "EUR"` |   |
| `subtotal` — required | `integer` | Minor units (cents). |
| `discount` — required | `integer` | Minor units (cents). |
| `total` — required | `integer` | Minor units (cents). |
| `total_usd` — required | `integer` | What is settled, in US cents, locked when the invoice opened. |
| `received_usd` — required | `integer` | Minor units (cents). |
| `pending_usd` — required | `integer` | Minor units (cents). |
| `amount_received` — required | `string` | Integer string in the asset's smallest unit. |
| `payment` — required | `object \| null` | The chain and asset the buyer chose; null until then. |
| `lines` — required | `object[]` |   |
| `subscription` — required | `string \| null` | `sub_…` |
| `checkout_session` — required | `string \| null` | `cs_…` |
| `payment_link` — required | `string \| null` | `plink_…` |
| `coupon` — required | `string \| null` | `cpn_…` |
| `receipt_number` — required | `string \| null` |   |
| `review_reason` — required | `string \| null` |   |
| `due_at` — required | `string \| null` | ISO 8601 |
| `paid_at` — required | `string \| null` | ISO 8601 |
| `fulfilled_at` — required | `string \| null` | ISO 8601 |
| `canceled_at` — required | `string \| null` | ISO 8601 |
| `metadata` — required | `map` |   |
| `created` — required | `string` | ISO 8601 |

```json
{
  "id": "inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "object": "invoice",
  "livemode": false,
  "url": "https://pay.perly.io/i/0b6f2c1e-8d4a-4f3e-9a7b-5c2d1e0f8a9b",
  "status": "open",
  "kind": "checkout",
  "number": "KS-2026-000142",
  "customer": "cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "customer_email": "ada@example.com",
  "customer_name": null,
  "description": "Everything in Pro, for a year.",
  "currency": "USD",
  "subtotal": 4900,
  "discount": 0,
  "total": 4900,
  "total_usd": 4900,
  "received_usd": 4900,
  "pending_usd": 4900,
  "amount_received": "49000000",
  "payment": {
    "chain": "base",
    "asset": "USDC",
    "address": "0x7a3f…1e0b",
    "amount_due": "49000000",
    "decimals": 6,
    "btc_usd_cents": 6800000,
    "opened_at": "2026-10-19T09:41:00Z",
    "expires_at": "2026-10-19T09:41:00Z"
  },
  "lines": [
    {
      "id": "il_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
      "price": "price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
      "product": "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
      "description": "Everything in Pro, for a year.",
      "quantity": 1,
      "unit_amount": 4900,
      "amount": 4900,
      "period_start": "2026-10-19T09:41:00Z",
      "period_end": "2026-10-19T09:41:00Z"
    }
  ],
  "subscription": "sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "checkout_session": "cs_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "payment_link": "plink_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "coupon": "cpn_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "receipt_number": null,
  "review_reason": null,
  "due_at": "2026-10-19T09:41:00Z",
  "paid_at": "2026-10-19T09:41:00Z",
  "fulfilled_at": "2026-10-19T09:41:00Z",
  "canceled_at": "2026-10-19T09:41:00Z",
  "metadata": {
    "order_id": "1042"
  },
  "created": "2026-10-19T09:41:00Z"
}
```

### Subscription

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` | `sub_…` |
| `object` — required | `"subscription"` |   |
| `livemode` — required | `boolean` |   |
| `status` — required | `string` |   |
| `customer` — required | `string` | `cus_…` |
| `price` — required | `string` | `price_…` |
| `quantity` — required | `integer` |   |
| `current_period_start` — required | `string` | ISO 8601 |
| `current_period_end` — required | `string` | ISO 8601 |
| `trial_end` — required | `string \| null` | ISO 8601 |
| `grace_days` — required | `integer` |   |
| `cancel_at_period_end` — required | `boolean` |   |
| `canceled_at` — required | `string \| null` | ISO 8601 |
| `ended_at` — required | `string \| null` | ISO 8601 |
| `paused_at` — required | `string \| null` | ISO 8601 |
| `pending_price` — required | `string \| null` | A downgrade waiting for the period end. |
| `kept_price` — required | `integer \| null` | The renewal price this subscriber keeps. |
| `latest_invoice` — required | `string \| null` | `inv_…` |
| `coupon` — required | `string \| null` | `cpn_…` |
| `metadata` — required | `map` |   |
| `created` — required | `string` | ISO 8601 |

```json
{
  "id": "sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "object": "subscription",
  "livemode": false,
  "status": "trialing",
  "customer": "cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "price": "price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "quantity": 1,
  "current_period_start": "2026-10-19T09:41:00Z",
  "current_period_end": "2026-10-19T09:41:00Z",
  "trial_end": "2026-10-19T09:41:00Z",
  "grace_days": 14,
  "cancel_at_period_end": true,
  "canceled_at": "2026-10-19T09:41:00Z",
  "ended_at": "2026-10-19T09:41:00Z",
  "paused_at": "2026-10-19T09:41:00Z",
  "pending_price": "price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "kept_price": 4900,
  "latest_invoice": "inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "coupon": "cpn_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "metadata": {
    "order_id": "1042"
  },
  "created": "2026-10-19T09:41:00Z"
}
```

### Entitlement

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` | `ent_…` |
| `object` — required | `"entitlement"` |   |
| `livemode` — required | `boolean` |   |
| `active` — required | `boolean` | Started, not ended, not revoked. |
| `customer` — required | `string \| null` | `cus_…` |
| `product` — required | `string \| null` | `prod_…` |
| `price` — required | `string \| null` | `price_…` |
| `model` — required | `"one_time" \| "pay_what_you_want" \| "fixed_term" \| "subscription" \| "lifetime" \| "credit_pack"` |   |
| `subscription` — required | `string \| null` | `sub_…` |
| `invoice` — required | `string` | `inv_…` |
| `starts_at` — required | `string` | ISO 8601 |
| `ends_at` — required | `string \| null` | Null = for ever. |
| `credits_total` — required | `integer \| null` |   |
| `credits_used` — required | `integer` |   |
| `credits_remaining` — required | `integer \| null` |   |
| `tier` — required | `string \| null` | `tier_…` |
| `seat_number` — required | `integer \| null` |   |
| `revoked_at` — required | `string \| null` | ISO 8601 |
| `created` — required | `string` | ISO 8601 |

```json
{
  "id": "ent_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "object": "entitlement",
  "livemode": false,
  "active": true,
  "customer": "cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "product": "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "price": "price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "model": "one_time",
  "subscription": "sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "invoice": "inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "starts_at": "2026-10-19T09:41:00Z",
  "ends_at": "2026-10-19T09:41:00Z",
  "credits_total": 4900,
  "credits_used": 1,
  "credits_remaining": 1,
  "tier": "tier_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "seat_number": 1,
  "revoked_at": "2026-10-19T09:41:00Z",
  "created": "2026-10-19T09:41:00Z"
}
```

### EntitlementCheck

| Name | Type | Description |
| --- | --- | --- |
| `object` — required | `"entitlement_check"` |   |
| `has_access` — required | `boolean` |   |
| `customer` — required | `string \| null` | `cus_…` |
| `product` — required | `string \| null` | `prod_…` |
| `ends_at` — required | `string \| null` | The latest end among active entitlements; null = for ever (or none). |
| `credits_remaining` — required | `integer \| null` |   |
| `entitlements` — required | `Entitlement[]` |   |

```json
{
  "object": "entitlement_check",
  "has_access": true,
  "customer": "cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "product": "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "ends_at": "2026-10-19T09:41:00Z",
  "credits_remaining": 1,
  "entitlements": [
    {
      "id": "ent_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
      "object": "entitlement",
      "livemode": false,
      "active": true,
      "customer": "cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
      "product": "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
      "price": "price_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
      "model": "one_time",
      "subscription": "sub_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
      "invoice": "inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
      "starts_at": "2026-10-19T09:41:00Z",
      "ends_at": "2026-10-19T09:41:00Z",
      "credits_total": 4900,
      "credits_used": 1,
      "credits_remaining": 1,
      "tier": "tier_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
      "seat_number": 1,
      "revoked_at": "2026-10-19T09:41:00Z",
      "created": "2026-10-19T09:41:00Z"
    }
  ]
}
```

### CreditBalance

| Name | Type | Description |
| --- | --- | --- |
| `object` — required | `"credit_balance"` |   |
| `livemode` — required | `boolean` |   |
| `customer` — required | `string` | `cus_…` |
| `product` — required | `string \| null` | Null = every product's credits together. |
| `balance` — required | `integer` | Credits left on active packs. |
| `low_balance_threshold` — required | `integer \| null` | The product's threshold; null = none set. |
| `low` — required | `boolean` | At or under the threshold (or zero). |
| `top_up_url` — required | `string` | The buyer's own top-up page: stable, safe to email or show in your app. |

```json
{
  "object": "credit_balance",
  "livemode": false,
  "customer": "cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "product": "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "balance": 1,
  "low_balance_threshold": 1,
  "low": true,
  "top_up_url": "https://shop.example/thanks"
}
```

### CreditUsage

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` | `cu_…` |
| `object` — required | `"credit_usage"` |   |
| `livemode` — required | `boolean` |   |
| `customer` — required | `string \| null` | `cus_…` |
| `product` — required | `string \| null` | `prod_…` |
| `entitlement` — required | `string \| null` | Set when one pack was named. |
| `credits` — required | `integer` |   |
| `action` — required | `string \| null` | Your label for what was done (`chat`, `image.hd`, …). |
| `balance` — required | `integer` | What was left right after. |
| `created` — required | `string` | ISO 8601 |

```json
{
  "id": "cu_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "object": "credit_usage",
  "livemode": false,
  "customer": "cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "product": "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "entitlement": "ent_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "credits": 1,
  "action": null,
  "balance": 1,
  "created": "2026-10-19T09:41:00Z"
}
```

### LicenseKey

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` | `lic_…` |
| `object` — required | `"license_key"` |   |
| `livemode` — required | `boolean` |   |
| `key` — required | `string` |   |
| `status` — required | `"active" \| "suspended" \| "revoked" \| "expired"` |   |
| `product` — required | `string \| null` | `prod_…` |
| `customer` — required | `string \| null` | `cus_…` |
| `entitlement` — required | `string` | `ent_…` |
| `activation_limit` — required | `integer \| null` |   |
| `activations` — required | `integer` |   |
| `expires_at` — required | `string \| null` | ISO 8601 |
| `created` — required | `string` | ISO 8601 |

```json
{
  "id": "lic_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "object": "license_key",
  "livemode": false,
  "key": "PERLY-8KQ2-X7LM-4N9P",
  "status": "active",
  "product": "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "customer": "cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "entitlement": "ent_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "activation_limit": 1,
  "activations": 1,
  "expires_at": "2026-10-19T09:41:00Z",
  "created": "2026-10-19T09:41:00Z"
}
```

### LicenseCheck

| Name | Type | Description |
| --- | --- | --- |
| `object` — required | `"license_check"` |   |
| `valid` — required | `boolean` |   |
| `reason` — required | `string \| null` |   |
| `license_key` — required | `object \| null` |   |
| `activation` — required | `object \| null` |   |

```json
{
  "object": "license_check",
  "valid": true,
  "reason": "not_found",
  "license_key": {
    "key": "PERLY-8KQ2-X7LM-4N9P",
    "livemode": false,
    "status": "active",
    "product": "prod_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
    "activation_limit": 1,
    "activations": 1,
    "expires_at": "2026-10-19T09:41:00Z"
  },
  "activation": {
    "id": "act_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
    "instance_name": "ada-laptop",
    "active": true,
    "created": "2026-10-19T09:41:00Z"
  }
}
```

### PortalSession

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` | `bps_…` |
| `object` — required | `"portal_session"` |   |
| `livemode` — required | `boolean` |   |
| `customer` — required | `string` | `cus_…` |
| `url` — required | `string` | Shown once. Valid until expires_at. |
| `return_url` — required | `string \| null` |   |
| `expires_at` — required | `string` | ISO 8601 |
| `created` — required | `string` | ISO 8601 |

```json
{
  "id": "bps_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "object": "portal_session",
  "livemode": false,
  "customer": "cus_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "url": "https://pay.perly.io/portal/session",
  "return_url": "https://shop.example/thanks",
  "expires_at": "2026-10-19T09:41:00Z",
  "created": "2026-10-19T09:41:00Z"
}
```

### Payment

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` | `pay_…` |
| `object` — required | `"payment"` |   |
| `livemode` — required | `boolean` |   |
| `invoice` — required | `string \| null` | `inv_…` |
| `chain` — required | `string` |   |
| `asset` — required | `"BTC" \| "USDC" \| "USDT"` | `BTC`, `USDC` or `USDT`. On `arbitrum` and `optimism`, `USDT` is USDT0 (LayerZero's omnichain USDT); show it as USDT0 there. |
| `token` — required | `string \| null` |   |
| `txid` — required | `string` |   |
| `position` — required | `integer` |   |
| `amount` — required | `string` | Integer string in the asset's smallest unit. |
| `decimals` — required | `integer` |   |
| `usd_cents` — required | `integer \| null` |   |
| `from_address` — required | `string \| null` |   |
| `to_address` — required | `string` |   |
| `block_number` — required | `integer \| null` |   |
| `confirmations` — required | `integer` |   |
| `arrived_at` — required | `string` | ISO 8601 |
| `confirmed_at` — required | `string \| null` | ISO 8601 |
| `dropped_at` — required | `string \| null` | ISO 8601 |
| `created` — required | `string` | ISO 8601 |

```json
{
  "id": "pay_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "object": "payment",
  "livemode": false,
  "invoice": "inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "chain": "base",
  "asset": "USDC",
  "token": null,
  "txid": "0x9f1c…e5b7",
  "position": 1,
  "amount": "49000000",
  "decimals": 6,
  "usd_cents": 4900,
  "from_address": null,
  "to_address": "…",
  "block_number": 1,
  "confirmations": 3,
  "arrived_at": "2026-10-19T09:41:00Z",
  "confirmed_at": "2026-10-19T09:41:00Z",
  "dropped_at": "2026-10-19T09:41:00Z",
  "created": "2026-10-19T09:41:00Z"
}
```

### Refund

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` | `re_…` |
| `object` — required | `"refund"` |   |
| `livemode` — required | `boolean` |   |
| `invoice` — required | `string` | `inv_…` |
| `payment` — required | `string \| null` | `pay_…` |
| `status` — required | `"requested" \| "awaiting_address" \| "ready_to_send" \| "sent" \| "confirmed" \| "canceled"` |   |
| `chain` — required | `string` |   |
| `asset` — required | `"BTC" \| "USDC" \| "USDT"` | `BTC`, `USDC` or `USDT`. On `arbitrum` and `optimism`, `USDT` is USDT0 (LayerZero's omnichain USDT); show it as USDT0 there. |
| `decimals` — required | `integer` |   |
| `amount` — required | `string` | Integer string in the asset's smallest unit. |
| `network_fee` — required | `string \| null` | Integer string in the asset's smallest unit. |
| `network_fee_payer` — required | `"buyer" \| "merchant"` |   |
| `amount_to_send` — required | `string \| null` | Integer string in the asset's smallest unit. |
| `reason` — required | `string \| null` |   |
| `refund_address` — required | `string \| null` |   |
| `txid` — required | `string \| null` | The transaction you named with mark_sent. Only it confirms the refund. |
| `sent_at` — required | `string \| null` | ISO 8601 |
| `confirmed_at` — required | `string \| null` | ISO 8601 |
| `canceled_at` — required | `string \| null` | ISO 8601 |
| `created` — required | `string` | ISO 8601 |

```json
{
  "id": "re_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "object": "refund",
  "livemode": false,
  "invoice": "inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "payment": "pay_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "status": "requested",
  "chain": "base",
  "asset": "USDC",
  "decimals": 6,
  "amount": "49000000",
  "network_fee": "49000000",
  "network_fee_payer": "buyer",
  "amount_to_send": "49000000",
  "reason": "requested_by_customer",
  "refund_address": "0x4b1e…9c2d",
  "txid": "0x9f1c…e5b7",
  "sent_at": "2026-10-19T09:41:00Z",
  "confirmed_at": "2026-10-19T09:41:00Z",
  "canceled_at": "2026-10-19T09:41:00Z",
  "created": "2026-10-19T09:41:00Z"
}
```

### RefundQuote

| Name | Type | Description |
| --- | --- | --- |
| `object` — required | `"refund_quote"` |   |
| `invoice` — required | `string` | `inv_…` |
| `refundable` — required | `boolean` |   |
| `reason` — required | `string \| null` |   |
| `chain` — required | `string \| null` |   |
| `asset` — required | `"BTC" \| "USDC" \| "USDT" \| null` | `BTC`, `USDC` or `USDT`. On `arbitrum` and `optimism`, `USDT` is USDT0 (LayerZero's omnichain USDT); show it as USDT0 there. |
| `decimals` — required | `integer \| null` |   |
| `amount` — required | `string \| null` | What can still be refunded. |
| `network_fee` — required | `string \| null` | Integer string in the asset's smallest unit. |
| `network_fee_payer` — required | `"buyer" \| "merchant" \| null` |   |
| `amount_to_send` — required | `string \| null` | Integer string in the asset's smallest unit. |

```json
{
  "object": "refund_quote",
  "invoice": "inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "refundable": true,
  "reason": "requested_by_customer",
  "chain": "base",
  "asset": "USDC",
  "decimals": 6,
  "amount": "49000000",
  "network_fee": "49000000",
  "network_fee_payer": "buyer",
  "amount_to_send": "49000000"
}
```

### Receipt

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` | `rcpt_…` |
| `object` — required | `"receipt"` |   |
| `livemode` — required | `boolean` |   |
| `kind` — required | `"payment" \| "refund"` |   |
| `number` — required | `string` |   |
| `invoice` — required | `string` | `inv_…` |
| `refund` — required | `string \| null` | `re_…` |
| `url` — required | `string` | The public receipt page. |
| `pdf` — required | `string` | This API's PDF of it. |
| `customer_email` — required | `string \| null` |   |
| `currency` — required | `"USD" \| "EUR"` |   |
| `amount` — required | `integer` | Minor units (cents). |
| `asset` — required | `"BTC" \| "USDC" \| "USDT" \| null` | `BTC`, `USDC` or `USDT`. On `arbitrum` and `optimism`, `USDT` is USDT0 (LayerZero's omnichain USDT); show it as USDT0 there. |
| `asset_amount` — required | `string \| null` | Integer string in the asset's smallest unit. |
| `decimals` — required | `integer \| null` |   |
| `issued_at` — required | `string` | ISO 8601 |
| `emailed_at` — required | `string \| null` | ISO 8601 |

```json
{
  "id": "rcpt_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "object": "receipt",
  "livemode": false,
  "kind": "payment",
  "number": "KS-2026-000142",
  "invoice": "inv_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "refund": "re_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "url": "https://pay.perly.io/r/KS-2026-000142",
  "pdf": "…",
  "customer_email": "ada@example.com",
  "currency": "USD",
  "amount": 4900,
  "asset": "USDC",
  "asset_amount": "49000000",
  "decimals": 6,
  "issued_at": "2026-10-19T09:41:00Z",
  "emailed_at": "2026-10-19T09:41:00Z"
}
```

### Event

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` | `evt_…` |
| `object` — required | `"event"` |   |
| `livemode` — required | `boolean` |   |
| `type` — required | `string` | `<object>.<verb>`, e.g. invoice.paid. |
| `object_type` — required | `string` |   |
| `object_id` — required | `string \| null` |   |
| `data` — required | `map` | `object`: the object the event is about, as the API shows it now; plus what the event recorded. |
| `created` — required | `string` | ISO 8601 |

```json
{
  "id": "evt_1042",
  "object": "event",
  "livemode": false,
  "type": "invoice.fulfilled",
  "object_type": "invoice",
  "object_id": null,
  "data": {},
  "created": "2026-10-19T09:41:00Z"
}
```

### WebhookEndpoint

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` | `we_…` |
| `object` — required | `"webhook_endpoint"` |   |
| `livemode` — required | `boolean` |   |
| `url` — required | `string` |   |
| `description` — required | `string \| null` |   |
| `enabled_events` — required | `string[]` | `*` is every event. |
| `status` — required | `"enabled" \| "disabled"` |   |
| `secret_prefix` — required | `string` |   |
| `secret` | `string` | The signing secret, `whsec_…`. Only when created or rolled. |
| `created` — required | `string` | ISO 8601 |

```json
{
  "id": "we_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "object": "webhook_endpoint",
  "livemode": false,
  "url": "https://shop.example/webhooks/perly",
  "description": "Everything in Pro, for a year.",
  "enabled_events": [
    "…"
  ],
  "status": "enabled",
  "secret_prefix": "…",
  "secret": "whsec_3f2a9c1e8b7d4a6f9e0c5b1a2d3e4f50",
  "created": "2026-10-19T09:41:00Z"
}
```

### Deleted

| Name | Type | Description |
| --- | --- | --- |
| `id` — required | `string` |   |
| `object` — required | `string` |   |
| `deleted` — required | `true` |   |

```json
{
  "id": "…",
  "object": "…",
  "deleted": true
}
```
