# QRBayad API reference

Base URL: `https://qrbayad.com`

## Authentication
Send your secret key on every request:

```
Authorization: Bearer sk_live_...
```

Create or roll keys at https://qrbayad.com/dashboard/developers. Keys are shown once. Keep them server-side only.

## Amounts
All amounts are integers in **centavos** (₱500.00 = `50000`). Currency is always `PHP`.

## Checkouts (payment links)

### Create a checkout
`POST /api/v1/checkouts`

| Field | Type | Required | Notes |
|---|---|---|---|
| amount | integer | yes | centavos, min 100 (₱1) |
| description | string | no | shown to the customer, max 200 |
| reference_id | string | no | your order id, echoed back |
| expires_in_minutes | integer | no | default 30, min 5, max 10080 (7 days) |

```bash
curl https://qrbayad.com/api/v1/checkouts \
  -H "Authorization: Bearer $QRBAYAD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"amount": 50000, "description": "Order #1001", "reference_id": "1001"}'
```

Response `201`:

```json
{
  "id": "6b2772d6-a8eb-4ef4-824a-519cdfffa587",
  "object": "checkout",
  "code": "85SEXH",
  "amount": 50000,
  "amount_due": 50000,
  "currency": "PHP",
  "description": "Order #1001",
  "reference_id": "1001",
  "status": "pending",
  "qr_payload": "000201010212...",
  "checkout_url": "https://qrbayad.com/c/6b2772d6-a8eb-4ef4-824a-519cdfffa587",
  "expires_at": "2026-10-17T13:40:29.145Z",
  "paid_at": null,
  "created_at": "2026-10-17T13:10:29.146Z"
}
```

Send the customer to `checkout_url` (hosted page with the QR and live status), or render `qr_payload` as a QR code yourself. `status` is `pending`, `paid` or `expired`. A late payment on an expired checkout still marks it `paid`.

`amount` is what you asked for. `amount_due` is what the QR charges and what the payment will be: the same as `amount`, except when another open checkout already charges that amount. Then it is ₱0.01 higher for each one (₱150.00, ₱150.01, ₱150.02...). Bank-to-bank transfers inside MariBank don't carry the checkout code, so this keeps every open checkout's amount unique and their payments matched. When reconciling, compare a payment to the checkout's `amount_due`, not to your order total.

### Retrieve a checkout
`GET /api/v1/checkouts/{id}`

### List checkouts
`GET /api/v1/checkouts?status=pending|paid|expired&limit=20` → `{ "object": "list", "data": [checkout, ...] }` (newest first, limit 1–100)

## Payments

### List payments
`GET /api/v1/payments?limit=20` → `{ "object": "list", "data": [payment, ...] }`

```json
{
  "id": "112546d3-...",
  "object": "payment",
  "amount": 100,
  "currency": "PHP",
  "status": "succeeded",
  "checkout_id": "1b071330-...",
  "match_method": "code",
  "sender_bank": "G-Xchange / GCash",
  "sender_last4": "4711",
  "bank_reference": "518377",
  "paid_at": "2026-10-17T12:56:00.000Z",
  "created_at": "2026-10-17T12:56:18.000Z"
}
```

`status: "unmatched"` means money arrived in the bank account without a matching checkout (for example a customer scanned the plain bank QR).

## Webhooks
Set your endpoint at https://qrbayad.com/dashboard/developers. When a checkout is paid we send:

```
POST <your url>
Content-Type: application/json
QRBayad-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256>

{
  "type": "checkout.paid",
  "created": 1792242738,
  "data": {
    "checkout": {
      "id": "6b2772d6-a8eb-4ef4-824a-519cdfffa587",
      "object": "checkout",
      "code": "85SEXH",
      "amount": 50000,
      "amount_due": 50000,
      "currency": "PHP",
      "description": "Order #1001",
      "reference_id": "1001",
      "status": "paid",
      "qr_payload": "000201010212...",
      "checkout_url": "https://qrbayad.com/c/6b2772d6-a8eb-4ef4-824a-519cdfffa587",
      "expires_at": "2026-10-17T13:40:29.145Z",
      "paid_at": "2026-10-17T13:12:00.000Z",
      "created_at": "2026-10-17T13:10:29.146Z"
    },
    "payment": {
      "id": "112546d3-...",
      "object": "payment",
      "amount": 50000,
      "currency": "PHP",
      "status": "succeeded",
      "checkout_id": "6b2772d6-a8eb-4ef4-824a-519cdfffa587",
      "match_method": "code",
      "sender_bank": "G-Xchange / GCash",
      "sender_last4": "4711",
      "bank_reference": "518377",
      "paid_at": "2026-10-17T13:12:00.000Z",
      "created_at": "2026-10-17T13:12:18.000Z"
    }
  }
}
```

`data.checkout` and `data.payment` are the same checkout and payment objects the API returns. Find your order with `data.checkout.reference_id`. `data.payment.amount` equals `data.checkout.amount_due`.

Verify: `v1 == HMAC_SHA256(signing_secret, t + "." + raw_body)`, and reject if `t` is older than 5 minutes.

```js
import crypto from 'node:crypto';

export function verifyQRBayad(rawBody, header, secret) {
  const parts = Object.fromEntries(header.split(',').map((p) => p.split('=')));
  const expected = crypto.createHmac('sha256', secret).update(`${parts.t}.${rawBody}`).digest('hex');
  const fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) < 300;
  return fresh && crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1 ?? ''));
}
```

Respond 2xx quickly. Treat the webhook as a hint and you may re-fetch the checkout with `GET /api/v1/checkouts/{id}` to confirm.

## Errors
JSON `{"error": "message"}` with status `400` (invalid body), `401` (bad key) or `404` (not found).

## MCP server
`https://qrbayad.com/mcp`: Streamable HTTP, same `Authorization: Bearer sk_live_...` header. Tools: `create_payment_link` (amount in pesos), `get_payment_link`, `list_payment_links`, `list_payments`, `get_account`. Setup per agent: https://qrbayad.com/agent-setup.md
