{
  "openapi": "3.0.3",
  "info": {
    "title": "Loyalty API",
    "version": "1.4.0",
    "description": "Multi-business REST API v1: each key belongs to a single business and only sees that business's data (an ID from another business returns 404).\n\n- **Authentication:** `Authorization: Bearer <key>`. Create the key in Dashboard → Developers with the scopes you need; the plan must include the API feature.\n- **Amounts** in minor units (cents): L 125.50 = `12550`. Stamp, point, visit and use balances are integers.\n- **Idempotency:** send `Idempotency-Key` on POST/PATCH/DELETE. Repeating the request returns the original response (`Idempotent-Replayed: true`); the same key with a different body → 409. Keys are kept for 24 h.\n- **Immutable ledger:** every balance change is a transaction with a unique reference; corrections are audited adjustments or reversals. The server always calculates stamps, points, discounts and balances.\n- **Responses:** `{\"data\": …}`; lists add `meta` (`current_page`, `per_page`, `total`, `last_page`; `per_page` max. 100).\n- **Errors:** business rules `{\"error\": {\"code\", \"message\"}}` (402, 403, 409, 422); validation `{\"message\", \"errors\": {field: [messages]}}` (422); missing resource or one from another business `{\"message\"}` (404).\n- **Rate limit:** 120 requests per minute per key (429).\n- **Dates:** `from`, `to`, `expires_at` and coupon dates (`starts_at`, `ends_at`) are sent as the business's local dates (`YYYY-MM-DD`); responses use ISO 8601 UTC.\n- **MCP (AI assistants):** `POST /api/mcp` (JSON-RPC 2.0, Streamable HTTP) with the same key and the `mcp:use` scope, or OAuth 2.1 with PKCE for connectors such as claude.ai and ChatGPT. Fixed read and non-destructive write tools on top of this API, with the same rules; none of them deletes, reverses or subtracts balance. Details in the MCP section of the documentation.\n\n**Scope.** The API covers day-to-day operations: customers, cards, purchases, redemptions, messages, coupons, branches and team. Only the dashboard can create and delete programs (with their design), create and edit automations, and create agency sub-accounts; through the API you can read them with `GET /programs/{program}`, `GET /automations` and `GET /subaccounts`."
  },
  "servers": [
    {
      "url": "/api/v1",
      "description": "This server"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "tags": [
    {
      "name": "cards",
      "description": "Customer cards: issue, look up, credit, subtract, redeem, expiration and memberships."
    },
    {
      "name": "customers",
      "description": "Customers: sign-up deduplicated by phone or email, lookup, editing and erasure."
    },
    {
      "name": "programs",
      "description": "Programs (card templates): rules, status, tiers, rewards and sign-up links. Programs are created and deleted from the dashboard (with their design); through the API you can read and edit them."
    },
    {
      "name": "segments",
      "description": "RFM customer segments for targeting messages."
    },
    {
      "name": "pushes",
      "description": "Messages to the Wallet pass of one card, a segment or all customers."
    },
    {
      "name": "webhooks",
      "description": "Subscriptions to receive signed events on your server."
    },
    {
      "name": "locations",
      "description": "The business's branches."
    },
    {
      "name": "managers",
      "description": "Team users and their permissions. The API manages branch managers and cashiers; owners and admins, only the dashboard."
    },
    {
      "name": "coupons",
      "description": "Promo codes."
    },
    {
      "name": "operations",
      "description": "Transaction ledger and reversals."
    },
    {
      "name": "statistics",
      "description": "Metrics calculated from real data (no estimates)."
    },
    {
      "name": "automations",
      "description": "Automations (messages and bonuses by trigger), read-only. They are created and edited in the dashboard."
    },
    {
      "name": "subaccounts",
      "description": "An agency's sub-accounts, read-only. They are created and managed from the agency dashboard."
    }
  ],
  "paths": {
    "/automations": {
      "get": {
        "tags": [
          "automations"
        ],
        "summary": "List automations",
        "operationId": "listAutomations",
        "description": "The business's automations, newest first, with their trigger and status. Read-only: they are created, edited and turned on from the dashboard.\n\n**Required scope:** `automations:read`.",
        "x-scope": "automations:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "trigger",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "enrolled",
                "earned",
                "reward_available",
                "birthday",
                "inactive",
                "points_expiring",
                "tier_upgraded",
                "referral_rewarded"
              ]
            },
            "description": "Filter by trigger"
          },
          {
            "name": "is_active",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            },
            "description": "1 = active, 0 = paused"
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PerPage"
          }
        ],
        "responses": {
          "200": {
            "description": "Automations",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Automation"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PageMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": 7,
                      "name": "We miss you (30 days)",
                      "trigger": "inactive",
                      "trigger_label": "No purchases in N days",
                      "trigger_config": {
                        "days": 30
                      },
                      "action": "send_message",
                      "action_label": "Send message",
                      "channel": "whatsapp",
                      "is_active": true,
                      "created_at": "2026-09-02T16:20:00+00:00"
                    }
                  ],
                  "meta": {
                    "current_page": 1,
                    "per_page": 25,
                    "total": 1,
                    "last_page": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards": {
      "get": {
        "tags": [
          "cards"
        ],
        "summary": "List cards",
        "operationId": "listCards",
        "description": "The business's cards, filterable by program, customer and status.\n\n**Required scope:** `cards:read`.",
        "x-scope": "cards:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "program_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Program"
          },
          {
            "name": "customer_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Customer"
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "suspended",
                "revoked",
                "expired",
                "used"
              ]
            },
            "description": "Status"
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PerPage"
          }
        ],
        "responses": {
          "200": {
            "description": "Cards",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Card"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PageMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "stamps",
                      "status": "active",
                      "balance": 5,
                      "unit": "stamps",
                      "tier_id": null,
                      "expires_at": null,
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "5 stamps"
                    }
                  ],
                  "meta": {
                    "current_page": 1,
                    "per_page": 25,
                    "total": 1,
                    "last_page": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Issue a card to a customer",
        "operationId": "createCard",
        "description": "Issues the program's card for the customer. Never duplicates customer+program: if it already exists, it is returned with HTTP 200. Applies the program's welcome gift.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "customer_id",
                  "program_id"
                ],
                "properties": {
                  "customer_id": {
                    "type": "integer",
                    "description": "Customer"
                  },
                  "program_id": {
                    "type": "integer",
                    "description": "Active program"
                  },
                  "initial_amount": {
                    "type": "integer",
                    "description": "Gift cards only: starting balance in cents. Cannot exceed the program's maximum balance (`config.max_balance`; if it does → 422 `max_balance`)",
                    "minimum": 0,
                    "maximum": 100000000
                  }
                }
              },
              "example": {
                "customer_id": 12,
                "program_id": 3
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The card already existed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Card"
                    }
                  }
                },
                "example": {
                  "data": {
                    "serial": "32852595C80B7B165F61",
                    "customer_id": 12,
                    "program_id": 3,
                    "program_type": "stamps",
                    "status": "active",
                    "balance": 5,
                    "unit": "stamps",
                    "tier_id": null,
                    "expires_at": null,
                    "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                    "wallet": {
                      "apple": "issued",
                      "google": "pending"
                    },
                    "balance_display": "5 stamps"
                  }
                }
              }
            }
          },
          "201": {
            "description": "Card issued",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Card"
                    }
                  }
                },
                "example": {
                  "data": {
                    "serial": "32852595C80B7B165F61",
                    "customer_id": 12,
                    "program_id": 3,
                    "program_type": "stamps",
                    "status": "active",
                    "balance": 5,
                    "unit": "stamps",
                    "tier_id": null,
                    "expires_at": null,
                    "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                    "wallet": {
                      "apple": "issued",
                      "google": "pending"
                    },
                    "balance_display": "5 stamps"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}": {
      "get": {
        "tags": [
          "cards"
        ],
        "summary": "Get card",
        "operationId": "getCard",
        "description": "Status, balance, tier, expiration and Wallet pass status.\n\n**Required scope:** `cards:read`.",
        "x-scope": "cards:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          }
        ],
        "responses": {
          "200": {
            "description": "Card",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Card"
                    }
                  }
                },
                "example": {
                  "data": {
                    "serial": "32852595C80B7B165F61",
                    "customer_id": 12,
                    "program_id": 3,
                    "program_type": "stamps",
                    "status": "active",
                    "balance": 5,
                    "unit": "stamps",
                    "tier_id": null,
                    "expires_at": null,
                    "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                    "wallet": {
                      "apple": "issued",
                      "google": "pending"
                    },
                    "balance_display": "5 stamps"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "patch": {
        "tags": [
          "cards"
        ],
        "summary": "Edit card",
        "operationId": "updateCard",
        "description": "Suspends or reactivates the card and/or changes its expiration. Does not change the balance. A revoked card or a used coupon cannot be changed (`card_final_state`). An expired card can only be reactivated by also sending a future `expires_at` (`card_expired`). The change is audited.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "status": {
                    "type": "string",
                    "description": "New status",
                    "enum": [
                      "active",
                      "suspended"
                    ]
                  },
                  "expires_at": {
                    "type": "string",
                    "description": "Expiration (local date; null = no expiration). Cannot be in the past.",
                    "format": "date",
                    "nullable": true
                  },
                  "reason": {
                    "type": "string",
                    "description": "Reason (audit log)",
                    "maxLength": 200
                  }
                }
              },
              "example": {
                "status": "suspended",
                "reason": "Review for suspicious use"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Card updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Card"
                    }
                  }
                },
                "example": {
                  "data": {
                    "serial": "32852595C80B7B165F61",
                    "customer_id": 12,
                    "program_id": 3,
                    "program_type": "stamps",
                    "status": "suspended",
                    "balance": 5,
                    "unit": "stamps",
                    "tier_id": null,
                    "expires_at": null,
                    "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                    "wallet": {
                      "apple": "issued",
                      "google": "pending"
                    },
                    "balance_display": "5 stamps"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "delete": {
        "tags": [
          "cards"
        ],
        "summary": "Revoke card",
        "operationId": "deleteCard",
        "description": "Revokes the card (final status, no further operations allowed). Nothing is deleted: the ledger is kept. The change is audited and the Wallet pass is updated.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reason": {
                    "type": "string",
                    "description": "Reason",
                    "maxLength": 200
                  }
                }
              },
              "example": {
                "reason": "Duplicate card"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Card revoked",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Card"
                    }
                  }
                },
                "example": {
                  "data": {
                    "serial": "32852595C80B7B165F61",
                    "customer_id": 12,
                    "program_id": 3,
                    "program_type": "stamps",
                    "status": "revoked",
                    "balance": 5,
                    "unit": "stamps",
                    "tier_id": null,
                    "expires_at": null,
                    "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                    "wallet": {
                      "apple": "issued",
                      "google": "pending"
                    },
                    "balance_display": "5 stamps"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/amount": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Add balance in cents",
        "operationId": "addAmount",
        "description": "Credits balance in cents without a purchase. Available for cashback (earning) and gift cards (top-up: respects the maximum balance and reloads); other types return `operation_not_supported`. It is recorded in the ledger with its reference.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount"
                ],
                "properties": {
                  "amount": {
                    "type": "integer",
                    "description": "Balance amount in cents",
                    "minimum": 1,
                    "maximum": 100000000
                  },
                  "description": {
                    "type": "string",
                    "description": "Description on the transaction",
                    "maxLength": 120
                  },
                  "branch_code": {
                    "type": "string",
                    "description": "Code of the branch where it happens (optional)",
                    "maxLength": 20,
                    "example": "CENTRO"
                  }
                }
              },
              "example": {
                "amount": 5000,
                "description": "Compensation for a delay"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Amount credited",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 981,
                      "type": "earn",
                      "amount": 1,
                      "balance_after": 5,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Credit (API)",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "stamps",
                      "status": "active",
                      "balance": 5,
                      "unit": "stamps",
                      "tier_id": null,
                      "expires_at": null,
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "5 stamps"
                    },
                    "discount": 0,
                    "redemption": null,
                    "replayed": false,
                    "message": "Credited: +1 stamp. Balance: 5 stamps."
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/amount/subtract": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Subtract balance in cents",
        "operationId": "subtractAmount",
        "description": "Subtracts balance in cents as an audited adjustment with a required reason (correction). The balance never goes negative (`insufficient_balance`). For regular usage use /debit or /redemptions.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount",
                  "reason"
                ],
                "properties": {
                  "amount": {
                    "type": "integer",
                    "description": "Balance amount in cents",
                    "minimum": 1,
                    "maximum": 100000000
                  },
                  "reason": {
                    "type": "string",
                    "description": "Reason (audit log)",
                    "minLength": 5,
                    "maxLength": 200
                  },
                  "branch_code": {
                    "type": "string",
                    "description": "Code of the branch where it happens (optional)",
                    "maxLength": 20,
                    "example": "CENTRO"
                  }
                }
              },
              "example": {
                "amount": 1,
                "reason": "Stamp recorded by mistake"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Amount subtracted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 981,
                      "type": "adjustment",
                      "amount": -1,
                      "balance_after": 4,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Adjustment: Stamp recorded by mistake",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "stamps",
                      "status": "active",
                      "balance": 4,
                      "unit": "stamps",
                      "tier_id": null,
                      "expires_at": null,
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "4 stamps"
                    },
                    "discount": 0,
                    "redemption": null,
                    "replayed": false,
                    "message": "Deducted: 1 stamp. Balance: 4 stamps."
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/coupon/redeem": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Use the card's coupon",
        "operationId": "redeemCouponCard",
        "description": "For coupon-type cards (single use): records the purchase, marks the card as used and returns the discount to apply. For promo codes see the coupons group.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "purchase_amount"
                ],
                "properties": {
                  "purchase_amount": {
                    "type": "integer",
                    "description": "Purchase total in cents",
                    "minimum": 1
                  },
                  "branch_code": {
                    "type": "string",
                    "description": "Code of the branch where it happens (optional)",
                    "maxLength": 20,
                    "example": "CENTRO"
                  }
                }
              },
              "example": {
                "purchase_amount": 20000
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Coupon used",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 981,
                      "type": "redeem",
                      "amount": -1,
                      "balance_after": 0,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Coupon redeemed",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "coupon",
                      "status": "used",
                      "balance": 0,
                      "unit": "uses",
                      "tier_id": null,
                      "expires_at": null,
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "0 uses"
                    },
                    "discount": 4000,
                    "redemption": null,
                    "replayed": false,
                    "message": "Deducted: 1 use. Discount to apply: L 40.00."
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/credit": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Load gift balance or renew pack",
        "operationId": "creditCard",
        "description": "Gift card: loads `amount` cents (respects the maximum balance and whether reloads are allowed). Visits or membership: new pack/period.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "amount": {
                    "type": "integer",
                    "description": "Gift card only: cents",
                    "minimum": 1
                  },
                  "branch_code": {
                    "type": "string",
                    "description": "Code of the branch where it happens (optional)",
                    "maxLength": 20,
                    "example": "CENTRO"
                  }
                }
              },
              "example": {
                "amount": 50000
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Top-up recorded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 981,
                      "type": "earn",
                      "amount": 1,
                      "balance_after": 5,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Credit (API)",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "stamps",
                      "status": "active",
                      "balance": 5,
                      "unit": "stamps",
                      "tier_id": null,
                      "expires_at": null,
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "5 stamps"
                    },
                    "discount": 0,
                    "redemption": null,
                    "replayed": false,
                    "message": "Credited: +1 stamp. Balance: 5 stamps."
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/debit": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Use balance, visit or use",
        "operationId": "debitCard",
        "description": "Uses gift balance, cashback (with `purchase_amount` to respect the per-purchase cap), a visit or a membership use.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount"
                ],
                "properties": {
                  "amount": {
                    "type": "integer",
                    "description": "Units to use (cents for gift card/cashback)",
                    "minimum": 1
                  },
                  "purchase_amount": {
                    "type": "integer",
                    "description": "Cashback: purchase total in cents"
                  },
                  "description": {
                    "type": "string",
                    "description": "Description",
                    "maxLength": 120
                  },
                  "branch_code": {
                    "type": "string",
                    "description": "Code of the branch where it happens (optional)",
                    "maxLength": 20,
                    "example": "CENTRO"
                  }
                }
              },
              "example": {
                "amount": 1
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Usage recorded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 981,
                      "type": "earn",
                      "amount": 1,
                      "balance_after": 5,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Credit (API)",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "stamps",
                      "status": "active",
                      "balance": 5,
                      "unit": "stamps",
                      "tier_id": null,
                      "expires_at": null,
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "5 stamps"
                    },
                    "discount": 0,
                    "redemption": null,
                    "replayed": false,
                    "message": "Credited: +1 stamp. Balance: 5 stamps."
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/expiration": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Set expiration date",
        "operationId": "setCardExpiration",
        "description": "Changes the card's expiration (end of the given day, local time). `null` = no expiration. An expired card with a future date becomes active again (the expired balance is not restored).\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "expires_at"
                ],
                "properties": {
                  "expires_at": {
                    "type": "string",
                    "description": "Date (YYYY-MM-DD) or null",
                    "format": "date",
                    "nullable": true
                  }
                }
              },
              "example": {
                "expires_at": "2027-03-31"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Card updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Card"
                    }
                  }
                },
                "example": {
                  "data": {
                    "serial": "32852595C80B7B165F61",
                    "customer_id": 12,
                    "program_id": 3,
                    "program_type": "stamps",
                    "status": "active",
                    "balance": 5,
                    "unit": "stamps",
                    "tier_id": null,
                    "expires_at": "2027-04-01T05:59:59+00:00",
                    "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                    "wallet": {
                      "apple": "issued",
                      "google": "pending"
                    },
                    "balance_display": "5 stamps"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/membership/renew": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Renew membership period",
        "operationId": "renewMembership",
        "description": "Starts a new period from today: the remaining uses expire and the uses included in the tier are credited.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "201": {
            "description": "Membership renewed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 981,
                      "type": "credit",
                      "amount": 8,
                      "balance_after": 8,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Membership renewal",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "membership",
                      "status": "active",
                      "balance": 8,
                      "unit": "uses",
                      "tier_id": 4,
                      "expires_at": "2026-12-18T15:04:05+00:00",
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "8 uses"
                    },
                    "discount": 0,
                    "redemption": null,
                    "replayed": false,
                    "message": "Credited: +8 uses. Balance: 8 uses."
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/membership/restore-uses": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Restore membership uses",
        "operationId": "restoreMembershipUses",
        "description": "Restores uses up to the number included in the tier without changing the validity period. If they are already complete it returns `nothing_to_restore`.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "201": {
            "description": "Uses restored",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 981,
                      "type": "credit",
                      "amount": 3,
                      "balance_after": 8,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Uses restoration",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "membership",
                      "status": "active",
                      "balance": 8,
                      "unit": "uses",
                      "tier_id": 4,
                      "expires_at": "2026-12-18T15:04:05+00:00",
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "8 uses"
                    },
                    "discount": 0,
                    "redemption": null,
                    "replayed": false,
                    "message": "Credited: +3 uses. Balance: 8 uses."
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/membership/tier": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Assign tier and period",
        "operationId": "setMembershipTier",
        "description": "Assigns a program tier (or `null` to remove it). For memberships, `period_days` restarts the period from today. If the program upgrades tiers automatically by spend, the next purchase may recalculate it.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "tier_id"
                ],
                "properties": {
                  "tier_id": {
                    "type": "integer",
                    "description": "Program tier or null",
                    "nullable": true
                  },
                  "period_days": {
                    "type": "integer",
                    "description": "Memberships: period length from today",
                    "minimum": 1,
                    "maximum": 3660
                  }
                }
              },
              "example": {
                "tier_id": 4,
                "period_days": 60
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Card updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Card"
                    }
                  }
                },
                "example": {
                  "data": {
                    "serial": "32852595C80B7B165F61",
                    "customer_id": 12,
                    "program_id": 3,
                    "program_type": "membership",
                    "status": "active",
                    "balance": 8,
                    "unit": "uses",
                    "tier_id": 4,
                    "expires_at": "2026-12-18T15:04:05+00:00",
                    "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                    "wallet": {
                      "apple": "issued",
                      "google": "pending"
                    },
                    "balance_display": "8 uses"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/points": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Add points",
        "operationId": "addPoints",
        "description": "Credits points without a purchase. Available for points programs; other types return `operation_not_supported`. It is recorded in the ledger with its reference.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount"
                ],
                "properties": {
                  "amount": {
                    "type": "integer",
                    "description": "Number of points",
                    "minimum": 1,
                    "maximum": 100000000
                  },
                  "description": {
                    "type": "string",
                    "description": "Description on the transaction",
                    "maxLength": 120
                  },
                  "branch_code": {
                    "type": "string",
                    "description": "Code of the branch where it happens (optional)",
                    "maxLength": 20,
                    "example": "CENTRO"
                  }
                }
              },
              "example": {
                "amount": 150,
                "description": "Compensation for a delay"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Points credited",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 981,
                      "type": "earn",
                      "amount": 1,
                      "balance_after": 5,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Credit (API)",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "stamps",
                      "status": "active",
                      "balance": 5,
                      "unit": "stamps",
                      "tier_id": null,
                      "expires_at": null,
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "5 stamps"
                    },
                    "discount": 0,
                    "redemption": null,
                    "replayed": false,
                    "message": "Credited: +1 stamp. Balance: 5 stamps."
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/points/subtract": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Subtract points",
        "operationId": "subtractPoints",
        "description": "Subtracts points as an audited adjustment with a required reason (correction). The balance never goes negative (`insufficient_balance`). For regular usage use /debit or /redemptions.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount",
                  "reason"
                ],
                "properties": {
                  "amount": {
                    "type": "integer",
                    "description": "Number of points",
                    "minimum": 1,
                    "maximum": 100000000
                  },
                  "reason": {
                    "type": "string",
                    "description": "Reason (audit log)",
                    "minLength": 5,
                    "maxLength": 200
                  },
                  "branch_code": {
                    "type": "string",
                    "description": "Code of the branch where it happens (optional)",
                    "maxLength": 20,
                    "example": "CENTRO"
                  }
                }
              },
              "example": {
                "amount": 1,
                "reason": "Stamp recorded by mistake"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Points subtracted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 981,
                      "type": "adjustment",
                      "amount": -1,
                      "balance_after": 4,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Adjustment: Stamp recorded by mistake",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "stamps",
                      "status": "active",
                      "balance": 4,
                      "unit": "stamps",
                      "tier_id": null,
                      "expires_at": null,
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "4 stamps"
                    },
                    "discount": 0,
                    "redemption": null,
                    "replayed": false,
                    "message": "Deducted: 1 stamp. Balance: 4 stamps."
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/redemptions": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Validate or redeem reward",
        "operationId": "redeemReward",
        "description": "Redeems a reward (deducts its cost and returns a code for the cashier). With `dry_run: true` it only validates.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "reward_id"
                ],
                "properties": {
                  "reward_id": {
                    "type": "integer",
                    "description": "Program reward"
                  },
                  "dry_run": {
                    "type": "boolean",
                    "description": "true = validate only, does not redeem"
                  },
                  "branch_code": {
                    "type": "string",
                    "description": "Code of the branch where it happens (optional)",
                    "maxLength": 20,
                    "example": "CENTRO"
                  }
                }
              },
              "example": {
                "reward_id": 7
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "dry_run: validation result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "valid": {
                          "type": "boolean"
                        },
                        "reason": {
                          "type": "string",
                          "nullable": true
                        },
                        "cost": {
                          "type": "integer"
                        },
                        "balance": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": {
                    "valid": false,
                    "reason": "insufficient_balance",
                    "cost": 10,
                    "balance": 5
                  }
                }
              }
            }
          },
          "201": {
            "description": "Redemption recorded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 981,
                      "type": "redeem",
                      "amount": -10,
                      "balance_after": 0,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Redemption: Americano coffee",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "stamps",
                      "status": "active",
                      "balance": 0,
                      "unit": "stamps",
                      "tier_id": null,
                      "expires_at": null,
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "0 stamps"
                    },
                    "discount": 0,
                    "redemption": {
                      "id": 55,
                      "code": "K7Q2M9XA",
                      "reward_id": 7
                    },
                    "replayed": false,
                    "message": "Redemption recorded: Americano coffee. Code K7Q2M9XA."
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/rewards": {
      "get": {
        "tags": [
          "cards"
        ],
        "summary": "Card rewards",
        "operationId": "listCardRewards",
        "description": "The program's active rewards and whether the current balance is enough.\n\n**Required scope:** `cards:read`.",
        "x-scope": "cards:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          }
        ],
        "responses": {
          "200": {
            "description": "Rewards",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "integer"
                          },
                          "name": {
                            "type": "string"
                          },
                          "cost": {
                            "type": "integer"
                          },
                          "stock": {
                            "type": "integer",
                            "nullable": true
                          },
                          "available": {
                            "type": "boolean"
                          }
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": 7,
                      "name": "Americano coffee",
                      "cost": 10,
                      "stock": null,
                      "available": false
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/rewards/receive": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Deliver reward",
        "operationId": "receiveReward",
        "description": "Equivalent to POST /cards/{serial}/redemptions: the customer receives the reward and its cost is deducted from the balance.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "reward_id"
                ],
                "properties": {
                  "reward_id": {
                    "type": "integer",
                    "description": "Program reward"
                  },
                  "dry_run": {
                    "type": "boolean",
                    "description": "true = validate only, does not redeem"
                  },
                  "branch_code": {
                    "type": "string",
                    "description": "Code of the branch where it happens (optional)",
                    "maxLength": 20,
                    "example": "CENTRO"
                  }
                }
              },
              "example": {
                "reward_id": 7
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "dry_run: validation result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "valid": {
                          "type": "boolean"
                        },
                        "reason": {
                          "type": "string",
                          "nullable": true
                        },
                        "cost": {
                          "type": "integer"
                        },
                        "balance": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": {
                    "valid": false,
                    "reason": "insufficient_balance",
                    "cost": 10,
                    "balance": 5
                  }
                }
              }
            }
          },
          "201": {
            "description": "Redemption recorded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 981,
                      "type": "redeem",
                      "amount": -10,
                      "balance_after": 0,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Redemption: Americano coffee",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "stamps",
                      "status": "active",
                      "balance": 0,
                      "unit": "stamps",
                      "tier_id": null,
                      "expires_at": null,
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "0 stamps"
                    },
                    "discount": 0,
                    "redemption": {
                      "id": 55,
                      "code": "K7Q2M9XA",
                      "reward_id": 7
                    },
                    "replayed": false,
                    "message": "Redemption recorded: Americano coffee. Code K7Q2M9XA."
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/stamps": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Add stamps",
        "operationId": "addStamps",
        "description": "Credits stamps without a purchase. Available for stamp cards (respects the program's maximum stamps per operation); other types return `operation_not_supported`. It is recorded in the ledger with its reference.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount"
                ],
                "properties": {
                  "amount": {
                    "type": "integer",
                    "description": "Number of stamps",
                    "minimum": 1,
                    "maximum": 100000000
                  },
                  "description": {
                    "type": "string",
                    "description": "Description on the transaction",
                    "maxLength": 120
                  },
                  "branch_code": {
                    "type": "string",
                    "description": "Code of the branch where it happens (optional)",
                    "maxLength": 20,
                    "example": "CENTRO"
                  }
                }
              },
              "example": {
                "amount": 1,
                "description": "Compensation for a delay"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Stamps credited",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 981,
                      "type": "earn",
                      "amount": 1,
                      "balance_after": 5,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Credit (API)",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "stamps",
                      "status": "active",
                      "balance": 5,
                      "unit": "stamps",
                      "tier_id": null,
                      "expires_at": null,
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "5 stamps"
                    },
                    "discount": 0,
                    "redemption": null,
                    "replayed": false,
                    "message": "Credited: +1 stamp. Balance: 5 stamps."
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/stamps/subtract": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Subtract stamps",
        "operationId": "subtractStamps",
        "description": "Subtracts stamps as an audited adjustment with a required reason (correction). The balance never goes negative (`insufficient_balance`). For regular usage use /debit or /redemptions.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount",
                  "reason"
                ],
                "properties": {
                  "amount": {
                    "type": "integer",
                    "description": "Number of stamps",
                    "minimum": 1,
                    "maximum": 100000000
                  },
                  "reason": {
                    "type": "string",
                    "description": "Reason (audit log)",
                    "minLength": 5,
                    "maxLength": 200
                  },
                  "branch_code": {
                    "type": "string",
                    "description": "Code of the branch where it happens (optional)",
                    "maxLength": 20,
                    "example": "CENTRO"
                  }
                }
              },
              "example": {
                "amount": 1,
                "reason": "Stamp recorded by mistake"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Stamps subtracted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 981,
                      "type": "adjustment",
                      "amount": -1,
                      "balance_after": 4,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Adjustment: Stamp recorded by mistake",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "stamps",
                      "status": "active",
                      "balance": 4,
                      "unit": "stamps",
                      "tier_id": null,
                      "expires_at": null,
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "4 stamps"
                    },
                    "discount": 0,
                    "redemption": null,
                    "replayed": false,
                    "message": "Deducted: 1 stamp. Balance: 4 stamps."
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/transactions": {
      "get": {
        "tags": [
          "cards"
        ],
        "summary": "Card transactions",
        "operationId": "listCardTransactions",
        "description": "The card's ledger, newest first.\n\n**Required scope:** `cards:read`.",
        "x-scope": "cards:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PerPage"
          }
        ],
        "responses": {
          "200": {
            "description": "Transactions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Transaction"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PageMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": 981,
                      "type": "earn",
                      "amount": 1,
                      "balance_after": 5,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Credit (API)",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    }
                  ],
                  "meta": {
                    "current_page": 1,
                    "per_page": 25,
                    "total": 1,
                    "last_page": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/visits": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Add visits",
        "operationId": "addVisits",
        "description": "Credits visits without a purchase. Available for visit packs (top-up to the pack); other types return `operation_not_supported`. It is recorded in the ledger with its reference.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount"
                ],
                "properties": {
                  "amount": {
                    "type": "integer",
                    "description": "Number of visits",
                    "minimum": 1,
                    "maximum": 100000000
                  },
                  "description": {
                    "type": "string",
                    "description": "Description on the transaction",
                    "maxLength": 120
                  },
                  "branch_code": {
                    "type": "string",
                    "description": "Code of the branch where it happens (optional)",
                    "maxLength": 20,
                    "example": "CENTRO"
                  }
                }
              },
              "example": {
                "amount": 1,
                "description": "Compensation for a delay"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Visits credited",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 981,
                      "type": "earn",
                      "amount": 1,
                      "balance_after": 5,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Credit (API)",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "stamps",
                      "status": "active",
                      "balance": 5,
                      "unit": "stamps",
                      "tier_id": null,
                      "expires_at": null,
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "5 stamps"
                    },
                    "discount": 0,
                    "redemption": null,
                    "replayed": false,
                    "message": "Credited: +1 stamp. Balance: 5 stamps."
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/cards/{serial}/visits/subtract": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Subtract visits",
        "operationId": "subtractVisits",
        "description": "Subtracts visits as an audited adjustment with a required reason (correction). The balance never goes negative (`insufficient_balance`). For regular usage use /debit or /redemptions.\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Serial"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount",
                  "reason"
                ],
                "properties": {
                  "amount": {
                    "type": "integer",
                    "description": "Number of visits",
                    "minimum": 1,
                    "maximum": 100000000
                  },
                  "reason": {
                    "type": "string",
                    "description": "Reason (audit log)",
                    "minLength": 5,
                    "maxLength": 200
                  },
                  "branch_code": {
                    "type": "string",
                    "description": "Code of the branch where it happens (optional)",
                    "maxLength": 20,
                    "example": "CENTRO"
                  }
                }
              },
              "example": {
                "amount": 1,
                "reason": "Stamp recorded by mistake"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Visits subtracted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 981,
                      "type": "adjustment",
                      "amount": -1,
                      "balance_after": 4,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Adjustment: Stamp recorded by mistake",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "stamps",
                      "status": "active",
                      "balance": 4,
                      "unit": "stamps",
                      "tier_id": null,
                      "expires_at": null,
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "4 stamps"
                    },
                    "discount": 0,
                    "redemption": null,
                    "replayed": false,
                    "message": "Deducted: 1 stamp. Balance: 4 stamps."
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/coupons": {
      "get": {
        "tags": [
          "coupons"
        ],
        "summary": "List coupons",
        "operationId": "listCoupons",
        "description": "Promo coupons, newest first.\n\n**Required scope:** `coupons:read`.",
        "x-scope": "coupons:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "code",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Exact code"
          },
          {
            "name": "is_active",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            },
            "description": "1 = active, 0 = inactive"
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PerPage"
          }
        ],
        "responses": {
          "200": {
            "description": "Coupons",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Coupon"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PageMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": 5,
                      "code": "VERANO15",
                      "name": "Summer 15%",
                      "discount_type": "percent",
                      "value": 1500,
                      "value_display": "15%",
                      "min_purchase": 20000,
                      "max_uses": 500,
                      "max_uses_per_customer": 1,
                      "uses_count": 37,
                      "customer_id": null,
                      "starts_at": "2026-11-01T06:00:00+00:00",
                      "ends_at": "2026-12-01T05:59:59+00:00",
                      "is_active": true,
                      "created_at": "2026-10-19T15:04:05+00:00"
                    }
                  ],
                  "meta": {
                    "current_page": 1,
                    "per_page": 25,
                    "total": 1,
                    "last_page": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "post": {
        "tags": [
          "coupons"
        ],
        "summary": "Create coupon",
        "operationId": "createCoupon",
        "description": "Creates a promo code that the cashier redeems in the scanner.\n\n**Required scope:** `coupons:write`.",
        "x-scope": "coupons:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "code": {
                    "type": "string",
                    "description": "Code (letters, numbers, - and _; stored in uppercase; unique)",
                    "maxLength": 40
                  },
                  "name": {
                    "type": "string",
                    "description": "Name",
                    "maxLength": 120
                  },
                  "discount_type": {
                    "type": "string",
                    "description": "Type",
                    "enum": [
                      "percent",
                      "fixed",
                      "product"
                    ]
                  },
                  "value": {
                    "type": "integer",
                    "description": "percent: percentage ×100 (max. 10000 = 100%); fixed: cents; product: ignored",
                    "minimum": 0
                  },
                  "min_purchase": {
                    "type": "integer",
                    "description": "Minimum purchase in cents",
                    "minimum": 0
                  },
                  "max_uses": {
                    "type": "integer",
                    "description": "Total uses (null = unlimited)",
                    "minimum": 1,
                    "nullable": true
                  },
                  "max_uses_per_customer": {
                    "type": "integer",
                    "description": "Uses per customer",
                    "minimum": 1,
                    "maximum": 1000
                  },
                  "customer_id": {
                    "type": "integer",
                    "description": "Personal coupon for this customer",
                    "nullable": true
                  },
                  "starts_at": {
                    "type": "string",
                    "description": "Start: the business's local date (YYYY-MM-DD, from 00:00) or ISO 8601 date and time",
                    "example": "2026-11-01",
                    "nullable": true
                  },
                  "ends_at": {
                    "type": "string",
                    "description": "End: the business's local date (YYYY-MM-DD, until 23:59:59) or ISO 8601 date and time. Same as or after the start",
                    "example": "2026-11-30",
                    "nullable": true
                  },
                  "is_active": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "code",
                  "name",
                  "discount_type"
                ]
              },
              "example": {
                "code": "VERANO15",
                "name": "Summer 15%",
                "discount_type": "percent",
                "value": 1500,
                "min_purchase": 20000,
                "max_uses": 500,
                "starts_at": "2026-11-01",
                "ends_at": "2026-11-30"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Coupon created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Coupon"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 5,
                    "code": "VERANO15",
                    "name": "Summer 15%",
                    "discount_type": "percent",
                    "value": 1500,
                    "value_display": "15%",
                    "min_purchase": 20000,
                    "max_uses": 500,
                    "max_uses_per_customer": 1,
                    "uses_count": 37,
                    "customer_id": null,
                    "starts_at": "2026-11-01T06:00:00+00:00",
                    "ends_at": "2026-12-01T05:59:59+00:00",
                    "is_active": true,
                    "created_at": "2026-10-19T15:04:05+00:00"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/coupons/{coupon}": {
      "get": {
        "tags": [
          "coupons"
        ],
        "summary": "Get coupon",
        "operationId": "getCoupon",
        "description": "Coupon data and uses.\n\n**Required scope:** `coupons:read`.",
        "x-scope": "coupons:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Coupon"
          }
        ],
        "responses": {
          "200": {
            "description": "Coupon",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Coupon"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 5,
                    "code": "VERANO15",
                    "name": "Summer 15%",
                    "discount_type": "percent",
                    "value": 1500,
                    "value_display": "15%",
                    "min_purchase": 20000,
                    "max_uses": 500,
                    "max_uses_per_customer": 1,
                    "uses_count": 37,
                    "customer_id": null,
                    "starts_at": "2026-11-01T06:00:00+00:00",
                    "ends_at": "2026-12-01T05:59:59+00:00",
                    "is_active": true,
                    "created_at": "2026-10-19T15:04:05+00:00"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "patch": {
        "tags": [
          "coupons"
        ],
        "summary": "Edit coupon",
        "operationId": "updateCoupon",
        "description": "Updates only the fields sent. Rules are validated against the resulting value: changing to `percent` requires a `value` ≤ 10000 and `ends_at` cannot end up before `starts_at` (sent or stored).\n\n**Required scope:** `coupons:write`.",
        "x-scope": "coupons:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Coupon"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "code": {
                    "type": "string",
                    "description": "Code (letters, numbers, - and _; stored in uppercase; unique)",
                    "maxLength": 40
                  },
                  "name": {
                    "type": "string",
                    "description": "Name",
                    "maxLength": 120
                  },
                  "discount_type": {
                    "type": "string",
                    "description": "Type",
                    "enum": [
                      "percent",
                      "fixed",
                      "product"
                    ]
                  },
                  "value": {
                    "type": "integer",
                    "description": "percent: percentage ×100 (max. 10000 = 100%); fixed: cents; product: ignored",
                    "minimum": 0
                  },
                  "min_purchase": {
                    "type": "integer",
                    "description": "Minimum purchase in cents",
                    "minimum": 0
                  },
                  "max_uses": {
                    "type": "integer",
                    "description": "Total uses (null = unlimited)",
                    "minimum": 1,
                    "nullable": true
                  },
                  "max_uses_per_customer": {
                    "type": "integer",
                    "description": "Uses per customer",
                    "minimum": 1,
                    "maximum": 1000
                  },
                  "customer_id": {
                    "type": "integer",
                    "description": "Personal coupon for this customer",
                    "nullable": true
                  },
                  "starts_at": {
                    "type": "string",
                    "description": "Start: the business's local date (YYYY-MM-DD, from 00:00) or ISO 8601 date and time",
                    "example": "2026-11-01",
                    "nullable": true
                  },
                  "ends_at": {
                    "type": "string",
                    "description": "End: the business's local date (YYYY-MM-DD, until 23:59:59) or ISO 8601 date and time. Same as or after the start",
                    "example": "2026-11-30",
                    "nullable": true
                  },
                  "is_active": {
                    "type": "boolean"
                  }
                }
              },
              "example": {
                "is_active": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Coupon updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Coupon"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 5,
                    "code": "VERANO15",
                    "name": "Summer 15%",
                    "discount_type": "percent",
                    "value": 1500,
                    "value_display": "15%",
                    "min_purchase": 20000,
                    "max_uses": 500,
                    "max_uses_per_customer": 1,
                    "uses_count": 37,
                    "customer_id": null,
                    "starts_at": "2026-11-01T06:00:00+00:00",
                    "ends_at": "2026-12-01T05:59:59+00:00",
                    "is_active": false,
                    "created_at": "2026-10-19T15:04:05+00:00"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "delete": {
        "tags": [
          "coupons"
        ],
        "summary": "Delete coupon",
        "operationId": "deleteCoupon",
        "description": "Only if it has no redemptions (`coupon_in_use`, 409); otherwise, deactivate it.\n\n**Required scope:** `coupons:write`.",
        "x-scope": "coupons:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Coupon"
          }
        ],
        "responses": {
          "200": {
            "description": "Coupon deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Deleted"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 7,
                    "deleted": true
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/customers": {
      "get": {
        "tags": [
          "customers"
        ],
        "summary": "List or search customers",
        "operationId": "listCustomers",
        "description": "Paginated list of non-anonymized customers, sorted by ID. Filter by phone (normalized to E.164 with the business's country) or by email.\n\n**Required scope:** `customers:read`.",
        "x-scope": "customers:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "phone",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Exact phone (local or international)"
          },
          {
            "name": "email",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Exact email"
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PerPage"
          }
        ],
        "responses": {
          "200": {
            "description": "Customers",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Customer"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PageMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": 12,
                      "name": "Carla Mejía",
                      "phone": "+50499887766",
                      "email": "carla@ejemplo.com",
                      "birthday": "1994-05-17",
                      "tags": [
                        "vip"
                      ],
                      "rfm_segment": "loyal",
                      "consents": {
                        "marketing_email": true,
                        "marketing_whatsapp": false
                      },
                      "created_at": "2026-09-02T14:20:00+00:00"
                    }
                  ],
                  "meta": {
                    "current_page": 1,
                    "per_page": 25,
                    "total": 1,
                    "last_page": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "post": {
        "tags": [
          "customers"
        ],
        "summary": "Create or identify customer",
        "operationId": "createCustomer",
        "description": "Creates the customer or returns the existing one if the business already has one with the same phone or email (`created: false`, HTTP 200).\n\n**Required scope:** `customers:write`.",
        "x-scope": "customers:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Full name",
                    "maxLength": 120
                  },
                  "phone": {
                    "type": "string",
                    "description": "Phone (required if there is no email)",
                    "maxLength": 20
                  },
                  "email": {
                    "type": "string",
                    "description": "Email (required if there is no phone)",
                    "format": "email",
                    "maxLength": 150
                  },
                  "birthday": {
                    "type": "string",
                    "description": "Date of birth",
                    "format": "date"
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "maxLength": 30
                    }
                  },
                  "consents": {
                    "type": "object",
                    "properties": {
                      "marketing_email": {
                        "type": "boolean"
                      },
                      "marketing_whatsapp": {
                        "type": "boolean"
                      },
                      "terms": {
                        "type": "boolean"
                      }
                    },
                    "description": "Consents granted (recorded with date and IP)"
                  }
                }
              },
              "example": {
                "name": "Carla Mejía",
                "phone": "9988-7766",
                "email": "carla@ejemplo.com",
                "consents": {
                  "marketing_email": true,
                  "terms": true
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Already existed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Customer"
                    },
                    "created": {
                      "type": "boolean"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 12,
                    "name": "Carla Mejía",
                    "phone": "+50499887766",
                    "email": "carla@ejemplo.com",
                    "birthday": "1994-05-17",
                    "tags": [
                      "vip"
                    ],
                    "rfm_segment": "loyal",
                    "consents": {
                      "marketing_email": true,
                      "marketing_whatsapp": false
                    },
                    "created_at": "2026-09-02T14:20:00+00:00"
                  },
                  "created": false
                }
              }
            }
          },
          "201": {
            "description": "Customer created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Customer"
                    },
                    "created": {
                      "type": "boolean"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 12,
                    "name": "Carla Mejía",
                    "phone": "+50499887766",
                    "email": "carla@ejemplo.com",
                    "birthday": "1994-05-17",
                    "tags": [
                      "vip"
                    ],
                    "rfm_segment": "loyal",
                    "consents": {
                      "marketing_email": true,
                      "marketing_whatsapp": false
                    },
                    "created_at": "2026-09-02T14:20:00+00:00"
                  },
                  "created": true
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/customers/{customer}": {
      "get": {
        "tags": [
          "customers"
        ],
        "summary": "Get customer",
        "operationId": "getCustomer",
        "description": "Customer with all their cards.\n\n**Required scope:** `customers:read`.",
        "x-scope": "customers:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Customer"
          }
        ],
        "responses": {
          "200": {
            "description": "Customer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Customer"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 12,
                    "name": "Carla Mejía",
                    "phone": "+50499887766",
                    "email": "carla@ejemplo.com",
                    "birthday": "1994-05-17",
                    "tags": [
                      "vip"
                    ],
                    "rfm_segment": "loyal",
                    "consents": {
                      "marketing_email": true,
                      "marketing_whatsapp": false
                    },
                    "created_at": "2026-09-02T14:20:00+00:00",
                    "cards": [
                      {
                        "serial": "32852595C80B7B165F61",
                        "customer_id": 12,
                        "program_id": 3,
                        "program_type": "stamps",
                        "status": "active",
                        "balance": 5,
                        "unit": "stamps",
                        "tier_id": null,
                        "expires_at": null,
                        "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                        "wallet": {
                          "apple": "issued",
                          "google": "pending"
                        },
                        "balance_display": "5 stamps"
                      }
                    ]
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "patch": {
        "tags": [
          "customers"
        ],
        "summary": "Edit customer",
        "operationId": "updateCustomer",
        "description": "Updates only the fields sent.\n\n**Required scope:** `customers:write`.",
        "x-scope": "customers:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Customer"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Name",
                    "maxLength": 120
                  },
                  "email": {
                    "type": "string",
                    "description": "Email unique within the business",
                    "format": "email",
                    "nullable": true
                  },
                  "birthday": {
                    "type": "string",
                    "description": "Date of birth",
                    "format": "date",
                    "nullable": true
                  },
                  "tags": {
                    "type": "array",
                    "nullable": true,
                    "items": {
                      "type": "string"
                    }
                  }
                }
              },
              "example": {
                "tags": [
                  "vip",
                  "wholesale"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Customer updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Customer"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 12,
                    "name": "Carla Mejía",
                    "phone": "+50499887766",
                    "email": "carla@ejemplo.com",
                    "birthday": "1994-05-17",
                    "tags": [
                      "vip",
                      "wholesale"
                    ],
                    "rfm_segment": "loyal",
                    "consents": {
                      "marketing_email": true,
                      "marketing_whatsapp": false
                    },
                    "created_at": "2026-09-02T14:20:00+00:00"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "delete": {
        "tags": [
          "customers"
        ],
        "summary": "Delete customer (anonymize)",
        "operationId": "deleteCustomer",
        "description": "Right to erasure: deletes name, phone, email, birthday, tags and notes, and revokes their cards. The ledger is kept without personal data. Repeating it has no effect.\n\n**Required scope:** `customers:write`.",
        "x-scope": "customers:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Customer"
          }
        ],
        "responses": {
          "200": {
            "description": "Customer anonymized",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "integer"
                        },
                        "anonymized": {
                          "type": "boolean"
                        },
                        "anonymized_at": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 12,
                    "anonymized": true,
                    "anonymized_at": "2026-10-19T15:04:05+00:00"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/locations": {
      "get": {
        "tags": [
          "locations"
        ],
        "summary": "List branches",
        "operationId": "listLocations",
        "description": "The business's branches sorted by name.\n\n**Required scope:** `locations:read`.",
        "x-scope": "locations:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "is_active",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            },
            "description": "1 = active, 0 = inactive"
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PerPage"
          }
        ],
        "responses": {
          "200": {
            "description": "Branches",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Location"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PageMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": 2,
                      "name": "Downtown Branch",
                      "code": "CENTRO",
                      "address": "Av. Cervantes 123",
                      "city": "Tegucigalpa",
                      "phone": "+50422223333",
                      "latitude": 14.0723,
                      "longitude": -87.1921,
                      "is_active": true,
                      "created_at": "2026-08-01T13:00:00+00:00"
                    }
                  ],
                  "meta": {
                    "current_page": 1,
                    "per_page": 25,
                    "total": 1,
                    "last_page": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "post": {
        "tags": [
          "locations"
        ],
        "summary": "Create branch",
        "operationId": "createLocation",
        "description": "Respects the plan's branch limit (`plan_limit`, 403).\n\n**Required scope:** `locations:write`.",
        "x-scope": "locations:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Name",
                    "maxLength": 120
                  },
                  "code": {
                    "type": "string",
                    "description": "Unique short code (stored in uppercase, without symbols)",
                    "maxLength": 20
                  },
                  "address": {
                    "type": "string",
                    "description": "Address",
                    "maxLength": 255,
                    "nullable": true
                  },
                  "city": {
                    "type": "string",
                    "description": "City",
                    "maxLength": 100,
                    "nullable": true
                  },
                  "phone": {
                    "type": "string",
                    "description": "Phone",
                    "maxLength": 30,
                    "nullable": true
                  },
                  "latitude": {
                    "type": "number",
                    "description": "Latitude (always together with longitude): Wallet pass location",
                    "minimum": -90,
                    "maximum": 90,
                    "nullable": true
                  },
                  "longitude": {
                    "type": "number",
                    "description": "Longitude (always together with latitude)",
                    "minimum": -180,
                    "maximum": 180,
                    "nullable": true
                  },
                  "is_active": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "name",
                  "code"
                ]
              },
              "example": {
                "name": "Downtown Branch",
                "code": "CENTRO",
                "address": "Av. Cervantes 123",
                "city": "Tegucigalpa",
                "latitude": 14.0723,
                "longitude": -87.1921
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Branch created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Location"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 2,
                    "name": "Downtown Branch",
                    "code": "CENTRO",
                    "address": "Av. Cervantes 123",
                    "city": "Tegucigalpa",
                    "phone": "+50422223333",
                    "latitude": 14.0723,
                    "longitude": -87.1921,
                    "is_active": true,
                    "created_at": "2026-08-01T13:00:00+00:00"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/locations/{location}": {
      "get": {
        "tags": [
          "locations"
        ],
        "summary": "Get branch",
        "operationId": "getLocation",
        "description": "Branch data.\n\n**Required scope:** `locations:read`.",
        "x-scope": "locations:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Location"
          }
        ],
        "responses": {
          "200": {
            "description": "Branch",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Location"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 2,
                    "name": "Downtown Branch",
                    "code": "CENTRO",
                    "address": "Av. Cervantes 123",
                    "city": "Tegucigalpa",
                    "phone": "+50422223333",
                    "latitude": 14.0723,
                    "longitude": -87.1921,
                    "is_active": true,
                    "created_at": "2026-08-01T13:00:00+00:00"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "patch": {
        "tags": [
          "locations"
        ],
        "summary": "Edit branch",
        "operationId": "updateLocation",
        "description": "Updates only the fields sent. To close it use `is_active: false`.\n\n**Required scope:** `locations:write`.",
        "x-scope": "locations:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Location"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Name",
                    "maxLength": 120
                  },
                  "code": {
                    "type": "string",
                    "description": "Unique short code (stored in uppercase, without symbols)",
                    "maxLength": 20
                  },
                  "address": {
                    "type": "string",
                    "description": "Address",
                    "maxLength": 255,
                    "nullable": true
                  },
                  "city": {
                    "type": "string",
                    "description": "City",
                    "maxLength": 100,
                    "nullable": true
                  },
                  "phone": {
                    "type": "string",
                    "description": "Phone",
                    "maxLength": 30,
                    "nullable": true
                  },
                  "latitude": {
                    "type": "number",
                    "description": "Latitude (always together with longitude): Wallet pass location",
                    "minimum": -90,
                    "maximum": 90,
                    "nullable": true
                  },
                  "longitude": {
                    "type": "number",
                    "description": "Longitude (always together with latitude)",
                    "minimum": -180,
                    "maximum": 180,
                    "nullable": true
                  },
                  "is_active": {
                    "type": "boolean"
                  }
                }
              },
              "example": {
                "phone": "+50422224444"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Branch updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Location"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 2,
                    "name": "Downtown Branch",
                    "code": "CENTRO",
                    "address": "Av. Cervantes 123",
                    "city": "Tegucigalpa",
                    "phone": "+50422224444",
                    "latitude": 14.0723,
                    "longitude": -87.1921,
                    "is_active": true,
                    "created_at": "2026-08-01T13:00:00+00:00"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "delete": {
        "tags": [
          "locations"
        ],
        "summary": "Delete branch",
        "operationId": "deleteLocation",
        "description": "Only if it has no purchases or transactions (`location_in_use`, 409) and is not the business's last branch (`last_location`, 422). If it has history, deactivate it.\n\n**Required scope:** `locations:write`.",
        "x-scope": "locations:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Location"
          }
        ],
        "responses": {
          "200": {
            "description": "Branch deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Deleted"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 7,
                    "deleted": true
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/managers": {
      "get": {
        "tags": [
          "managers"
        ],
        "summary": "List team users",
        "operationId": "listManagers",
        "description": "The business's users with their role and branches.\n\n**Required scope:** `managers:read`.",
        "x-scope": "managers:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "role",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Role"
          },
          {
            "name": "is_active",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            },
            "description": "1 = active, 0 = inactive"
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PerPage"
          }
        ],
        "responses": {
          "200": {
            "description": "Users",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Manager"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PageMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": 21,
                      "name": "Luis Rivera",
                      "email": "luis@ejemplo.com",
                      "role": "cashier",
                      "role_label": "Cashier",
                      "is_active": true,
                      "branch_ids": [
                        2
                      ],
                      "last_login_at": null,
                      "created_at": "2026-10-19T15:04:05+00:00"
                    }
                  ],
                  "meta": {
                    "current_page": 1,
                    "per_page": 25,
                    "total": 1,
                    "last_page": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "post": {
        "tags": [
          "managers"
        ],
        "summary": "Create team user",
        "operationId": "createManager",
        "description": "Creates a user with the `manager` or `cashier` role and sends them an email to set their password (the API never receives passwords). Respects the plan's user limit.\n\n**Required scope:** `managers:write`.",
        "x-scope": "managers:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Name",
                    "maxLength": 120
                  },
                  "email": {
                    "type": "string",
                    "description": "Email (unique)",
                    "format": "email",
                    "maxLength": 255
                  },
                  "role": {
                    "type": "string",
                    "description": "Role assignable through the API: manager or cashier. Owners and admins are managed only from the dashboard.",
                    "enum": [
                      "manager",
                      "cashier"
                    ]
                  },
                  "branch_ids": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    },
                    "nullable": true,
                    "description": "Assigned branches"
                  },
                  "is_active": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "name",
                  "email",
                  "role"
                ]
              },
              "example": {
                "name": "Luis Rivera",
                "email": "luis@ejemplo.com",
                "role": "cashier",
                "branch_ids": [
                  2
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "User created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/Manager"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "invitation_sent": {
                              "type": "boolean",
                              "description": "The email to set the password was sent"
                            }
                          }
                        }
                      ]
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 21,
                    "name": "Luis Rivera",
                    "email": "luis@ejemplo.com",
                    "role": "cashier",
                    "role_label": "Cashier",
                    "is_active": true,
                    "branch_ids": [
                      2
                    ],
                    "last_login_at": null,
                    "created_at": "2026-10-19T15:04:05+00:00",
                    "invitation_sent": true
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/managers/permissions": {
      "get": {
        "tags": [
          "managers"
        ],
        "summary": "Roles and permissions",
        "operationId": "listManagerPermissions",
        "description": "Available roles with the permissions each one grants.\n\n`assignable_by_api` lists the roles an API key can assign (branch manager and cashier). Owner and admin are assigned only from the dashboard: an admin can create API keys.\n\n**Required scope:** `managers:read`.",
        "x-scope": "managers:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Roles",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "role": {
                            "type": "string"
                          },
                          "label": {
                            "type": "string"
                          },
                          "all_branches": {
                            "type": "boolean",
                            "description": "Works at every branch"
                          },
                          "abilities": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "key": {
                                  "type": "string"
                                },
                                "label": {
                                  "type": "string"
                                }
                              }
                            }
                          },
                          "assignable_by_api": {
                            "type": "boolean"
                          }
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "role": "cashier",
                      "label": "Cashier",
                      "all_branches": false,
                      "abilities": [
                        {
                          "key": "cards.operate",
                          "label": "Scan, earn and redeem"
                        }
                      ],
                      "assignable_by_api": true
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/managers/{manager}": {
      "get": {
        "tags": [
          "managers"
        ],
        "summary": "Get user",
        "operationId": "getManager",
        "description": "User data.\n\n**Required scope:** `managers:read`.",
        "x-scope": "managers:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Manager"
          }
        ],
        "responses": {
          "200": {
            "description": "User",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Manager"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 21,
                    "name": "Luis Rivera",
                    "email": "luis@ejemplo.com",
                    "role": "cashier",
                    "role_label": "Cashier",
                    "is_active": true,
                    "branch_ids": [
                      2
                    ],
                    "last_login_at": null,
                    "created_at": "2026-10-19T15:04:05+00:00"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "patch": {
        "tags": [
          "managers"
        ],
        "summary": "Edit user",
        "operationId": "updateManager",
        "description": "Updates the name, email, role, branches or status of a branch manager or cashier. Owners (`owner_protected`) and admins (`role_protected`) cannot be changed through the API (403). Reactivating respects the plan's user limit.\n\n**Required scope:** `managers:write`.",
        "x-scope": "managers:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Manager"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Name",
                    "maxLength": 120
                  },
                  "email": {
                    "type": "string",
                    "description": "Email (unique)",
                    "format": "email",
                    "maxLength": 255
                  },
                  "role": {
                    "type": "string",
                    "description": "Role assignable through the API: manager or cashier. Owners and admins are managed only from the dashboard.",
                    "enum": [
                      "manager",
                      "cashier"
                    ]
                  },
                  "branch_ids": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    },
                    "nullable": true,
                    "description": "Assigned branches"
                  },
                  "is_active": {
                    "type": "boolean",
                    "description": "Reactivating respects the plan's user limit (`plan_limit`, 403)"
                  }
                }
              },
              "example": {
                "role": "manager",
                "branch_ids": [
                  2,
                  3
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "User updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Manager"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 21,
                    "name": "Luis Rivera",
                    "email": "luis@ejemplo.com",
                    "role": "manager",
                    "role_label": "Branch manager",
                    "is_active": true,
                    "branch_ids": [
                      2,
                      3
                    ],
                    "last_login_at": null,
                    "created_at": "2026-10-19T15:04:05+00:00"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "delete": {
        "tags": [
          "managers"
        ],
        "summary": "Deactivate user",
        "operationId": "deleteManager",
        "description": "Deactivates a branch manager or cashier (they can no longer log in or operate). The user is not deleted, to keep the operations history. Owners and admins cannot be changed through the API (403).\n\n**Required scope:** `managers:write`.",
        "x-scope": "managers:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Manager"
          }
        ],
        "responses": {
          "200": {
            "description": "User deactivated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Manager"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 21,
                    "name": "Luis Rivera",
                    "email": "luis@ejemplo.com",
                    "role": "cashier",
                    "role_label": "Cashier",
                    "is_active": false,
                    "branch_ids": [
                      2
                    ],
                    "last_login_at": null,
                    "created_at": "2026-10-19T15:04:05+00:00"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/operations": {
      "get": {
        "tags": [
          "operations"
        ],
        "summary": "List operations",
        "operationId": "listOperations",
        "description": "Ledger of the whole business (newest first): earnings, redemptions, top-ups, usages, adjustments, reversals and expirations.\n\n**Required scope:** `cards:read`.",
        "x-scope": "cards:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "earn",
                "bonus",
                "redeem",
                "credit",
                "debit",
                "reversal",
                "expiration",
                "adjustment"
              ]
            },
            "description": "Transaction type"
          },
          {
            "name": "program_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Program"
          },
          {
            "name": "customer_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Customer (transactions from all their cards)"
          },
          {
            "name": "card_serial",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Card"
          },
          {
            "$ref": "#/components/parameters/From"
          },
          {
            "$ref": "#/components/parameters/To"
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PerPage"
          }
        ],
        "responses": {
          "200": {
            "description": "Operations",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Operation"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PageMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": 981,
                      "type": "earn",
                      "amount": 1,
                      "balance_after": 5,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Credit (API)",
                      "created_at": "2026-10-19T15:04:05+00:00",
                      "card_serial": "32852595C80B7B165F61",
                      "program_id": 3,
                      "customer_id": 12
                    }
                  ],
                  "meta": {
                    "current_page": 1,
                    "per_page": 25,
                    "total": 1,
                    "last_page": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/programs": {
      "get": {
        "tags": [
          "programs"
        ],
        "summary": "Active programs",
        "operationId": "listActivePrograms",
        "description": "Active programs with their rewards catalog and sign-up link (what you need to issue cards from a POS).\n\n**Required scope:** `cards:read`.",
        "x-scope": "cards:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Programs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ProgramSummary"
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": 3,
                      "name": "Stamp card",
                      "type": "stamps",
                      "unit": "stamps",
                      "config": {
                        "stamps_target": 10,
                        "reward_name": "Americano coffee",
                        "stamps_per_purchase": 1
                      },
                      "rewards": [
                        {
                          "id": 7,
                          "name": "Americano coffee",
                          "cost": 10,
                          "stock": null
                        }
                      ],
                      "enrollment_url": "https://app.example.com/r/cafe-aroma/tarjeta-de-sellos"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/programs/{program}": {
      "get": {
        "tags": [
          "programs"
        ],
        "summary": "Get program",
        "operationId": "getProgram",
        "description": "Program (card template) with rules, basic design, tiers and rewards.\n\n**Required scope:** `programs:read`.",
        "x-scope": "programs:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Program"
          }
        ],
        "responses": {
          "200": {
            "description": "Program",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Program"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 3,
                    "name": "Stamp card",
                    "slug": "tarjeta-de-sellos",
                    "type": "stamps",
                    "type_label": "Stamp card",
                    "unit": "stamps",
                    "status": "active",
                    "description": "Collect 10 stamps and get a coffee.",
                    "terms": "One stamp per purchase over L 50.",
                    "config": {
                      "stamps_target": 10,
                      "reward_name": "Americano coffee",
                      "stamps_per_purchase": 1
                    },
                    "welcome_bonus": 1,
                    "birthday_bonus": 0,
                    "enrollment_open": true,
                    "enrollment_url": "https://app.example.com/r/cafe-aroma/tarjeta-de-sellos",
                    "design": {
                      "background_color": "#1E1B4B",
                      "foreground_color": "#FFFFFF",
                      "label_color": "#C7D2FE",
                      "logo_text": "Café Aroma",
                      "header_message": null
                    },
                    "cards_count": 248,
                    "tiers": [],
                    "rewards": [
                      {
                        "id": 7,
                        "name": "Americano coffee",
                        "description": "Medium size",
                        "cost": 10,
                        "min_tier_id": null,
                        "stock": null,
                        "max_per_customer": null,
                        "estimated_cost": 3500,
                        "is_active": true
                      }
                    ],
                    "published_at": "2026-08-01T13:00:00+00:00",
                    "created_at": "2026-07-30T18:45:00+00:00"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "patch": {
        "tags": [
          "programs"
        ],
        "summary": "Edit program",
        "operationId": "updateProgram",
        "description": "Changes the name, description, terms, open sign-up or status. Activating or pausing an archived program respects the plan's program limit, which counts active and paused programs (`plan_limit`). Issued passes are updated.\n\n**Required scope:** `programs:write`.",
        "x-scope": "programs:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Program"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Name",
                    "maxLength": 80
                  },
                  "description": {
                    "type": "string",
                    "description": "Description",
                    "maxLength": 500,
                    "nullable": true
                  },
                  "terms": {
                    "type": "string",
                    "description": "Terms and conditions",
                    "maxLength": 3000,
                    "nullable": true
                  },
                  "enrollment_open": {
                    "type": "boolean",
                    "description": "Accepts new sign-ups"
                  },
                  "status": {
                    "type": "string",
                    "description": "Status",
                    "enum": [
                      "active",
                      "paused",
                      "archived"
                    ]
                  }
                }
              },
              "example": {
                "status": "paused"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Program updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Program"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 3,
                    "name": "Stamp card",
                    "slug": "tarjeta-de-sellos",
                    "type": "stamps",
                    "type_label": "Stamp card",
                    "unit": "stamps",
                    "status": "paused",
                    "description": "Collect 10 stamps and get a coffee.",
                    "terms": "One stamp per purchase over L 50.",
                    "config": {
                      "stamps_target": 10,
                      "reward_name": "Americano coffee",
                      "stamps_per_purchase": 1
                    },
                    "welcome_bonus": 1,
                    "birthday_bonus": 0,
                    "enrollment_open": true,
                    "enrollment_url": "https://app.example.com/r/cafe-aroma/tarjeta-de-sellos",
                    "design": {
                      "background_color": "#1E1B4B",
                      "foreground_color": "#FFFFFF",
                      "label_color": "#C7D2FE",
                      "logo_text": "Café Aroma",
                      "header_message": null
                    },
                    "cards_count": 248,
                    "tiers": [],
                    "rewards": [
                      {
                        "id": 7,
                        "name": "Americano coffee",
                        "description": "Medium size",
                        "cost": 10,
                        "min_tier_id": null,
                        "stock": null,
                        "max_per_customer": null,
                        "estimated_cost": 3500,
                        "is_active": true
                      }
                    ],
                    "published_at": "2026-08-01T13:00:00+00:00",
                    "created_at": "2026-07-30T18:45:00+00:00"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/programs/{program}/enrollment-links": {
      "get": {
        "tags": [
          "programs"
        ],
        "summary": "Sign-up links",
        "operationId": "getEnrollmentLinks",
        "description": "General link and one per active branch (`b=CODE`). With `src` the source is added to measure campaigns (stored on the customer and shown in /statistics/sources).\n\n**Required scope:** `programs:read`.",
        "x-scope": "programs:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Program"
          },
          {
            "name": "src",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 40,
              "example": "instagram"
            },
            "description": "Source (letters, numbers, . _ -)"
          }
        ],
        "responses": {
          "200": {
            "description": "Links",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "enrollment_open": {
                          "type": "boolean"
                        },
                        "general": {
                          "type": "string"
                        },
                        "branches": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "branch_id": {
                                "type": "integer"
                              },
                              "code": {
                                "type": "string"
                              },
                              "name": {
                                "type": "string"
                              },
                              "url": {
                                "type": "string"
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": {
                    "enrollment_open": true,
                    "general": "https://app.example.com/r/cafe-aroma/tarjeta-de-sellos?src=instagram",
                    "branches": [
                      {
                        "branch_id": 2,
                        "code": "CENTRO",
                        "name": "Downtown Branch",
                        "url": "https://app.example.com/r/cafe-aroma/tarjeta-de-sellos?b=CENTRO&src=instagram"
                      }
                    ]
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/programs/{program}/rewards": {
      "get": {
        "tags": [
          "programs"
        ],
        "summary": "List rewards",
        "operationId": "listRewards",
        "description": "All the program's rewards (active and inactive). Stamps and points only.\n\n**Required scope:** `programs:read`.",
        "x-scope": "programs:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Program"
          }
        ],
        "responses": {
          "200": {
            "description": "Rewards",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Reward"
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": 7,
                      "name": "Americano coffee",
                      "description": "Medium size",
                      "cost": 10,
                      "min_tier_id": null,
                      "stock": null,
                      "max_per_customer": null,
                      "estimated_cost": 3500,
                      "is_active": true
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "post": {
        "tags": [
          "programs"
        ],
        "summary": "Create reward",
        "operationId": "createReward",
        "description": "Adds a redeemable reward (stamp and points programs).\n\n**Required scope:** `programs:write`.",
        "x-scope": "programs:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Program"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Name",
                    "maxLength": 80
                  },
                  "description": {
                    "type": "string",
                    "description": "Description",
                    "maxLength": 300,
                    "nullable": true
                  },
                  "cost": {
                    "type": "integer",
                    "description": "Cost in stamps or points",
                    "minimum": 1,
                    "maximum": 10000000
                  },
                  "min_tier_id": {
                    "type": "integer",
                    "description": "Minimum program tier",
                    "nullable": true
                  },
                  "stock": {
                    "type": "integer",
                    "description": "Stock (null = unlimited)",
                    "minimum": 0,
                    "nullable": true
                  },
                  "max_per_customer": {
                    "type": "integer",
                    "description": "Maximum redemptions per customer",
                    "minimum": 1,
                    "nullable": true
                  },
                  "estimated_cost": {
                    "type": "integer",
                    "description": "Cost to the business in cents",
                    "minimum": 0
                  },
                  "is_active": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "name",
                  "cost"
                ]
              },
              "example": {
                "name": "Americano coffee",
                "cost": 10,
                "estimated_cost": 3500
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Reward created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Reward"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 7,
                    "name": "Americano coffee",
                    "description": "Medium size",
                    "cost": 10,
                    "min_tier_id": null,
                    "stock": null,
                    "max_per_customer": null,
                    "estimated_cost": 3500,
                    "is_active": true
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/programs/{program}/rewards/{reward}": {
      "patch": {
        "tags": [
          "programs"
        ],
        "summary": "Edit reward",
        "operationId": "updateReward",
        "description": "Updates only the fields sent. To retire it use `is_active: false`.\n\n**Required scope:** `programs:write`.",
        "x-scope": "programs:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Program"
          },
          {
            "$ref": "#/components/parameters/RewardId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Name",
                    "maxLength": 80
                  },
                  "description": {
                    "type": "string",
                    "description": "Description",
                    "maxLength": 300,
                    "nullable": true
                  },
                  "cost": {
                    "type": "integer",
                    "description": "Cost in stamps or points",
                    "minimum": 1,
                    "maximum": 10000000
                  },
                  "min_tier_id": {
                    "type": "integer",
                    "description": "Minimum program tier",
                    "nullable": true
                  },
                  "stock": {
                    "type": "integer",
                    "description": "Stock (null = unlimited)",
                    "minimum": 0,
                    "nullable": true
                  },
                  "max_per_customer": {
                    "type": "integer",
                    "description": "Maximum redemptions per customer",
                    "minimum": 1,
                    "nullable": true
                  },
                  "estimated_cost": {
                    "type": "integer",
                    "description": "Cost to the business in cents",
                    "minimum": 0
                  },
                  "is_active": {
                    "type": "boolean"
                  }
                }
              },
              "example": {
                "cost": 12
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Reward updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Reward"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 7,
                    "name": "Americano coffee",
                    "description": "Medium size",
                    "cost": 12,
                    "min_tier_id": null,
                    "stock": null,
                    "max_per_customer": null,
                    "estimated_cost": 3500,
                    "is_active": true
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "delete": {
        "tags": [
          "programs"
        ],
        "summary": "Delete reward",
        "operationId": "deleteReward",
        "description": "Only if it was never redeemed (`reward_in_use`, 409); otherwise, deactivate it.\n\n**Required scope:** `programs:write`.",
        "x-scope": "programs:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Program"
          },
          {
            "$ref": "#/components/parameters/RewardId"
          }
        ],
        "responses": {
          "200": {
            "description": "Reward deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Deleted"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 7,
                    "deleted": true
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/programs/{program}/statistics/rewards": {
      "get": {
        "tags": [
          "statistics"
        ],
        "summary": "Statistics by reward",
        "operationId": "getRewardStatistics",
        "description": "Redemptions and reversals per reward in the period (no dates: all time), total estimated cost and active cards that can reach each reward today.\n\n**Required scope:** `statistics:read`.",
        "x-scope": "statistics:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Program"
          },
          {
            "$ref": "#/components/parameters/From"
          },
          {
            "$ref": "#/components/parameters/To"
          }
        ],
        "responses": {
          "200": {
            "description": "Statistics",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "reward_id": {
                            "type": "integer"
                          },
                          "name": {
                            "type": "string"
                          },
                          "cost": {
                            "type": "integer"
                          },
                          "is_active": {
                            "type": "boolean"
                          },
                          "redeemed": {
                            "type": "integer"
                          },
                          "reversed": {
                            "type": "integer"
                          },
                          "estimated_cost_total": {
                            "type": "integer",
                            "description": "Cents"
                          },
                          "eligible_cards": {
                            "type": "integer",
                            "description": "Active cards with enough balance today"
                          }
                        }
                      }
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "from": {
                          "type": "string",
                          "nullable": true
                        },
                        "to": {
                          "type": "string",
                          "nullable": true
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "reward_id": 7,
                      "name": "Americano coffee",
                      "cost": 10,
                      "is_active": true,
                      "redeemed": 120,
                      "reversed": 2,
                      "estimated_cost_total": 420000,
                      "eligible_cards": 35
                    }
                  ],
                  "meta": {
                    "from": null,
                    "to": null
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/programs/{program}/statistics/sources": {
      "get": {
        "tags": [
          "statistics"
        ],
        "summary": "Statistics by source",
        "operationId": "getSourceStatistics",
        "description": "Issued cards grouped by customer source (`source`: public_form, api, staff, import; `source_detail`: the `src` of the sign-up link) and sign-up branch.\n\n**Required scope:** `statistics:read`.",
        "x-scope": "statistics:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Program"
          },
          {
            "$ref": "#/components/parameters/From"
          },
          {
            "$ref": "#/components/parameters/To"
          }
        ],
        "responses": {
          "200": {
            "description": "Sources",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "source": {
                            "type": "string"
                          },
                          "source_detail": {
                            "type": "string",
                            "nullable": true
                          },
                          "branch_id": {
                            "type": "integer",
                            "nullable": true
                          },
                          "cards": {
                            "type": "integer"
                          }
                        }
                      }
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "integer"
                        },
                        "from": {
                          "type": "string",
                          "nullable": true
                        },
                        "to": {
                          "type": "string",
                          "nullable": true
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "source": "public_form",
                      "source_detail": "instagram",
                      "branch_id": 2,
                      "cards": 64
                    },
                    {
                      "source": "staff",
                      "source_detail": null,
                      "branch_id": null,
                      "cards": 12
                    }
                  ],
                  "meta": {
                    "total": 76,
                    "from": null,
                    "to": null
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/programs/{program}/tiers": {
      "get": {
        "tags": [
          "programs"
        ],
        "summary": "List tiers",
        "operationId": "listTiers",
        "description": "The program's tiers (points, cashback, discount and membership).\n\n**Required scope:** `programs:read`.",
        "x-scope": "programs:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Program"
          }
        ],
        "responses": {
          "200": {
            "description": "Tiers",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Tier"
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": 4,
                      "name": "Gold",
                      "threshold": 500000,
                      "discount_percent": 10.0,
                      "points_multiplier": 1.5,
                      "included_uses": 8,
                      "benefits": "Complimentary drink on your birthday",
                      "color": "#D4A017"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "post": {
        "tags": [
          "programs"
        ],
        "summary": "Create tier",
        "operationId": "createTier",
        "description": "Customers move up a tier with their next purchase based on accumulated spend.\n\n**Required scope:** `programs:write`.",
        "x-scope": "programs:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Program"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Name",
                    "maxLength": 60
                  },
                  "threshold": {
                    "type": "integer",
                    "description": "Accumulated spend to reach it, in cents (unique per program)",
                    "minimum": 0
                  },
                  "discount_percent": {
                    "type": "number",
                    "description": "Discount (%)",
                    "minimum": 0,
                    "maximum": 100
                  },
                  "points_multiplier": {
                    "type": "number",
                    "description": "Points multiplier",
                    "minimum": 1,
                    "maximum": 10
                  },
                  "included_uses": {
                    "type": "integer",
                    "description": "Memberships: uses per period",
                    "minimum": 0,
                    "maximum": 1000,
                    "nullable": true
                  },
                  "benefits": {
                    "type": "string",
                    "description": "Benefits (text)",
                    "maxLength": 500,
                    "nullable": true
                  },
                  "color": {
                    "type": "string",
                    "description": "Color #RRGGBB",
                    "pattern": "^#[0-9A-Fa-f]{6}$",
                    "nullable": true
                  }
                },
                "required": [
                  "name",
                  "threshold"
                ]
              },
              "example": {
                "name": "Gold",
                "threshold": 500000,
                "discount_percent": 10,
                "included_uses": 8
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Tier created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Tier"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 4,
                    "name": "Gold",
                    "threshold": 500000,
                    "discount_percent": 10.0,
                    "points_multiplier": 1.5,
                    "included_uses": 8,
                    "benefits": "Complimentary drink on your birthday",
                    "color": "#D4A017"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/programs/{program}/tiers/{tier}": {
      "patch": {
        "tags": [
          "programs"
        ],
        "summary": "Edit tier",
        "operationId": "updateTier",
        "description": "Updates only the fields sent.\n\n**Required scope:** `programs:write`.",
        "x-scope": "programs:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Program"
          },
          {
            "$ref": "#/components/parameters/Tier"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Name",
                    "maxLength": 60
                  },
                  "threshold": {
                    "type": "integer",
                    "description": "Accumulated spend to reach it, in cents (unique per program)",
                    "minimum": 0
                  },
                  "discount_percent": {
                    "type": "number",
                    "description": "Discount (%)",
                    "minimum": 0,
                    "maximum": 100
                  },
                  "points_multiplier": {
                    "type": "number",
                    "description": "Points multiplier",
                    "minimum": 1,
                    "maximum": 10
                  },
                  "included_uses": {
                    "type": "integer",
                    "description": "Memberships: uses per period",
                    "minimum": 0,
                    "maximum": 1000,
                    "nullable": true
                  },
                  "benefits": {
                    "type": "string",
                    "description": "Benefits (text)",
                    "maxLength": 500,
                    "nullable": true
                  },
                  "color": {
                    "type": "string",
                    "description": "Color #RRGGBB",
                    "pattern": "^#[0-9A-Fa-f]{6}$",
                    "nullable": true
                  }
                }
              },
              "example": {
                "name": "Gold Plus"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Tier updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Tier"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 4,
                    "name": "Gold Plus",
                    "threshold": 500000,
                    "discount_percent": 10.0,
                    "points_multiplier": 1.5,
                    "included_uses": 8,
                    "benefits": "Complimentary drink on your birthday",
                    "color": "#D4A017"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "delete": {
        "tags": [
          "programs"
        ],
        "summary": "Delete tier",
        "operationId": "deleteTier",
        "description": "Only if no card has it assigned (`tier_in_use`, 409).\n\n**Required scope:** `programs:write`.",
        "x-scope": "programs:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Program"
          },
          {
            "$ref": "#/components/parameters/Tier"
          }
        ],
        "responses": {
          "200": {
            "description": "Tier deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Deleted"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 7,
                    "deleted": true
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/purchases": {
      "post": {
        "tags": [
          "cards"
        ],
        "summary": "Record purchase",
        "operationId": "addPurchase",
        "description": "Records a purchase and credits according to the program's rules (stamps per purchase or per amount, points, cashback, tiers, happy hours). Returns the discount to apply if the program is a discount or membership program. `external_reference` prevents duplicates: the same reference returns the original operation (`replayed: true`).\n\n**Required scope:** `cards:write`.",
        "x-scope": "cards:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "card_serial",
                  "amount"
                ],
                "properties": {
                  "card_serial": {
                    "type": "string",
                    "description": "Card (QR)",
                    "minLength": 20,
                    "maxLength": 20
                  },
                  "amount": {
                    "type": "integer",
                    "description": "Purchase total in cents",
                    "minimum": 1,
                    "maximum": 100000000
                  },
                  "external_reference": {
                    "type": "string",
                    "description": "POS invoice or receipt no.",
                    "maxLength": 100
                  },
                  "items": {
                    "type": "array",
                    "maxItems": 200,
                    "description": "Optional detail for reports",
                    "items": {
                      "type": "object",
                      "required": [
                        "name",
                        "quantity",
                        "unit_price"
                      ],
                      "properties": {
                        "sku": {
                          "type": "string"
                        },
                        "name": {
                          "type": "string"
                        },
                        "category": {
                          "type": "string"
                        },
                        "quantity": {
                          "type": "integer",
                          "minimum": 1
                        },
                        "unit_price": {
                          "type": "integer",
                          "description": "Cents",
                          "minimum": 0
                        }
                      }
                    }
                  },
                  "branch_code": {
                    "type": "string",
                    "description": "Code of the branch where it happens (optional)",
                    "maxLength": 20,
                    "example": "CENTRO"
                  }
                }
              },
              "example": {
                "card_serial": "32852595C80B7B165F61",
                "amount": 30000,
                "external_reference": "FAC-000123",
                "branch_code": "CENTRO"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Already recorded (same reference)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 981,
                      "type": "earn",
                      "amount": 1,
                      "balance_after": 5,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Credit (API)",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "stamps",
                      "status": "active",
                      "balance": 5,
                      "unit": "stamps",
                      "tier_id": null,
                      "expires_at": null,
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "5 stamps"
                    },
                    "discount": 0,
                    "redemption": null,
                    "replayed": true,
                    "message": "Credited: +1 stamp. Balance: 5 stamps."
                  }
                }
              }
            }
          },
          "201": {
            "description": "Purchase recorded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 981,
                      "type": "earn",
                      "amount": 1,
                      "balance_after": 5,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": null,
                      "branch_id": 1,
                      "description": "Credit (API)",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "stamps",
                      "status": "active",
                      "balance": 5,
                      "unit": "stamps",
                      "tier_id": null,
                      "expires_at": null,
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "5 stamps"
                    },
                    "discount": 0,
                    "redemption": null,
                    "replayed": false,
                    "message": "Credited: +1 stamp. Balance: 5 stamps."
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/pushes": {
      "get": {
        "tags": [
          "pushes"
        ],
        "summary": "List sent messages",
        "operationId": "listPushes",
        "description": "Wallet channel campaigns (created through the API or from the dashboard) with their counts. Filters by program, card and status.\n\n**Required scope:** `pushes:write`.",
        "x-scope": "pushes:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "program_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Sends targeted at this program's customers"
          },
          {
            "name": "card_serial",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Sends to this card"
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "scheduled",
                "sending",
                "sent",
                "canceled"
              ]
            },
            "description": "Send status"
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PerPage"
          }
        ],
        "responses": {
          "200": {
            "description": "Sends",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Push"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PageMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": 31,
                      "name": "API: Double stamps today until 6 p.m.",
                      "title": "Today only",
                      "message": "Double stamps today until 6 p.m.",
                      "status": "sent",
                      "audience": {
                        "segments": [
                          "at_risk"
                        ]
                      },
                      "counts": {
                        "recipients": 42,
                        "sent": 39,
                        "skipped": 3,
                        "failed": 0,
                        "pending": 0
                      },
                      "created_at": "2026-10-19T15:04:05+00:00",
                      "scheduled_at": null,
                      "sent_at": "2026-10-19T15:04:06+00:00"
                    }
                  ],
                  "meta": {
                    "current_page": 1,
                    "per_page": 25,
                    "total": 1,
                    "last_page": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "post": {
        "tags": [
          "pushes"
        ],
        "summary": "Send a message to the Wallet pass",
        "operationId": "sendPush",
        "description": "Shows a message on the pass of one card, a segment or all customers with an installed pass (optionally only for one program). Creates a Wallet channel campaign visible in the dashboard. Requires the plan's **Campaigns** feature.\n\nReal limits: Apple shows it as a notification when the pass updates; Google allows up to 3 notifications per pass every 24 h; the weekly cap of marketing messages per customer is respected (skipped ones count as `skipped`). Variables: {name}, {business}, {program}, {balance}, {link}.\n\nWith `scheduled_at` (only `segment` or `all`) the send stays in `scheduled` status and goes out at that time; without it, it is sent immediately.\n\n**Required scope:** `pushes:write`.",
        "x-scope": "pushes:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "target",
                  "message"
                ],
                "properties": {
                  "target": {
                    "type": "string",
                    "description": "Target",
                    "enum": [
                      "card",
                      "segment",
                      "all"
                    ]
                  },
                  "card_serial": {
                    "type": "string",
                    "description": "Required if target=card"
                  },
                  "segment": {
                    "type": "string",
                    "description": "Required if target=segment",
                    "enum": [
                      "champions",
                      "loyal",
                      "potential",
                      "new",
                      "at_risk",
                      "lost",
                      "no_purchases"
                    ]
                  },
                  "program_id": {
                    "type": "integer",
                    "description": "Only customers with an active card in this program"
                  },
                  "title": {
                    "type": "string",
                    "description": "Header",
                    "maxLength": 60
                  },
                  "message": {
                    "type": "string",
                    "description": "Notification text",
                    "maxLength": 190
                  },
                  "name": {
                    "type": "string",
                    "description": "Internal campaign name",
                    "maxLength": 120
                  },
                  "scheduled_at": {
                    "type": "string",
                    "format": "date-time",
                    "nullable": true,
                    "description": "Schedule the send (the business's local date and time, or ISO 8601 with time zone). Must be in the future. Not allowed with target=card."
                  }
                }
              },
              "example": {
                "target": "segment",
                "segment": "at_risk",
                "title": "Today only",
                "message": "Double stamps today until 6 p.m."
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Send created: started (`sent`/`sending`) or scheduled (`scheduled`)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Push"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 31,
                    "name": "API: Double stamps today until 6 p.m.",
                    "title": "Today only",
                    "message": "Double stamps today until 6 p.m.",
                    "status": "sent",
                    "audience": {
                      "segments": [
                        "at_risk"
                      ]
                    },
                    "counts": {
                      "recipients": 42,
                      "sent": 39,
                      "skipped": 3,
                      "failed": 0,
                      "pending": 0
                    },
                    "created_at": "2026-10-19T15:04:05+00:00",
                    "scheduled_at": null,
                    "sent_at": "2026-10-19T15:04:06+00:00"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/pushes/{push}": {
      "get": {
        "tags": [
          "pushes"
        ],
        "summary": "Get send",
        "operationId": "getPush",
        "description": "Send status and recipient count (sent, skipped, failed, pending).\n\n**Required scope:** `pushes:write`.",
        "x-scope": "pushes:write",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Push"
          }
        ],
        "responses": {
          "200": {
            "description": "Send",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Push"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 31,
                    "name": "API: Double stamps today until 6 p.m.",
                    "title": "Today only",
                    "message": "Double stamps today until 6 p.m.",
                    "status": "sent",
                    "audience": {
                      "segments": [
                        "at_risk"
                      ]
                    },
                    "counts": {
                      "recipients": 42,
                      "sent": 39,
                      "skipped": 3,
                      "failed": 0,
                      "pending": 0
                    },
                    "created_at": "2026-10-19T15:04:05+00:00",
                    "scheduled_at": null,
                    "sent_at": "2026-10-19T15:04:06+00:00"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/segments": {
      "get": {
        "tags": [
          "segments"
        ],
        "summary": "List customer segments",
        "operationId": "listSegments",
        "description": "RFM segments (recency, frequency, monetary) with the number of customers from the latest calculation. Use them as the audience in POST /pushes.\n\n**Required scope:** `segments:read`.",
        "x-scope": "segments:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Segments",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Segment"
                      }
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "calculated_at": {
                          "type": "string",
                          "format": "date-time",
                          "nullable": true
                        },
                        "not_calculated": {
                          "type": "integer",
                          "description": "Customers without a segment yet"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "key": "champions",
                      "label": "Champions",
                      "customers": 18
                    },
                    {
                      "key": "loyal",
                      "label": "Loyal",
                      "customers": 64
                    },
                    {
                      "key": "at_risk",
                      "label": "At risk",
                      "customers": 23
                    }
                  ],
                  "meta": {
                    "calculated_at": "2026-10-19T08:00:00+00:00",
                    "not_calculated": 4
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/statistics/revenue": {
      "get": {
        "tags": [
          "statistics"
        ],
        "summary": "Sales and loyalty statistics",
        "operationId": "getRevenueStatistics",
        "description": "Same overview as the dashboard for a period (by default, the last 30 days), optionally by branch or program. Amounts in cents. Each metric's definition is in `meta.definitions`.\n\n**Required scope:** `statistics:read`.",
        "x-scope": "statistics:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/From"
          },
          {
            "$ref": "#/components/parameters/To"
          },
          {
            "name": "branch_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Branch"
          },
          {
            "name": "program_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Program"
          }
        ],
        "responses": {
          "200": {
            "description": "Overview",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "description": "Metrics (see meta.definitions)"
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "from": {
                          "type": "string",
                          "format": "date"
                        },
                        "to": {
                          "type": "string",
                          "format": "date"
                        },
                        "currency": {
                          "type": "string"
                        },
                        "definitions": {
                          "type": "object"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": {
                    "customers_total": 1240,
                    "new_customers": 86,
                    "cards_issued": 91,
                    "active_cards": 412,
                    "wallet_passes": {
                      "apple": 310,
                      "google": 205
                    },
                    "purchases": 1630,
                    "revenue": 48900000,
                    "avg_ticket": 30000,
                    "buyers": 702,
                    "returning": 388,
                    "frequency": 2.32,
                    "rewards_redeemed": 120,
                    "reward_cost": 420000,
                    "at_risk": 57,
                    "by_branch": [
                      {
                        "name": "Downtown Branch",
                        "purchases": 1010,
                        "revenue": 30100000
                      }
                    ],
                    "units_by_program": [
                      {
                        "id": 3,
                        "name": "Stamp card",
                        "type": "stamps",
                        "issued": 1650,
                        "redeemed": 1200,
                        "rate": 72.7
                      }
                    ]
                  },
                  "meta": {
                    "from": "2026-09-20",
                    "to": "2026-10-19",
                    "currency": "HNL",
                    "definitions": {
                      "revenue": "Sum of those purchases' amounts (before discounts)."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/subaccounts": {
      "get": {
        "tags": [
          "subaccounts"
        ],
        "summary": "List sub-accounts",
        "operationId": "listSubaccounts",
        "description": "Businesses managed by the agency that owns the key, sorted by name, with their plan and subscription status. Read-only: sub-accounts are created from the agency dashboard. A key from a business that is not an agency gets 403 (`not_agency`); another agency's sub-accounts are never visible.\n\n**Required scope:** `subaccounts:read`.",
        "x-scope": "subaccounts:read",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PerPage"
          }
        ],
        "responses": {
          "200": {
            "description": "Sub-accounts",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Subaccount"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/PageMeta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": 41,
                      "name": "Panadería La Espiga",
                      "slug": "panaderia-la-espiga",
                      "email": "hola@laespiga.example",
                      "phone": "+50422334455",
                      "country": "HN",
                      "currency": "HNL",
                      "timezone": "America/Tegucigalpa",
                      "plan": "Business",
                      "subscription_status": "active",
                      "created_at": "2026-09-15T14:30:00+00:00"
                    }
                  ],
                  "meta": {
                    "current_page": 1,
                    "per_page": 25,
                    "total": 1,
                    "last_page": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "Without the `subaccounts:read` scope (`forbidden`) or the business is not an agency (`not_agency`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": {
                    "code": "not_agency",
                    "message": "This business is not an agency: it has no sub-accounts."
                  }
                }
              }
            }
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/transactions/{transaction}/reverse": {
      "post": {
        "tags": [
          "operations"
        ],
        "summary": "Reverse operation",
        "operationId": "reverseTransaction",
        "description": "Audited compensating reversal: never deletes the original transaction. Also reverses the associated purchase or redemption. Fails if the resulting balance would be negative.\n\n**Required scope:** `transactions:reverse`.",
        "x-scope": "transactions:reverse",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Transaction"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "reason"
                ],
                "properties": {
                  "reason": {
                    "type": "string",
                    "description": "Reason",
                    "minLength": 5,
                    "maxLength": 200
                  }
                }
              },
              "example": {
                "reason": "Refund of invoice FAC-000123"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Reversal recorded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/OperationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "transaction": {
                      "id": 982,
                      "type": "reversal",
                      "amount": -1,
                      "balance_after": 4,
                      "reference": "api:2f6b1c0d9e8a7f6b5c4d3e2f1a0b9c8d7e6f5a4b",
                      "purchase_id": null,
                      "reverses_transaction_id": 981,
                      "branch_id": 1,
                      "description": "Reversal: Refund of invoice FAC-000123",
                      "created_at": "2026-10-19T15:04:05+00:00"
                    },
                    "card": {
                      "serial": "32852595C80B7B165F61",
                      "customer_id": 12,
                      "program_id": 3,
                      "program_type": "stamps",
                      "status": "active",
                      "balance": 4,
                      "unit": "stamps",
                      "tier_id": null,
                      "expires_at": null,
                      "public_url": "https://app.example.com/t/Xk3f9QnV2pLr8sTb",
                      "wallet": {
                        "apple": "issued",
                        "google": "pending"
                      },
                      "balance_display": "4 stamps"
                    },
                    "discount": 0,
                    "redemption": null,
                    "replayed": false,
                    "message": "Deducted: 1 stamp. Balance: 4 stamps."
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/webhooks": {
      "get": {
        "tags": [
          "webhooks"
        ],
        "summary": "List webhooks",
        "operationId": "listWebhooks",
        "description": "Active and inactive subscriptions (without the secret) and event catalog in `meta.events`.\n\n**Required scope:** `webhooks:manage`.",
        "x-scope": "webhooks:manage",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Webhooks",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Webhook"
                      }
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "events": {
                          "type": "object",
                          "description": "Event → description"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": 3,
                      "url": "https://pos.ejemplo.com/webhooks/fidelizacion",
                      "events": [
                        "purchase.created",
                        "reward.redeemed"
                      ],
                      "is_active": true,
                      "created_at": "2026-10-19T15:04:05+00:00"
                    }
                  ],
                  "meta": {
                    "events": {
                      "purchase.created": "Purchase recorded"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      },
      "post": {
        "tags": [
          "webhooks"
        ],
        "summary": "Subscribe a URL to events",
        "operationId": "createWebhook",
        "description": "Registers an HTTPS URL. The signing secret (`secret`) is returned **only in this response**: store it. That is why this route does not store responses for Idempotency-Key; the same URL cannot be registered twice (409 `webhook_exists`).\n\nEach delivery carries `X-Webhook-Signature: t=<unix>,v1=<hex>` with `v1 = HMAC-SHA256(secret, t + \".\" + body)`.\n\n**Required scope:** `webhooks:manage`.",
        "x-scope": "webhooks:manage",
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url",
                  "events"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "HTTPS URL",
                    "format": "uri",
                    "maxLength": 500
                  },
                  "events": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "string",
                      "enum": [
                        "customer.created",
                        "card.issued",
                        "transaction.created",
                        "transaction.reversed",
                        "reward.redeemed",
                        "purchase.created"
                      ]
                    }
                  }
                }
              },
              "example": {
                "url": "https://pos.ejemplo.com/webhooks/fidelizacion",
                "events": [
                  "purchase.created",
                  "reward.redeemed"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Webhook created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/Webhook"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "secret": {
                              "type": "string",
                              "description": "Signing secret (shown once)"
                            }
                          }
                        }
                      ]
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 3,
                    "url": "https://pos.ejemplo.com/webhooks/fidelizacion",
                    "events": [
                      "purchase.created",
                      "reward.redeemed"
                    ],
                    "is_active": true,
                    "created_at": "2026-10-19T15:04:05+00:00",
                    "secret": "whsec_9fK2mQ7xL4pR8tV1nB6cD3eG5hJ0kW2yZ4aS7uX9"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/webhooks/{webhook}": {
      "delete": {
        "tags": [
          "webhooks"
        ],
        "summary": "Delete webhook",
        "operationId": "deleteWebhook",
        "description": "Deletes the subscription and its delivery log.\n\n**Required scope:** `webhooks:manage`.",
        "x-scope": "webhooks:manage",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/Webhook"
          }
        ],
        "responses": {
          "200": {
            "description": "Webhook deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Deleted"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": 7,
                    "deleted": true
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "`fk_…` API key (Dashboard → Developers). Shown only once, when it is created."
      }
    },
    "parameters": {
      "Serial": {
        "name": "serial",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "pattern": "^[0-9A-Fa-f]{20}$"
        },
        "description": "Card number (the same as the QR)",
        "example": "32852595C80B7B165F61"
      },
      "Customer": {
        "name": "customer",
        "in": "path",
        "required": true,
        "schema": {
          "type": "integer"
        },
        "description": "Customer ID"
      },
      "Program": {
        "name": "program",
        "in": "path",
        "required": true,
        "schema": {
          "type": "integer"
        },
        "description": "Program ID"
      },
      "Tier": {
        "name": "tier",
        "in": "path",
        "required": true,
        "schema": {
          "type": "integer"
        },
        "description": "Tier ID (must belong to the program)"
      },
      "RewardId": {
        "name": "reward",
        "in": "path",
        "required": true,
        "schema": {
          "type": "integer"
        },
        "description": "Reward ID (must belong to the program)"
      },
      "Transaction": {
        "name": "transaction",
        "in": "path",
        "required": true,
        "schema": {
          "type": "integer"
        },
        "description": "Transaction ID"
      },
      "Push": {
        "name": "push",
        "in": "path",
        "required": true,
        "schema": {
          "type": "integer"
        },
        "description": "Send ID"
      },
      "Webhook": {
        "name": "webhook",
        "in": "path",
        "required": true,
        "schema": {
          "type": "integer"
        },
        "description": "Webhook ID"
      },
      "Location": {
        "name": "location",
        "in": "path",
        "required": true,
        "schema": {
          "type": "integer"
        },
        "description": "Branch ID"
      },
      "Manager": {
        "name": "manager",
        "in": "path",
        "required": true,
        "schema": {
          "type": "integer"
        },
        "description": "User ID"
      },
      "Coupon": {
        "name": "coupon",
        "in": "path",
        "required": true,
        "schema": {
          "type": "integer"
        },
        "description": "Coupon ID"
      },
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "schema": {
          "type": "string",
          "maxLength": 100
        },
        "description": "Unique key per operation (e.g. a UUID). Repeating the request returns the original response with `Idempotent-Replayed: true`; another request with the same key → 409. Kept for 24 h."
      },
      "Page": {
        "name": "page",
        "in": "query",
        "required": false,
        "schema": {
          "type": "integer",
          "minimum": 1
        },
        "description": "Page (starting at 1)"
      },
      "PerPage": {
        "name": "per_page",
        "in": "query",
        "required": false,
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100,
          "default": 25
        },
        "description": "Items per page"
      },
      "From": {
        "name": "from",
        "in": "query",
        "required": false,
        "schema": {
          "type": "string",
          "format": "date"
        },
        "description": "From (the business's local date, YYYY-MM-DD)"
      },
      "To": {
        "name": "to",
        "in": "query",
        "required": false,
        "schema": {
          "type": "string",
          "format": "date"
        },
        "description": "To, inclusive (the business's local date)"
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Key missing, invalid, expired or revoked",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "unauthenticated",
                "message": "Invalid, expired or revoked API key."
              }
            }
          }
        }
      },
      "Forbidden": {
        "description": "The key does not have the required scope, the plan does not include the feature or a plan limit was reached (`forbidden`, `plan_feature_missing`, `plan_limit`)",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "forbidden",
                "message": "The key does not have the cards:write scope."
              }
            }
          }
        }
      },
      "NotFound": {
        "description": "Does not exist or belongs to another business",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string"
                }
              }
            },
            "example": {
              "message": "Not Found"
            }
          }
        }
      },
      "Unprocessable": {
        "description": "Validation (`errors` per field) or business rule (`error.code`: insufficient_balance, card_inactive, operation_not_supported…)",
        "content": {
          "application/json": {
            "schema": {
              "oneOf": [
                {
                  "$ref": "#/components/schemas/ValidationError"
                },
                {
                  "$ref": "#/components/schemas/Error"
                }
              ]
            },
            "examples": {
              "validacion": {
                "summary": "Validation",
                "value": {
                  "message": "Amount is required.",
                  "errors": {
                    "amount": [
                      "Amount is required."
                    ]
                  }
                }
              },
              "negocio": {
                "summary": "Business rule",
                "value": {
                  "error": {
                    "code": "insufficient_balance",
                    "message": "Insufficient balance. Available: 3 stamps."
                  }
                }
              }
            }
          }
        }
      },
      "Conflict": {
        "description": "Conflict: Idempotency-Key reused with a different request, duplicate reference or resource in use",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "idempotency_conflict",
                "message": "The Idempotency-Key was already used with a different request."
              }
            }
          }
        }
      },
      "PaymentRequired": {
        "description": "The business's subscription is not active (writes only)",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "subscription_inactive",
                "message": "The subscription is not active."
              }
            }
          }
        }
      },
      "TooManyRequests": {
        "description": "More than 120 requests per minute with the same key"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "description": "Stable code to program against",
                "example": "insufficient_balance"
              },
              "message": {
                "type": "string",
                "description": "Human-readable message to display"
              }
            }
          }
        }
      },
      "ValidationError": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "description": "Overview"
          },
          "errors": {
            "type": "object",
            "description": "Field → list of messages",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      },
      "PageMeta": {
        "type": "object",
        "properties": {
          "current_page": {
            "type": "integer",
            "description": "Current page"
          },
          "per_page": {
            "type": "integer",
            "description": "Items per page (max. 100)"
          },
          "total": {
            "type": "integer",
            "description": "Total items"
          },
          "last_page": {
            "type": "integer",
            "description": "Last page"
          }
        }
      },
      "Deleted": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "Identifier"
          },
          "deleted": {
            "type": "boolean",
            "description": "Always true"
          }
        }
      },
      "Customer": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "Customer identifier"
          },
          "name": {
            "type": "string",
            "description": "Full name"
          },
          "phone": {
            "type": "string",
            "description": "Phone in E.164 format",
            "nullable": true,
            "example": "+50499887766"
          },
          "email": {
            "type": "string",
            "description": "Email",
            "nullable": true
          },
          "birthday": {
            "type": "string",
            "description": "Date of birth",
            "format": "date",
            "nullable": true
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Free-form tags"
          },
          "rfm_segment": {
            "type": "string",
            "description": "RFM segment from the latest calculation",
            "nullable": true,
            "enum": [
              "champions",
              "loyal",
              "potential",
              "new",
              "at_risk",
              "lost",
              "no_purchases"
            ]
          },
          "consents": {
            "type": "object",
            "properties": {
              "marketing_email": {
                "type": "boolean"
              },
              "marketing_whatsapp": {
                "type": "boolean"
              }
            }
          },
          "created_at": {
            "type": "string",
            "description": "Signed up",
            "format": "date-time"
          },
          "cards": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Card"
            },
            "description": "Only in GET /customers/{customer}"
          }
        }
      },
      "Card": {
        "type": "object",
        "properties": {
          "serial": {
            "type": "string",
            "description": "Card number (the same as the QR): 20 hexadecimal characters",
            "example": "32852595C80B7B165F61"
          },
          "customer_id": {
            "type": "integer",
            "description": "Owner customer"
          },
          "program_id": {
            "type": "integer",
            "description": "The card's program (template)"
          },
          "program_type": {
            "type": "string",
            "description": "Program type",
            "enum": [
              "stamps",
              "points",
              "cashback",
              "discount",
              "coupon",
              "gift_card",
              "membership",
              "visits"
            ]
          },
          "status": {
            "type": "string",
            "description": "Status: active, suspended, revoked (final), expired, used (used coupon, final)",
            "enum": [
              "active",
              "suspended",
              "revoked",
              "expired",
              "used"
            ]
          },
          "balance": {
            "type": "integer",
            "description": "Balance in the program's unit: stamps, points, uses, visits or cents"
          },
          "unit": {
            "type": "string",
            "description": "Balance unit",
            "enum": [
              "stamps",
              "points",
              "money",
              "uses",
              "visits",
              "none"
            ]
          },
          "tier_id": {
            "type": "integer",
            "description": "Current tier",
            "nullable": true
          },
          "expires_at": {
            "type": "string",
            "description": "Expiration",
            "format": "date-time",
            "nullable": true
          },
          "public_url": {
            "type": "string",
            "description": "The card's secret link for the customer (from there they add it to Wallet)"
          },
          "wallet": {
            "type": "object",
            "description": "Pass status by platform",
            "nullable": true,
            "additionalProperties": {
              "type": "string"
            }
          },
          "balance_display": {
            "type": "string",
            "description": "Formatted balance",
            "example": "120 pts"
          }
        }
      },
      "Transaction": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "Transaction identifier"
          },
          "type": {
            "type": "string",
            "description": "earn=earning, bonus=bonus, redeem=redemption, credit=top-up, debit=usage, reversal=reversal, expiration=expiration, adjustment=adjustment",
            "enum": [
              "earn",
              "bonus",
              "redeem",
              "credit",
              "debit",
              "reversal",
              "expiration",
              "adjustment"
            ]
          },
          "amount": {
            "type": "integer",
            "description": "Balance change (negative when subtracting)"
          },
          "balance_after": {
            "type": "integer",
            "description": "Resulting balance"
          },
          "reference": {
            "type": "string",
            "description": "Unique reference (ledger idempotency)"
          },
          "purchase_id": {
            "type": "integer",
            "description": "Associated purchase",
            "nullable": true
          },
          "reverses_transaction_id": {
            "type": "integer",
            "description": "Reversed transaction",
            "nullable": true
          },
          "branch_id": {
            "type": "integer",
            "description": "Branch",
            "nullable": true
          },
          "description": {
            "type": "string",
            "description": "Description",
            "nullable": true
          },
          "created_at": {
            "type": "string",
            "description": "Date",
            "format": "date-time"
          }
        }
      },
      "Operation": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Transaction"
          },
          {
            "type": "object",
            "properties": {
              "card_serial": {
                "type": "string",
                "description": "Card"
              },
              "program_id": {
                "type": "integer",
                "description": "Program"
              },
              "customer_id": {
                "type": "integer",
                "description": "Customer"
              }
            }
          }
        ]
      },
      "OperationResult": {
        "type": "object",
        "properties": {
          "transaction": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Transaction"
              }
            ],
            "nullable": true
          },
          "card": {
            "$ref": "#/components/schemas/Card"
          },
          "discount": {
            "type": "integer",
            "description": "Discount to apply at checkout (cents)"
          },
          "redemption": {
            "type": "object",
            "properties": {
              "id": {
                "type": "integer"
              },
              "code": {
                "type": "string",
                "description": "Redemption code for the cashier"
              },
              "reward_id": {
                "type": "integer"
              }
            },
            "nullable": true
          },
          "replayed": {
            "type": "boolean",
            "description": "true if the operation already existed (same reference): it was not applied again"
          },
          "message": {
            "type": "string",
            "description": "Summary to show the cashier"
          }
        }
      },
      "ProgramSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "description": "Type",
            "enum": [
              "stamps",
              "points",
              "cashback",
              "discount",
              "coupon",
              "gift_card",
              "membership",
              "visits"
            ]
          },
          "unit": {
            "type": "string"
          },
          "config": {
            "type": "object",
            "description": "Program type rules"
          },
          "rewards": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "integer"
                },
                "name": {
                  "type": "string"
                },
                "cost": {
                  "type": "integer"
                },
                "stock": {
                  "type": "integer",
                  "nullable": true
                }
              }
            }
          },
          "enrollment_url": {
            "type": "string",
            "description": "Public sign-up link"
          }
        }
      },
      "Program": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "description": "Program type",
            "enum": [
              "stamps",
              "points",
              "cashback",
              "discount",
              "coupon",
              "gift_card",
              "membership",
              "visits"
            ]
          },
          "type_label": {
            "type": "string"
          },
          "unit": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "description": "Status",
            "enum": [
              "draft",
              "active",
              "paused",
              "archived"
            ]
          },
          "description": {
            "type": "string",
            "nullable": true
          },
          "terms": {
            "type": "string",
            "nullable": true
          },
          "config": {
            "type": "object",
            "description": "Type-specific rules (stamps for a reward, points per lempira, etc.)"
          },
          "welcome_bonus": {
            "type": "integer",
            "description": "Gift units on sign-up"
          },
          "birthday_bonus": {
            "type": "integer",
            "description": "Birthday gift units"
          },
          "enrollment_open": {
            "type": "boolean"
          },
          "enrollment_url": {
            "type": "string"
          },
          "design": {
            "type": "object",
            "properties": {
              "background_color": {
                "type": "string"
              },
              "foreground_color": {
                "type": "string"
              },
              "label_color": {
                "type": "string"
              },
              "logo_text": {
                "type": "string",
                "nullable": true
              },
              "header_message": {
                "type": "string",
                "nullable": true
              }
            }
          },
          "cards_count": {
            "type": "integer",
            "description": "Cards issued",
            "nullable": true
          },
          "tiers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Tier"
            }
          },
          "rewards": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Reward"
            }
          },
          "published_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Tier": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "threshold": {
            "type": "integer",
            "description": "Accumulated spend to reach it (cents)"
          },
          "discount_percent": {
            "type": "number",
            "description": "Tier discount (%)"
          },
          "points_multiplier": {
            "type": "number",
            "description": "Points multiplier"
          },
          "included_uses": {
            "type": "integer",
            "description": "Memberships: uses included per period",
            "nullable": true
          },
          "benefits": {
            "type": "string",
            "nullable": true
          },
          "color": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "Reward": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string",
            "nullable": true
          },
          "cost": {
            "type": "integer",
            "description": "Cost in the program's unit (stamps or points)"
          },
          "min_tier_id": {
            "type": "integer",
            "description": "Minimum tier",
            "nullable": true
          },
          "stock": {
            "type": "integer",
            "description": "Stock (null = unlimited)",
            "nullable": true
          },
          "max_per_customer": {
            "type": "integer",
            "nullable": true
          },
          "estimated_cost": {
            "type": "integer",
            "description": "Cost to the business (cents), for reports"
          },
          "is_active": {
            "type": "boolean"
          }
        }
      },
      "Location": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "code": {
            "type": "string",
            "description": "Short code (alphanumeric, uppercase)"
          },
          "address": {
            "type": "string",
            "nullable": true
          },
          "city": {
            "type": "string",
            "nullable": true
          },
          "phone": {
            "type": "string",
            "nullable": true
          },
          "latitude": {
            "type": "number",
            "nullable": true
          },
          "longitude": {
            "type": "number",
            "nullable": true
          },
          "is_active": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Manager": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "role": {
            "type": "string",
            "description": "owner, admin, manager or cashier (the API only assigns manager or cashier)"
          },
          "role_label": {
            "type": "string"
          },
          "is_active": {
            "type": "boolean"
          },
          "branch_ids": {
            "type": "array",
            "items": {
              "type": "integer"
            },
            "description": "Assigned branches (roles that cover every branch ignore them)"
          },
          "last_login_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Coupon": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "discount_type": {
            "type": "string",
            "description": "percent, fixed (fixed amount) or product (free product)",
            "enum": [
              "percent",
              "fixed",
              "product"
            ]
          },
          "value": {
            "type": "integer",
            "description": "percent: percentage ×100 (1500 = 15%); fixed: cents; product: 0"
          },
          "value_display": {
            "type": "string"
          },
          "min_purchase": {
            "type": "integer",
            "description": "Minimum purchase (cents)"
          },
          "max_uses": {
            "type": "integer",
            "description": "Total uses (null = unlimited)",
            "nullable": true
          },
          "max_uses_per_customer": {
            "type": "integer"
          },
          "uses_count": {
            "type": "integer"
          },
          "customer_id": {
            "type": "integer",
            "description": "Personal coupon",
            "nullable": true
          },
          "starts_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Valid from (UTC)"
          },
          "ends_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Valid until (UTC); a YYYY-MM-DD date is valid until 23:59:59 local time"
          },
          "is_active": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Push": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "title": {
            "type": "string",
            "nullable": true
          },
          "message": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "description": "draft, scheduled, sending, sent or canceled",
            "enum": [
              "draft",
              "scheduled",
              "sending",
              "sent",
              "canceled"
            ]
          },
          "audience": {
            "type": "object",
            "description": "Filters used: segments, loyalty_program_id, card_serial"
          },
          "counts": {
            "type": "object",
            "properties": {
              "recipients": {
                "type": "integer"
              },
              "sent": {
                "type": "integer"
              },
              "skipped": {
                "type": "integer",
                "description": "Skipped (no installed pass, weekly message cap…)"
              },
              "failed": {
                "type": "integer"
              },
              "pending": {
                "type": "integer"
              }
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "scheduled_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Scheduled time (UTC) if it was scheduled"
          },
          "sent_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "Webhook": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "url": {
            "type": "string"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "customer.created",
                "card.issued",
                "transaction.created",
                "transaction.reversed",
                "reward.redeemed",
                "purchase.created"
              ]
            }
          },
          "is_active": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Segment": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "description": "Segment key",
            "enum": [
              "champions",
              "loyal",
              "potential",
              "new",
              "at_risk",
              "lost",
              "no_purchases"
            ]
          },
          "label": {
            "type": "string"
          },
          "customers": {
            "type": "integer"
          }
        }
      },
      "Automation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "trigger": {
            "type": "string",
            "description": "Trigger",
            "enum": [
              "enrolled",
              "earned",
              "reward_available",
              "birthday",
              "inactive",
              "points_expiring",
              "tier_upgraded",
              "referral_rewarded"
            ]
          },
          "trigger_label": {
            "type": "string"
          },
          "trigger_config": {
            "type": "object",
            "nullable": true,
            "description": "Trigger parameters, e.g. `{\"days\": 30}` for inactive and points_expiring"
          },
          "action": {
            "type": "string",
            "enum": [
              "send_message",
              "grant_bonus"
            ]
          },
          "action_label": {
            "type": "string"
          },
          "channel": {
            "type": "string",
            "nullable": true,
            "description": "Message channel (wallet, email or whatsapp); null if the action is a bonus"
          },
          "is_active": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Subaccount": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "nullable": true
          },
          "phone": {
            "type": "string",
            "nullable": true
          },
          "country": {
            "type": "string",
            "description": "2-letter ISO code"
          },
          "currency": {
            "type": "string"
          },
          "timezone": {
            "type": "string"
          },
          "plan": {
            "type": "string",
            "nullable": true,
            "description": "Sub-account plan name"
          },
          "subscription_status": {
            "type": "string",
            "nullable": true,
            "enum": [
              "trial",
              "active",
              "suspended",
              "canceled"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  }
}
