# Bre-B QR codes

> Generate dynamic Bre-B QR codes (one fixed-amount payment) or static ones (the payer types the amount) tied to your keys.

[Sandbox · coming soon]

A Bre-B QR code is scanned with any banking app and pays one of your [Bre-B keys](https://developers.zulu.com.co/en/docs/pay-in/bre-b.md). zulu gives you the EMVCo content to draw your own QR and a PNG ready to show.

## Dynamic or static

| Type      | How it is created | Payments                                               | Best for                                     |
| --------- | ----------------- | ------------------------------------------------------ | -------------------------------------------- |
| `DYNAMIC` | With `amount`     | One, of that amount; then it is `PAID`                 | An order, a bill, a checkout payment         |
| `STATIC`  | Without `amount`  | Many; the payer types the amount and it stays `ACTIVE` | A QR printed at the counter, tips, donations |

## Create a QR code

**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)

**POST /v1/bre-b/qr-codes**

```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"
}'
```

```javascript
const response = await fetch('https://sandbox.zulu.com.co/v1/bre-b/qr-codes', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.ZULU_ACCESS_TOKEN}`,
    'X-API-Key': process.env.ZULU_API_KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "key": "@acmepagos",
    "amount": 85000,
    "reference": "PED-1093"
  }),
});

console.log(response.status, await response.json());
```

```python
import os

import requests

response = requests.post(
    "https://sandbox.zulu.com.co/v1/bre-b/qr-codes",
    headers={
        "Authorization": f"Bearer {os.environ['ZULU_ACCESS_TOKEN']}",
        "X-API-Key": os.environ["ZULU_API_KEY"],
    },
    json={
        "key": "@acmepagos",
        "amount": 85000,
        "reference": "PED-1093",
    },
    timeout=30,
)
print(response.status_code, response.json())
```

- **`key`** is the key that receives. Without it, the oldest of your active keys is used.
- **`amount`** (whole pesos, up to 12,110,000) makes it dynamic.
- **`reference`** (up to 25 characters) travels in the QR and in the deposit: use it to know which order was paid.
- **`expiresInMinutes`** (1 to 10,080) sets the expiry. A dynamic QR expires after 60 minutes by default; a static one without this field never expires.

The response carries `payload` (the EMVCo content, to render your own image with any QR library) and `imageUrl` (a PNG). In the sandbox the QR uses a non-routable identifier (`CO.ZULU.SANDBOX`): no banking app can pay it.

## Statuses

| Status    | What it means             |
| --------- | ------------------------- |
| `ACTIVE`  | Takes payments.           |
| `PAID`    | Dynamic and already paid. |
| `EXPIRED` | Expired.                  |

**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)

Every payment creates a deposit with `method: BRE_B_QR` and the QR's `reference` (or its id when you sent none), and sends the `DEPOSITS` webhook.

## Simulate the payment

**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)

A dynamic QR is paid without `amount`; a static one needs the `amount` the payer "typed".

**POST /v1/sandbox/bre-b/qr-codes/\{id}/pay**

```bash
curl https://sandbox.zulu.com.co/v1/sandbox/bre-b/qr-codes/3f6c2a9e-8d41-4b7a-9c1e-2f5d7a8b9c0d/pay \
  -H "Authorization: Bearer $ZULU_ACCESS_TOKEN" \
  -H "X-API-Key: $ZULU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "payer": {
    "fullName": "Marta Ruiz",
    "documentType": "CC",
    "documentNumber": "52123456",
    "bankName": "Banco Davivienda"
  }
}'
```

```javascript
const response = await fetch('https://sandbox.zulu.com.co/v1/sandbox/bre-b/qr-codes/3f6c2a9e-8d41-4b7a-9c1e-2f5d7a8b9c0d/pay', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.ZULU_ACCESS_TOKEN}`,
    'X-API-Key': process.env.ZULU_API_KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "payer": {
      "fullName": "Marta Ruiz",
      "documentType": "CC",
      "documentNumber": "52123456",
      "bankName": "Banco Davivienda"
    }
  }),
});

console.log(response.status, await response.json());
```

```python
import os

import requests

response = requests.post(
    "https://sandbox.zulu.com.co/v1/sandbox/bre-b/qr-codes/3f6c2a9e-8d41-4b7a-9c1e-2f5d7a8b9c0d/pay",
    headers={
        "Authorization": f"Bearer {os.environ['ZULU_ACCESS_TOKEN']}",
        "X-API-Key": os.environ["ZULU_API_KEY"],
    },
    json={
        "payer": {
            "fullName": "Marta Ruiz",
            "documentType": "CC",
            "documentNumber": "52123456",
            "bankName": "Banco Davivienda",
        },
    },
    timeout=30,
)
print(response.status_code, response.json())
```

## Errors

| HTTP | error | cause | Description |
| --- | --- | --- | --- |
| 404 | `NotFoundApiError` | `bre-b key "%s" not found` | The key does not exist (in your workspace, or in the Bre-B directory when resolving it). Test data: `@notfound`. |
| 404 | `NotFoundApiError` | `qr code "%s" not found` | No QR code with that id exists in your workspace. |
| 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`). |
| 422 | `UnprocessableEntityApiError` | `bre-b key "%s" is blocked` | The key is blocked and does not receive payments. |
| 422 | `UnprocessableEntityApiError` | `amount %d is above the bre-b maximum of %d` | Bre-B accepts up to 12,110,000 COP per transfer. |
| 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 STATIC: amount is required` | A static QR has no amount: the simulator needs the payment's `amount`. |
| 422 | `UnprocessableEntityApiError` | `qr code "%s" is DYNAMIC: its amount can not be changed` | A dynamic QR already fixes the amount: omit `amount`. |
