# Counter payments with a dynamic QR

> Show one QR code per order at your till or in your app, and confirm the payment in seconds with no card terminal and no manual reconciliation.

[Sandbox · coming soon]

A merchant wants to collect at the till (or in its app) with a QR code the customer scans from their banking app, and confirm the payment instantly.

## The flow

1. When the order closes, you create a dynamic QR with the amount and the order number.
2. You show `imageUrl` (or draw `payload`) on the till's screen.
3. The customer scans and pays over Bre-B.
4. The `DEPOSITS` webhook carries the deposit with the order's `reference`; the till shows "Paid".

## 1. One QR code per order

**POST** `/v1/bre-b/qr-codes` — Create a Bre-B QR code · [Sandbox · coming soon] · [See the reference](https://developers.zulu.com.co/en/reference/create-qr-code.md)

```bash
curl https://sandbox.zulu.com.co/v1/bre-b/qr-codes \
  -H "Authorization: Bearer $ZULU_ACCESS_TOKEN" \
  -H "X-API-Key: $ZULU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"key": "@acmepagos", "amount": 85000, "reference": "PED-1093", "expiresInMinutes": 15}'
```

A dynamic QR accepts a single payment of the exact amount: no partial payments and no overpayments. Fit `expiresInMinutes` to how long a customer takes at your till.

## 2. Show the QR code

- **Fast:** show `imageUrl`, a ready PNG.
- **Your way:** render the image from `payload` (EMVCo content) with your QR library, in your colors and with your logo.

## 3. Confirm the payment

Listen to the `DEPOSITS` webhook and match `reference` against the order. If your till can not receive webhooks, poll the QR every few seconds while it is on screen:

**GET** `/v1/bre-b/qr-codes/{id}` — Get a QR code · [Sandbox · coming soon] · [See the reference](https://developers.zulu.com.co/en/reference/get-qr-code.md)

```js title="wait-for-payment.js"
export async function waitForPayment(qrId, { timeoutMs = 15 * 60_000 } = {}) {
  const deadline = Date.now() + timeoutMs;

  while (Date.now() < deadline) {
    const qr = await zulu.get(`/v1/bre-b/qr-codes/${qrId}`);
    if (qr.status === 'PAID') return 'PAID';
    if (qr.status === 'EXPIRED') return 'EXPIRED';
    await new Promise((resolve) => setTimeout(resolve, 2000));
  }

  return 'TIMEOUT';
}
```

## 4. A static QR for everything else

For tips or amounts the customer decides, print a static QR (no `amount`): it takes many payments and each arrives as a deposit with its amount.

## 5. Test it

**POST** `/v1/sandbox/bre-b/qr-codes/{id}/pay` — Simulate a QR code payment · [Sandbox only] · [See the reference](https://developers.zulu.com.co/en/reference/simulate-qr-code-payment.md)

Pay the QR with the simulator and check your till turns to "Paid". To test expiry, create one with `expiresInMinutes: 1` and wait.

| HTTP | error | cause | Description |
| --- | --- | --- | --- |
| 422 | `UnprocessableEntityApiError` | `qr code "%s" is %s` | The QR code no longer takes payments: it expired, or it is dynamic and was already paid. |
| 422 | `UnprocessableEntityApiError` | `qr code "%s" is DYNAMIC: its amount can not be changed` | A dynamic QR already fixes the amount: omit `amount`. |
| 422 | `UnprocessableEntityApiError` | `the workspace does not have an active bre-b key` | To create a QR without `key`, the workspace needs at least one active key (`POST /v1/bre-b/keys`). |
