> ## Documentation Index
> Fetch the complete documentation index at: https://docs-pos.solya.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Apply an authorised discount to a whole ticket

> Applies a manager-authorised reduction to the WHOLE ticket and persists the traced record. This is the deliberate, one-off human decision — reach for it only when no automatic promotion or presented coupon covers the case, and never to reproduce an offer that should be a rule (`POST /v1/promotions`) or a code (`POST /v1/coupons`). You supply the `id`, which is the IDEMPOTENCY ANCHOR: a second post of the same id is rejected 409 rather than doubling the reduction, so generate one id per intended discount and retry with the same one. `reason` is a closed vocabulary (`manual_markdown`, `promotional`, `loyalty_reward`, `damaged_goods`, `manager_goodwill`) and `note` carries up to 280 characters of free-text justification. Express the reduction either as `basis:'percent'` with `percentBps` in BASIS POINTS (1000 = 10%) or `basis:'amount'` with `amountCents` in integer CENTS; the `cart` snapshot you pass is what the gross is computed from, and it is read, never mutated. The default policy caps a discount at 50% and at 50.00 € and refuses a reduction larger than the base — breaching any of those gives 422, which means 'the request was well-formed but too deep', not a malformed body. Applying a discount records it; it does not settle a sale, which stays `POST /v1/checkout/finalize`.



## OpenAPI

````yaml /openapi.json post /v1/discounts/ticket
openapi: 3.0.3
info:
  title: Solya POS API
  version: 1.0.0
  description: >-
    The Solya POS backend HTTP surface. Every documented operation is
    agent-ready: it carries an `operationId`, an agent-facing `description`, the
    `pos.*` scopes it enforces (`x-required-permissions`) and an `x-agent-tier`.
    Success responses return the payload as raw JSON; failures return the
    `ErrorResponse` envelope (`{ error: { code, message, statusCode } }`).
servers:
  - url: /
    description: The backend, relative to its deployed origin.
security: []
paths:
  /v1/discounts/ticket:
    post:
      tags:
        - Promotions
      summary: Apply an authorised discount to a whole ticket
      description: >-
        Applies a manager-authorised reduction to the WHOLE ticket and persists
        the traced record. This is the deliberate, one-off human decision —
        reach for it only when no automatic promotion or presented coupon covers
        the case, and never to reproduce an offer that should be a rule (`POST
        /v1/promotions`) or a code (`POST /v1/coupons`). You supply the `id`,
        which is the IDEMPOTENCY ANCHOR: a second post of the same id is
        rejected 409 rather than doubling the reduction, so generate one id per
        intended discount and retry with the same one. `reason` is a closed
        vocabulary (`manual_markdown`, `promotional`, `loyalty_reward`,
        `damaged_goods`, `manager_goodwill`) and `note` carries up to 280
        characters of free-text justification. Express the reduction either as
        `basis:'percent'` with `percentBps` in BASIS POINTS (1000 = 10%) or
        `basis:'amount'` with `amountCents` in integer CENTS; the `cart`
        snapshot you pass is what the gross is computed from, and it is read,
        never mutated. The default policy caps a discount at 50% and at 50.00 €
        and refuses a reduction larger than the base — breaching any of those
        gives 422, which means 'the request was well-formed but too deep', not a
        malformed body. Applying a discount records it; it does not settle a
        sale, which stays `POST /v1/checkout/finalize`.
      operationId: applyTicketDiscount
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - type: object
                  properties:
                    id:
                      type: string
                      minLength: 1
                    reason:
                      type: string
                      enum:
                        - manual_markdown
                        - promotional
                        - loyalty_reward
                        - damaged_goods
                        - manager_goodwill
                    note:
                      type: string
                      maxLength: 280
                    cart:
                      type: object
                      properties:
                        lines:
                          type: array
                          items:
                            type: object
                            properties:
                              id:
                                type: string
                                minLength: 1
                              skuId:
                                nullable: true
                                type: string
                                pattern: ^[0-9a-f]{64}$
                              quantity:
                                type: integer
                                minimum: 0
                                exclusiveMinimum: true
                                maximum: 9007199254740991
                              unitPrice:
                                type: integer
                                minimum: 0
                                maximum: 9007199254740991
                              vatRate:
                                type: number
                                minimum: 0
                                maximum: 100
                              free:
                                type: boolean
                            required:
                              - id
                              - skuId
                              - quantity
                              - unitPrice
                              - vatRate
                              - free
                        freeLineSequence:
                          type: integer
                          minimum: 0
                          maximum: 9007199254740991
                      required:
                        - lines
                        - freeLineSequence
                    basis:
                      type: string
                      enum:
                        - percent
                    percentBps:
                      type: integer
                      minimum: 1
                      maximum: 10000
                  required:
                    - id
                    - reason
                    - cart
                    - basis
                    - percentBps
                - type: object
                  properties:
                    id:
                      type: string
                      minLength: 1
                    reason:
                      type: string
                      enum:
                        - manual_markdown
                        - promotional
                        - loyalty_reward
                        - damaged_goods
                        - manager_goodwill
                    note:
                      type: string
                      maxLength: 280
                    cart:
                      type: object
                      properties:
                        lines:
                          type: array
                          items:
                            type: object
                            properties:
                              id:
                                type: string
                                minLength: 1
                              skuId:
                                nullable: true
                                type: string
                                pattern: ^[0-9a-f]{64}$
                              quantity:
                                type: integer
                                minimum: 0
                                exclusiveMinimum: true
                                maximum: 9007199254740991
                              unitPrice:
                                type: integer
                                minimum: 0
                                maximum: 9007199254740991
                              vatRate:
                                type: number
                                minimum: 0
                                maximum: 100
                              free:
                                type: boolean
                            required:
                              - id
                              - skuId
                              - quantity
                              - unitPrice
                              - vatRate
                              - free
                        freeLineSequence:
                          type: integer
                          minimum: 0
                          maximum: 9007199254740991
                      required:
                        - lines
                        - freeLineSequence
                    basis:
                      type: string
                      enum:
                        - amount
                    amountCents:
                      type: integer
                      minimum: 0
                      exclusiveMinimum: true
                      maximum: 9007199254740991
                  required:
                    - id
                    - reason
                    - cart
                    - basis
                    - amountCents
              example:
                id: disc-2026-04-17-0142
                reason: manual_markdown
                note: Damaged packaging on the display unit
                cart:
                  lines:
                    - id: line-1
                      skuId: null
                      quantity: 2
                      unitPrice: 1990
                      vatRate: 20
                      free: false
                  freeLineSequence: 0
                basis: percent
                percentBps: 1000
      responses:
        '201':
          description: The persisted discount record, with the valued signed reduction.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  scope:
                    type: string
                    enum:
                      - line
                      - ticket
                  lineId:
                    nullable: true
                    type: string
                  basis:
                    type: string
                    enum:
                      - percent
                      - amount
                  baseCents:
                    type: integer
                    minimum: -9007199254740991
                    maximum: 9007199254740991
                  amountCents:
                    type: integer
                    minimum: -9007199254740991
                    maximum: 9007199254740991
                  effectiveBps:
                    type: integer
                    minimum: -9007199254740991
                    maximum: 9007199254740991
                  reason:
                    type: string
                    enum:
                      - manual_markdown
                      - promotional
                      - loyalty_reward
                      - damaged_goods
                      - manager_goodwill
                  note:
                    type: string
                  actorId:
                    type: string
                  at:
                    type: string
                required:
                  - id
                  - scope
                  - lineId
                  - basis
                  - baseCents
                  - amountCents
                  - effectiveBps
                  - reason
                  - actorId
                  - at
                additionalProperties: false
                description: >-
                  The persisted discount record, with the valued signed
                  reduction.
                example:
                  id: disc-2026-04-17-0142
                  scope: ticket
                  lineId: null
                  basis: percent
                  baseCents: 3980
                  amountCents: -398
                  effectiveBps: 1000
                  reason: manual_markdown
                  note: Damaged packaging on the display unit
                  actorId: usr-manager-3
                  at: '2026-04-17T14:32:05.000Z'
        '400':
          description: >-
            The request failed schema validation; `error.fieldErrors` lists the
            fields.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationErrorResponse'
        '401':
          description: No valid credential was presented — send a bearer token.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: The actor is authenticated but lacks the required `pos.*` scope.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '409':
          description: >-
            The request conflicts with current state (duplicate id or stale
            version).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: The request is well-formed but violates a domain rule.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: An unexpected server error — safe to retry idempotent requests.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - bearerAuth: []
components:
  schemas:
    ValidationErrorResponse:
      type: object
      required:
        - error
      additionalProperties: false
      description: >-
        A `VALIDATION_FAILED` envelope carrying the offending fields in
        `fieldErrors`.
      properties:
        error:
          type: object
          required:
            - code
            - message
            - statusCode
          additionalProperties: false
          properties:
            code:
              type: string
              enum:
                - VALIDATION_FAILED
            message:
              type: string
            statusCode:
              type: integer
            fieldErrors:
              type: array
              description: >-
                One entry per rejected field: the field path and why it was
                rejected.
              items:
                type: object
                required:
                  - field
                  - message
                additionalProperties: false
                properties:
                  field:
                    type: string
                    description: Dot-path of the offending field.
                  message:
                    type: string
                    description: Why the field was rejected.
    ErrorResponse:
      type: object
      required:
        - error
      additionalProperties: false
      description: The uniform failure envelope every non-2xx response returns.
      properties:
        error:
          type: object
          required:
            - code
            - message
            - statusCode
          additionalProperties: false
          properties:
            code:
              type: string
              enum:
                - VALIDATION_FAILED
                - UNAUTHORIZED
                - FORBIDDEN
                - NOT_FOUND
                - CONFLICT
                - BUSINESS_RULE_VIOLATION
                - INTERNAL_ERROR
              description: >-
                Machine-readable kernel `ResultCode` — branch on this, not on
                `message`.
            message:
              type: string
              description: >-
                Human-readable explanation. Safe to surface; never leaks server
                internals.
            statusCode:
              type: integer
              description: >-
                The HTTP status, mirrored into the body so a client need not
                read headers.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        `Authorization: Bearer <token>`. Accepts EITHER a Keycloak access token
        (scopes-in-token) OR an opaque POS session token; both resolve to the
        same `pos.*` scope vocabulary the route guards enforce.

````