openapi: "3.0.3"
info:
  title: AQUA Pay API
  version: "1.0.0"
  description: |
    Bitcoin payment API — Lightning, Liquid and Bitcoin on-chain. Payments go straight to your
    self-custody AQUA wallet — no KYC, no chargebacks, no middleman. Bitcoin on-chain is paid
    directly to the Bitcoin account of your connected wallet, with no swap; a store switches it
    on in Settings and chooses how many confirmations a payment needs.

    **Getting started:** sign up at https://pay.aqua.net/account with an email code and create a
    store; its secret API key is shown once. Then connect a wallet (the dashboard's AQUA QR, or
    `POST /api/v1/connect/descriptor`) and create payments.

    **Not available during the launch:** the product catalogue (`/api/v1/products` answers
    410 `service_retired`), campaigns (a link of kind `campaign` is 400 `campaign_retired`) and
    AI agent sign-up by API.

    **Plan gating:** none while AQUA Pay is free during the private launch — every account has full
    REST API access with a secret key (`ak_live_...`). Paid plans start later, on a date to be
    announced; the planned plans and their limits are at https://pay.aqua.net/pricing and
    https://pay.aqua.net/docs#plans. Once they start, secret-key calls on the Starter plan answer
    403 `pro_plan_required`; publishable keys (`ak_pub_...`) always work. A feature the
    account's plan does not include (a `redirect_url`, for one) is then refused with 403 and
    `code: feature_not_in_plan`, naming `feature`, `tier` and `required_tier`. When a plan and
    its 4-day grace period have ended, or a new account's free trial is used up, new payments
    answer 402 `payments_paused`; during the grace period and while paused, creating or editing
    payment links and POS terminals answers 402 `store_frozen`.

    **Limits today (private launch):** 10 stores per account and 500 active items per account.
    All limits: https://pay.aqua.net/docs#rate-limits

    **Base URL:** `https://pay.aqua.net`

    **Supported currencies:** EUR, USD, GBP, CAD, AUD, JPY, CHF, DKK, BRL, SEK, NOK, PLN, CZK, HUF, RON, TRY, MXN, CLP, COP, ARS, NZD, SGD, HKD, KRW, INR, TWD, THB, IDR, ILS, AED, SAR, ZAR, HNL, GTQ, CRC, PEN, UYU, DOP, PYG, NGN, KES, GHS, UGX, TZS, XOF, XAF, PHP, VND, PKR, MYR, KZT, UAH, GEL

    **Payment bounds:** at least 1000 sats across all channels (smaller amounts are refused, never
    rounded up), and at most Indra's current maximum for a single payment. Refunds are in the asset
    paid; on Lightning up to Indra's current refund maximum, on Liquid with no maximum.

    **Not in this spec:** listing, editing and archiving payment links, issuing credit notes and
    replacement invoices, and invoice settings take a dashboard session only.

servers:
  - url: https://pay.aqua.net

components:
  securitySchemes:
    SecretKey:
      type: http
      scheme: bearer
      description: Secret API key (`ak_live_...`) — merchant backend calls only
    PublishableKey:
      type: http
      scheme: bearer
      description: Publishable key (`ak_pub_...`) — safe to use in browser JS SDK

  schemas:
    Error:
      type: object
      properties:
        error:
          type: string
      required: [error]

    Payment:
      type: object
      properties:
        payment_id:
          type: string
          example: pmt_abc123
        status:
          type: string
          enum: [pending, paid, expired]
          description: "`pending` until settlement. `paid` when the Lightning payment's L-BTC lockup is seen or the Liquid payment (L-BTC or USDT) confirms (1 Liquid block). `expired` when the invoice expires or fails, or 10 minutes after creation for a payment without Lightning — it may reopen to `pending` within 24 hours of creation if the exact L-BTC or USDT amount arrives late, so treat a later `paid` as paid."
        amount_fiat:
          type: number
          description: Amount in fiat currency
          example: 25.00
        currency:
          type: string
          example: EUR
        amount_sats:
          type: integer
          description: Order amount in satoshis (fiat converted at current BTC rate)
          example: 12500
        invoice_sats:
          type: integer
          nullable: true
          description: |
            Null when the payment has no Lightning (above Indra's current maximum).
            Amount the buyer must pay via Lightning (satoshis) — the amount in the invoice.
            Equal to `amount_sats`: an order below the minimum payment is refused, not padded.
            Always use this value when displaying the Lightning invoice amount.
          example: 12500
        methods:
          type: array
          items:
            type: string
            enum: [lightning, liquid, bitcoin, usdt]
          description: |
            Payment methods available for this payment, exactly what it takes: `lightning` up to Indra's
            current maximum; `liquid` (L-BTC direct) up to 10 000 000 sats; `bitcoin` when the store has
            Bitcoin on-chain switched on and the amount is between 20 000 and 10 000 000 sats; `usdt` when
            the store has USDT on Liquid switched on (up to 10 000 USDT).
          example: ["lightning", "liquid"]
        lightning_invoice:
          type: string
          nullable: true
          description: Null above Indra's current Lightning maximum — the payment is then paid directly. BOLT11 invoice. Render as a QR code (bare string — no `lightning:` prefix). Use as an href with the `lightning:` scheme for tap-to-pay links.
          example: lnbc125u1p...
        liquid_address:
          type: string
          description: |
            Confidential Liquid address — for L-BTC, and for USDT when the payment offers it. For the QR code
            use a `liquidnetwork:` URI with the amount and asset (`usdt_bip21_uri` for USDT); Copy the bare address.
          example: VJL4iV2MML...
        usdt_amount:
          type: string
          nullable: true
          description: USDT on Liquid, when offered — the USDT to send, a decimal string (priced 1:1 with USD, rounded up to the cent). Null when the payment offers no USDT.
          example: "54.10"
        usdt_bip21_uri:
          type: string
          nullable: true
          description: "`liquidnetwork:<liquid_address>?amount=<USDT>&assetid=<USDT asset id>` — render as the USDT QR so AQUA selects USDT and fills in the amount. Null when the payment offers no USDT."
          example: "liquidnetwork:VJL4iV2MML...?amount=54.10000000&assetid=ce091c998b83c78bb71a632313ba3760f1763d9cfcffae02258ffa9865a37bd2"
        btc_address:
          type: string
          nullable: true
          description: |
            The payment's Bitcoin address (native SegWit, on your wallet's Bitcoin account), once
            one has been allocated — null until then. An address is allocated only when it is asked
            for (`POST /api/v1/payments/{id}/bitcoin`, or the buyer opening the Bitcoin tab), so an
            abandoned checkout uses no address.
          example: bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu
        btc_amount_sat:
          type: integer
          nullable: true
          description: Exact amount to send to `btc_address`, in sats, in one transaction (equals `amount_sats`). Null until an address is allocated.
          example: 25000
        btc_bip21_uri:
          type: string
          nullable: true
          description: "`bitcoin:<address>?amount=<BTC>` — render as the Bitcoin QR so wallets fill in the amount."
          example: "bitcoin:bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu?amount=0.00025000"
        btc_window_ends_at:
          type: string
          format: date-time
          nullable: true
          description: The buyer should send before this time (60 minutes after allocation). A transaction seen before it holds the payment open until it confirms.
        btc_confirmations_required:
          type: integer
          nullable: true
          enum: [1, 2, 3, 6]
          description: Confirmations this payment needs before it is `paid` — the store's setting when the address was allocated. Never fewer than one.
        btc_confirmations:
          type: integer
          nullable: true
          description: Confirmations of the Bitcoin transaction seen so far (0 while in the mempool).
        btc_txid:
          type: string
          nullable: true
          description: The Bitcoin transaction paying this payment, once seen.
        btc_stage:
          type: string
          enum: [not_allocated, awaiting_payment, detected, paid, window_closed, closed]
          description: Where the Bitcoin part of the payment is.
        checkout_url:
          type: string
          description: Hosted checkout page. Redirect your buyer here for a zero-integration checkout. Alternatively, render `lightning_invoice` and `liquid_address` in your own UI.
          example: https://pay.aqua.net/pay/pmt_abc123
        redirect_url:
          type: string
          nullable: true
          description: Returned by POST only. The return page this payment will use — null when none was sent, or when the store's plan has no return page and the one sent was ignored.
        expires_at:
          type: string
          format: date-time
          description: ISO 8601 timestamp when the Lightning invoice expires (10 minutes after creation).
        created_at:
          type: string
          format: date-time
          description: ISO 8601 timestamp of payment creation. Returned by GET only.
        settled_at:
          type: string
          format: date-time
          nullable: true
          description: ISO 8601 timestamp of settlement. `null` until the payment is `paid`. Returned by GET only.
        settled_asset:
          type: string
          nullable: true
          enum: [btc, usdt]
          description: What a paid payment was paid in — `usdt` for USDT on Liquid, `btc` for Lightning, L-BTC or Bitcoin on-chain. `null` until `paid`. Returned by GET only.
        credit_state:
          type: string
          enum: [none, partial, full]
          description: How much of the payment's invoice credit notes have credited. `none` unless paid. Returned by GET only.
        metadata:
          type: object
          nullable: true
          additionalProperties: true
          description: Arbitrary key-value data you passed at creation. Returned verbatim in webhooks, and by GET to a secret key only — never to a publishable key, which is public.
        reference:
          type: string
          nullable: true
          description: Your own order or invoice reference, as sent at creation with a secret key. Not unique. Returned by POST, by GET to a secret key only, and in webhooks. Search with `GET /api/v1/payments/list?reference=`.
        created_with:
          type: string
          nullable: true
          enum: [secret, publishable, link]
          description: How the payment was created — `secret` (your server), `publishable` (a browser, which chose the amount and metadata itself) or `link` (a payment link). Trust `metadata` and `reference` as your order link only when this is `secret`, and always check the amount. `null` for earlier payments not made from a link, whose key was never recorded. Returned by POST, by GET to a secret key only, and in webhooks.
      example:
        payment_id: pmt_abc123
        status: pending
        amount_fiat: 25.00
        currency: EUR
        amount_sats: 12500
        invoice_sats: 12500
        methods: ["lightning", "liquid"]
        lightning_invoice: "lnbc125u1p..."
        liquid_address: "VJL4iV2MML..."
        btc_address: null
        btc_amount_sat: null
        btc_stage: not_allocated
        checkout_url: "https://pay.aqua.net/pay/pmt_abc123"
        expires_at: "2026-06-19T12:10:00Z"

    Refund:
      type: object
      properties:
        refund_id: { type: string, example: ref_x1y2z3 }
        payment_id: { type: string }
        status: { type: string, example: awaiting_buyer }
        amount:
          oneOf: [{ type: integer }, { type: string }]
          description: In the asset paid — an integer of sats, or a USDT decimal string ("12.50")
        amount_unit: { type: string, enum: [sat, usdt] }
        asset: { type: string, enum: [btc, usdt] }
        method: { type: string, enum: [lightning, liquid], nullable: true, description: Chosen by the buyer when claiming }
        refund_sats: { type: integer, nullable: true, description: The amount in sats; null for USDT }
        credited_fiat: { type: number, description: "What the refund's credit note credits, in `currency`: its share of what was paid, applied to the invoice total" }
        currency: { type: string }
        refund_reason: { type: string, nullable: true }
        initiated_via: { type: string, enum: [dashboard, api] }
        has_buyer_email: { type: boolean }
        claim_link:
          type: string
          nullable: true
          description: The buyer's credential. Only while the refund awaits the buyer and the link is unexpired.
        expires_at: { type: string, format: date-time }
        created_at: { type: string, format: date-time }

    PaymentLink:
      type: object
      properties:
        id:
          type: string
          example: lnk_abc123
        title:
          type: string
          nullable: true
        description:
          type: string
          nullable: true
        amount_fiat:
          type: number
          nullable: true
          description: Fixed amount, or null for an open amount the buyer chooses
        currency:
          type: string
        redirect_url:
          type: string
          nullable: true
        min_amount_fiat:
          type: number
          nullable: true
        max_amount_fiat:
          type: number
          nullable: true
        kind:
          type: string
          enum: [link, invoice]
        due_date:
          type: string
          format: date-time
          nullable: true
        payer_email:
          type: string
          nullable: true
        payer_name:
          type: string
          nullable: true
        reference:
          type: string
          nullable: true
        settled_count:
          type: integer
        settled_fiat:
          type: number
        status:
          type: string
          example: active
        use_count:
          type: integer
        plan_active:
          type: boolean
          description: "False when the link's owner did not keep it on a plan with lower limits: it takes no new payments. Always true while AQUA Pay is free during the private launch. See https://pay.aqua.net/docs#plans-lower"
        url:
          type: string
          example: https://pay.aqua.net/pay/lnk_abc123
        created_at:
          type: string
          format: date-time

paths:

  /api/v1/connect/descriptor:
    post:
      summary: Connect wallet via descriptors (no AQUA QR required)
      description: |
        Supply your own Liquid descriptors directly.
        This is the programmatic alternative to scanning the AQUA wallet QR code.
        Requires a secret API key. Connects once: 409 if this store already has a wallet
        (support resets it); 409 `wallet_in_use` if another store holds this wallet; 400
        `invalid_descriptor` if it cannot be read; 403 `feature_not_in_plan` (`agentOnboarding`,
        planned for Business and Enterprise once paid plans start).
      tags: [Wallet]
      security:
        - SecretKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [lbtc_descriptor, btcln_descriptor]
              properties:
                lbtc_descriptor:
                  type: string
                  description: Liquid BTC confidential descriptor (ct(slip77(...),elsh(wpkh(...))))
                  example: "ct(slip77(master_key_hex),elsh(wpkh([fp/49'/1776'/0']xpub.../0/*)))"
                btcln_descriptor:
                  type: string
                  description: Stored for the AQUA payload; not used for address derivation. Pass the same descriptor as `lbtc_descriptor`.
                  example: "ct(slip77(master_key_hex),elsh(wpkh([fp/49'/1776'/0']xpub.../0/*)))"
                btc_descriptor:
                  type: string
                  description: |
                    Optional — the same wallet's Bitcoin account, for Bitcoin on-chain:
                    `wpkh([fingerprint/84'/0'/0']xpub.../0/*)`, with the same master fingerprint as
                    `lbtc_descriptor`. 400 `invalid_btc_descriptor` otherwise; 409 `wallet_in_use` if
                    another store holds this Bitcoin account.
                  example: "wpkh([fp/84'/0'/0']xpub.../0/*)"
      responses:
        "200":
          description: Descriptors stored, wallet connected
          content:
            application/json:
              schema:
                type: object
                properties:
                  connected:
                    type: boolean
                    example: true
        "400":
          description: Invalid descriptor format, a descriptor over 500 characters, or `invalid_descriptor`
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "401":
          description: Invalid or missing API key
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "403":
          description: A publishable key, or `feature_not_in_plan` (not returned during the private launch)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "409":
          description: This store already has a wallet (contact support to reset it), or `wallet_in_use` — another store holds this wallet
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  # ── Payments ──────────────────────────────────────────────────────────────────

  /api/v1/payments:
    post:
      summary: Create a payment
      description: |
        Creates an Indra reverse swap and returns a Lightning invoice and a Liquid BTC address.
        When `methods` includes `bitcoin`, ask for the payment's Bitcoin address with
        `POST /api/v1/payments/{id}/bitcoin` (the hosted checkout does this when the buyer opens
        the Bitcoin tab); `btc_address` is null until then.

        **Auth:** a secret key from your server, or a publishable key from the buyer's browser
        (the embed and the JS SDK). A publishable key cannot send `reference`.

        **Hosted checkout:** redirect your buyer to `checkout_url` for a zero-integration checkout.

        **Headless:** render `lightning_invoice` and `liquid_address` in your own UI. Use `invoice_sats` for the Lightning amount display — it is the amount in the
        invoice, and equals `amount_sats`.

        **Payment bounds:** the amount must convert to at least **1000 sats** at the
        current BTC rate, and to no more than Indra's current maximum — otherwise `400`. Public link endpoints expose
        the live fiat equivalent as `min_payable_fiat`.

        Rate limits today, during the private launch: 30 requests a minute per store and
        300 requests a minute per account (across every store it owns). At most
        50 open payments per store and 500 open payments per account. A refusal carries
        `scope`, `limit` and, for open payments, `current` and `tier`. A valid secret
        key is held to these limits wherever it calls from. Without one (a publishable
        key, or a missing or invalid key), requests count toward 30 requests a minute
        per IP address, answered 429 without `scope`; with a publishable key, payment
        creation is also held to 10 requests a minute per IP address. Planned paid-plan limits:
        https://pay.aqua.net/docs#plans.
      tags: [Payments]
      security:
        - SecretKey: []
        - PublishableKey: []
      parameters:
        - in: header
          name: Idempotency-Key
          required: false
          schema:
            type: string
            maxLength: 255
          description: |
            Client-generated key (e.g. UUID or order ID) to make this request idempotent.
            If the same key is sent twice with identical body, the cached response is returned
            with no duplicate swap created. If the body differs, the server returns `422`.
            Secret key only: with a publishable key the header is ignored.
            Keys expire after 24 hours and can be freely reused after expiry.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [amount, currency]
              properties:
                amount:
                  oneOf: [{ type: number }, { type: string, pattern: '^\d+(\.\d+)?$' }]
                  description: Amount in fiat, a plain decimal with no more decimals than the currency has (2, or 0 for JPY, HUF, CLP, COP, ARS, KRW, TWD, IDR, CRC, PYG, NGN, UGX, TZS, XOF, XAF, VND, PKR and KZT); more is refused with 400 `amount_precision`. Must convert to at least 1000 sats at the current BTC rate.
                  example: 25.00
                amount_fiat:
                  oneOf: [{ type: number }, { type: string, pattern: '^\d+(\.\d+)?$' }]
                  description: Alias of `amount`; `amount` wins when both are sent. Send one of the two.
                currency:
                  type: string
                  pattern: '^[A-Z]{3}$'
                  description: ISO 4217 code, one of the supported currencies (`GET /api/v1/currencies`)
                  example: EUR
                redirect_url:
                  type: string
                  description: HTTPS URL to redirect buyer after payment on the hosted checkout. Must be https:, no credentials, ≤2048 chars. A Business and Enterprise feature once paid plans start (included in Business during the private launch); with a publishable key on a plan without it, ignored and the payment still created; the response's `redirect_url` is then null.
                description:
                  type: string
                  maxLength: 500
                  description: Optional description shown on the invoice.
                line_items:
                  type: array
                  maxItems: 20
                  description: Optional breakdown printed on the invoice. The rows, each rounded to the currency's precision, must total exactly `amount`, or 400. Omit for a single-line invoice; `[]` is an error.
                  items:
                    type: object
                    required: [description, qty, unit_price]
                    properties:
                      description: { type: string, maxLength: 200 }
                      qty: { type: number, description: Positive; fractions allowed }
                      unit_price: { type: number, description: Zero or more }
                metadata:
                  type: object
                  additionalProperties: true
                  description: Arbitrary key-value pairs (≤2 KB) stored with the payment and returned in webhooks.
                reference:
                  type: string
                  maxLength: 128
                  description: Your own order or invoice reference — 1 to 128 characters, no control characters, trimmed. Secret key only; a publishable key sending one gets 400 `reference_requires_secret_key`. Not unique, so a new payment for the same order after an expiry is allowed.
            example:
              amount: 25.00
              currency: EUR
              redirect_url: https://yourstore.com/thank-you
              reference: "ORD-1234"
              metadata:
                order_id: "ORD-1234"
      responses:
        "201":
          description: Payment created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Payment"
              example:
                payment_id: pmt_abc123
                status: pending
                amount_fiat: 25.00
                currency: EUR
                amount_sats: 12500
                invoice_sats: 12500
                methods: ["lightning", "liquid"]
                lightning_invoice: "lnbc125u1p..."
                liquid_address: "VJL4iV2MML..."
                btc_address: null
                btc_amount_sat: null
                checkout_url: "https://pay.aqua.net/pay/pmt_abc123"
                redirect_url: "https://yourstore.com/thank-you"
                expires_at: "2026-06-19T12:10:00Z"
                created_with: secret
                reference: "ORD-1234"
        "400":
          description: Validation error (unsupported currency, `amount_precision` — more decimals than the currency has, invalid redirect_url, invalid line_items, amount too small, an amount no payment method takes (above Lightning, L-BTC, USDT and Bitcoin on-chain maximums — above Indra's maximum alone the payment is created without Lightning), `reference_requires_secret_key`, wallet not connected, etc.)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "401":
          description: Invalid or missing API key
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "402":
          description: "`payments_paused` — not returned during the private launch. Once paid plans start: new payments are paused because the plan and its 4-day grace period have ended (`reason: plan_ended`) or a new account's free trial is used up (`reason: trial_used`), or the store was not kept by its owner on a plan with lower limits (`reason: store_deactivated`, no `paused_since`). The body carries `error`, `reason`, `paused_since`, `message` and `buyer_message`. Renew or choose a plan at pay.aqua.net/account. A missing secret-key plan is 403 `pro_plan_required`, not 402. See https://pay.aqua.net/docs#err-payments_paused"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "403":
          description: "Not returned during the private launch. Once paid plans start, a secret key on a plan without the REST API: `error: pro_plan_required`, `code: feature_not_in_plan`, with `feature`, `tier` and `required_tier`. Also `email_not_verified` when the store's email is not verified."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "409":
          description: "`request_in_flight` — same idempotency key is being processed concurrently"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "422":
          description: "`idempotency_key_reused_with_different_payload` — same key sent with a different request body"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "429":
          description: |
            `rate_limit_exceeded` — the store's or the account's request rate (with `scope`, `limit`
            and a `Retry-After` header); or `too_many_open_payments` — the store's or the account's
            open-payment cap (with `scope`, `limit`, `current`, `tier`; no `Retry-After`, it clears as
            payments are paid or expire). With a publishable key, also a per-device rate and a
            per-device cap on open payments (no `scope`).
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "503":
          description: The exchange rate, Indra's fees and limits, or Indra itself is temporarily unavailable, or the wallet must be reconnected. Retry after a few seconds. A missing rate also carries `code` `currency_unavailable`, the `currency` and a `Retry-After` header.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /api/v1/payments/list:
    get:
      summary: List the store's payments, newest first
      description: |
        Keyset-paged. Pass `next_before` from a page as `before` to get the next one; it is
        null on the last page. Works with any secret key (no plan gate) and from the dashboard.
      tags: [Payments]
      security:
        - SecretKey: []
      parameters:
        - name: status
          in: query
          schema:
            type: string
            default: pending,paid
          description: "`all`, or a comma-separated subset of `pending`, `paid`, `expired`. Default `pending,paid`."
        - name: limit
          in: query
          schema: { type: integer, minimum: 1, maximum: 200, default: 50 }
        - name: before
          in: query
          schema: { type: string }
          description: Cursor — `next_before` from the previous page (`<created_at>|<payment_id>`).
        - name: reference
          in: query
          schema: { type: string }
          description: Exact match on the `reference` you sent at creation. Not unique — every match is listed.
      responses:
        "200":
          description: A page of payments
          content:
            application/json:
              schema:
                type: object
                properties:
                  payments:
                    type: array
                    items:
                      type: object
                      description: "payment_id, created_at, status, invoice_channel, buyer_name, buyer_email, amount_fiat, currency, order_sats, invoice_number, invoice_status, credit_note_number, underpaid_sats, reference, created_with, service_name, latest_credit_note, can_replace, refunded_amount, refundable_amount, refundable_amount_bill (a tipped POS sale: what is left of the bill without include_tip; null otherwise)"
                  next_before:
                    type: string
                    nullable: true
        "400":
          description: Invalid `status`, `before` or `reference`
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /api/v1/payments/{id}:
    get:
      summary: Get payment status
      description: |
        Returns the full payment object including `created_at` and `settled_at`.
        `metadata`, `reference` and `created_with` are returned to a secret key
        only: a publishable key is public and a payment id is in every checkout
        link, so a publishable key gets the other fields alone.
        `credit_state` says how much of the invoice credit notes have credited.
        Poll this endpoint or use webhooks to track payment status. With a secret
        key, polling and the other /api/v1/payments requests count toward
        300 requests a minute per account, apart from payment creation.
      tags: [Payments]
      security:
        - SecretKey: []
        - PublishableKey: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            example: pmt_abc123
      responses:
        "200":
          description: Payment object
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Payment"
              example:
                payment_id: pmt_abc123
                status: paid
                amount_fiat: 25.00
                currency: EUR
                amount_sats: 12500
                invoice_sats: 12500
                methods: ["lightning", "liquid"]
                lightning_invoice: "lnbc125u1p..."
                liquid_address: "VJL4iV2MML..."
                btc_address: null
                btc_amount_sat: null
                btc_stage: not_allocated
                checkout_url: "https://pay.aqua.net/pay/pmt_abc123"
                created_at: "2026-06-19T12:00:00Z"
                settled_at: "2026-06-19T12:07:43Z"
                credit_state: none
                metadata:
                  order_id: "ORD-1234"
                reference: "ORD-1234"
                created_with: secret
        "404":
          description: Payment not found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  /api/v1/payments/{id}/bitcoin:
    post:
      summary: Get the payment's Bitcoin address
      description: |
        Allocates the payment's Bitcoin on-chain address, or returns the one it already has
        (idempotent). Paid directly to the Bitcoin account of the store's connected wallet: the
        buyer sends exactly `btc_amount_sat`, in one transaction, before `btc_window_ends_at`, and
        the payment is `paid` after `btc_confirmations_required` confirmations (webhook
        `payment.confirmed`). Never counted before its first confirmation. An exact-amount payment
        that arrives after the window still completes, up to 7 days later.
      tags: [Payments]
      security:
        - SecretKey: []
        - PublishableKey: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            example: pmt_abc123
      responses:
        "200":
          description: The payment's Bitcoin fields (see the Payment object's `btc_*` fields)
          content:
            application/json:
              example:
                payment_id: pmt_abc123
                btc_address: bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu
                btc_amount_sat: 25000
                btc_bip21_uri: "bitcoin:bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu?amount=0.00025000"
                btc_window_ends_at: "2026-11-01T13:00:00Z"
                btc_confirmations_required: 1
                btc_confirmations: null
                btc_txid: null
                btc_stage: awaiting_payment
        "404":
          description: Payment not found
        "409":
          description: "`bitcoin_not_available` (the store has Bitcoin off, its wallet gave no usable Bitcoin account, or the amount is outside 20 000 – 10 000 000 sats), or `payment_not_open`"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "503":
          description: "`bitcoin_temporarily_unavailable` — try again later; Lightning and Liquid still work"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  # ── Payment Links ─────────────────────────────────────────────────────────────

  /api/v1/payment-links:
    post:
      summary: Create a payment link
      description: |
        Creates a reusable link at `url` (`https://pay.aqua.net/pay/lnk_…`). Takes a secret key
        (once paid plans start, Business and Enterprise — otherwise 403 `pro_plan_required`) or a
        dashboard session. Every field is optional: omit the amount for an open-amount link.
        Listing, editing and archiving links are done in the dashboard (Get paid), not with a key.
      tags: [Payment Links]
      security:
        - SecretKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                title:
                  type: string
                description:
                  type: string
                amount_fiat:
                  type: number
                  nullable: true
                  description: Fixed amount, or omit for an open amount. No more decimals than the currency has (2, or 0 for JPY, HUF, CLP, COP, ARS, KRW, TWD, IDR, CRC, PYG, NGN, UGX, TZS, XOF, XAF, VND, PKR and KZT); more is refused with 400 `amount_precision`, as are `min_amount_fiat`, `max_amount_fiat` and `goal_fiat`. A fixed amount must clear the 1000-sat minimum with a rate-drift margin (400 `amount_below_minimum`).
                amount:
                  type: number
                  nullable: true
                  description: Alias of `amount_fiat`; `amount_fiat` wins when both are sent.
                currency:
                  type: string
                  pattern: '^[A-Z]{3}$'
                  description: ISO 4217 code, one of the supported currencies (`GET /api/v1/currencies`)
                  default: EUR
                redirect_url:
                  type: string
                  description: HTTPS URL after payment. A Business and Enterprise feature once paid plans start (403 `feature_not_in_plan`); included in Business during the private launch.
                line_items:
                  type: array
                  maxItems: 20
                  description: Fixed-amount links only. Copied onto every payment made from the link; must total `amount_fiat` exactly.
                  items:
                    type: object
                    properties:
                      description: { type: string, maxLength: 200 }
                      qty: { type: number }
                      unit_price: { type: number }
                min_amount_fiat:
                  type: number
                  description: Open-amount links — the lowest amount the buyer may enter.
                max_amount_fiat:
                  type: number
                  description: Open-amount links — the highest amount the buyer may enter; not below `min_amount_fiat`.
                kind:
                  type: string
                  enum: [link, invoice]
                  default: link
                  description: "`invoice` — a customer invoice to one payer, exempt from the active-item cap. `campaign` is refused with 400 `campaign_retired`: campaigns are switched off."
                due_date:
                  type: string
                  format: date-time
                payer_email:
                  type: string
                  format: email
                payer_name:
                  type: string
                  maxLength: 200
                reference:
                  type: string
                  maxLength: 140
            example:
              title: "1hr Consultation"
              amount_fiat: 150.00
              currency: USD
      responses:
        "201":
          description: Link created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PaymentLink"
        "400":
          description: Validation error (unsupported currency, `amount_precision`, `amount_below_minimum`, line_items without a fixed amount, invalid redirect_url, kind, due_date or payer_email), or `campaign_retired` for a link of kind `campaign`
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "402":
          description: "`store_frozen` — not returned during the private launch. Once paid plans start: the plan is in its grace period or payments are paused, so no new payment links. See https://pay.aqua.net/docs#err-store_frozen"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "403":
          description: >
            Plan limit reached (`plan_limit_reached`). ONE unified cap covers all
            active payment links, each counted once, across every store the account owns.
            Today, during the private launch: 500 active items per account.
            Planned paid plans: 5 / 50 / 500 active items per account (Starter / Business / Enterprise; planned,
            Enterprise subject to confirmation).
            Customer invoices (`kind: invoice`) are exempt. Archive an item (or
            upgrade) and retry. Also `pro_plan_required` or `feature_not_in_plan`
            once paid plans start. Current usage is in `limits.items`
            (`active`, `max`, `store_active`, `scope`) on the dashboard's link list.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    enum: [plan_limit_reached, pro_plan_required, feature_not_in_plan]
                  message:
                    type: string
                  scope:
                    type: string
                    enum: [store, account]
                    description: "`account` — counted across the account's stores; `store` for a store with no owner account"
                  limit:
                    type: integer
                  current:
                    type: integer
                  tier:
                    type: string
                    enum: [starter, pro, enterprise]

  # ── Refunds ───────────────────────────────────────────────────────────────────

  /api/v1/invoice/{payment_id}/refund:
    parameters:
      - name: payment_id
        in: path
        required: true
        schema:
          type: string
          example: pmt_abc123
    post:
      summary: Start a refund
      description: |
        Starts a refund of a paid payment, in the asset paid — sats for a Bitcoin payment, USDT
        for a USDT payment — never converted at an exchange rate; in full or in parts, one at a
        time. AQUA Pay never holds funds: the buyer claims the refund with the claim link
        (emailed when the payment has a buyer email) on Lightning or to a Liquid address, and
        the merchant then sends it from their own wallet. Only fund a refund your own system
        started. The claim link is returned only here (and by an Idempotency-Key
        replay while the buyer can still use it). A secret key may start 10 refunds an hour
        and 50 a day per store; the store's owner is emailed of every one. See /docs#refunds.
      tags: [Refunds]
      security:
        - SecretKey: []
      parameters:
        - name: Idempotency-Key
          in: header
          required: false
          description: 1–255 characters, kept with the refund for its lifetime. The same key and request answer 200 with that refund.
          schema:
            type: string
            maxLength: 255
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                amount:
                  oneOf: [{ type: integer }, { type: string }]
                  description: "In the asset paid: a whole number of sats (at least 1000), or a USDT amount with at most two decimals. Default: everything not yet refunded. `mode: fiat` and `fiat_amount` are retired (400 `fiat_refunds_retired`)."
                include_tip:
                  type: boolean
                  description: A POS sale with a tip — refunds are bounded by the bill's share unless true
                reason:
                  type: string
                  maxLength: 200
      responses:
        "201":
          description: Refund started
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Refund"
        "200":
          description: Idempotency-Key replay — the refund that key started
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Refund"
        "400":
          description: |
            Not refundable: the payment is unpaid or its invoice voided; `fiat_refunds_retired`;
            `invalid_amount`; `below_minimum` (1000 sats); more than was paid and not yet refunded
            (`exceeds_refundable`), than the bill's share of a tipped sale (`exceeds_bill`) or than
            credit notes leave (`exceeds_uncredited`) — each with `refundable`; or
            `invalid_idempotency_key`.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "403":
          description: A publishable key, or `pro_plan_required`
        "404":
          description: Payment not found
        "409":
          description: "`refund_in_progress` — another refund of this payment is in progress; `already_refunded` — everything paid is refunded; `already_credited` — the invoice is credited in full"
        "422":
          description: "`idempotency_key_reused_with_different_payload`"
        "429":
          description: "`refund_rate_limited` — with `limit`, `window` (hour or day), `retry_after` and a `Retry-After` header"
    get:
      summary: Get the payment's refund
      description: The latest refund attempt, with earlier ones in `history`. Never returns the claim link to a secret key.
      tags: [Refunds]
      security:
        - SecretKey: []
      responses:
        "200":
          description: The refund
          content:
            application/json:
              schema:
                type: object
                properties:
                  refund_id: { type: string }
                  status:
                    type: string
                    enum: [awaiting_buyer, awaiting_payment, mempool, paid, complete, failed, cancelled]
                  amount: { oneOf: [{ type: integer }, { type: string }] }
                  amount_unit: { type: string, enum: [sat, usdt] }
                  asset: { type: string, enum: [btc, usdt] }
                  method: { type: string, enum: [lightning, liquid], nullable: true }
                  refund_sats: { type: integer, nullable: true }
                  credited_fiat: { type: number }
                  currency: { type: string }
                  refund_reason: { type: string, nullable: true }
                  buyer_liquid_address: { type: string, nullable: true, description: Liquid — where to send it }
                  deadline_at: { type: string, format: date-time, nullable: true, description: Liquid — send by then }
                  txid: { type: string, nullable: true, description: Liquid — the transaction found or reported }
                  verified_by: { type: string, enum: [chain, merchant], nullable: true }
                  refunded_amount: { oneOf: [{ type: integer }, { type: string }], description: What the payment's refunds returned, in the asset paid }
                  refundable_amount: { oneOf: [{ type: integer }, { type: string }], description: What may still be refunded }
                  refundable_amount_bill: { oneOf: [{ type: integer }, { type: string }], nullable: true, description: "A tipped POS sale: what may still be refunded without `include_tip` (the bill's share); null when there is no tip" }
                  created_at: { type: string, format: date-time, description: When this refund was started }
                  initiated_via: { type: string, enum: [dashboard, api] }
                  lockup_address: { type: string, nullable: true }
                  lockup_amount_sat: { type: integer, nullable: true }
                  timeout_block_height: { type: integer, nullable: true, description: The Liquid block height by which the swap must be funded }
                  timeout_blocks_left: { type: integer, nullable: true, description: "Blocks left to fund it, while `awaiting_payment` or `mempool`; null when unknown" }
                  claim_token_expires_at: { type: string, format: date-time }
                  refund_completed_at: { type: string, format: date-time, nullable: true }
                  return_state: { type: string, nullable: true, description: "A failed refund's L-BTC on its way back: pending, broadcast, confirmed, failed, not_needed or resolved" }
                  return_txid: { type: string, nullable: true }
                  returned_sats: { type: integer, nullable: true }
                  can_retry: { type: boolean }
                  history: { type: array, items: { type: object } }
        "404":
          description: No refund for this payment
    delete:
      summary: Cancel a refund
      description: While the buyer has not claimed it, or a Liquid refund before anything was sent. The store's owner is emailed when a secret key cancels one.
      tags: [Refunds]
      security:
        - SecretKey: []
      responses:
        "200":
          description: Cancelled
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok: { type: boolean }
                  refund_id: { type: string }
        "409":
          description: The refund can no longer be cancelled

  /api/v1/invoice/{payment_id}/refund/transaction:
    parameters:
      - name: payment_id
        in: path
        required: true
        schema:
          type: string
    post:
      summary: Report a Liquid refund's transaction
      description: |
        For a Liquid refund AQUA Pay could not read from the chain on its own (coins the store's
        key cannot unblind, several recipients in one send). The transaction must exist, pay the
        buyer's address and not be older than the claim; the refund completes at its first
        confirmation, and its credit note says it was reported by the merchant.
      tags: [Refunds]
      security:
        - SecretKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [txid]
              properties:
                txid: { type: string, pattern: "^[0-9a-f]{64}$" }
      responses:
        "200":
          description: Recorded
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok: { type: boolean }
                  refund_id: { type: string }
                  status: { type: string, enum: [mempool, complete] }
                  txid: { type: string }
                  verified_by: { type: string, enum: [merchant] }
        "400":
          description: "`invalid_txid`, `tx_not_found`, `tx_not_to_buyer` or `tx_before_claim`"
        "409":
          description: "`refund_not_waiting`, `tx_already_found` or `tx_already_used`"
        "503":
          description: The Liquid explorer cannot be reached. Retry.

  # ── Webhooks ──────────────────────────────────────────────────────────────────

  /api/v1/webhooks:
    post:
      summary: Set the webhook endpoint
      description: |
        Every delivery is signed: `X-AQUA-Pay-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>.<raw body>">`,
        keyed with the store's signing secret (two `v1` values during a rotation's 24-hour overlap).
        The first URL, and a URL on a different host, come with a new secret, returned
        here once (`secret`); the old secret then stops at once. A new path on the same host keeps it.
        Events: `payment.confirmed`, `payment.expired`, `payment.reopened`, `credit_note.issued`,
        `invoice.reissued`, `payment.resync`, `refund.awaiting_funding`, `refund.completed`,
        `refund.failed`, `refund.cancelled`, `refund.returned` (each with a `refund` object), and
        `payment.test` from the test button. Ignore an event type you do not know. Each carries
        `event_id` (stable across retries — deduplicate on it), `sequence` (the payment's events
        numbered 1, 2, 3… in order), `occurred_at` and `previous_status`. 9 attempts over about
        3 days; see /docs#webhooks.
      tags: [Webhooks]
      security:
        - SecretKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [url]
              properties:
                url:
                  type: string
                  description: Public HTTPS URL to receive POST notifications
      responses:
        "200":
          description: Webhook endpoint set
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
                  url:
                    type: string
                  secret:
                    type: string
                    description: Present only when a new signing secret was created (first URL, or a new host). Shown once.
                  secret_reason:
                    type: string
                    enum: [new, new_host]

    get:
      summary: Get the webhook configuration
      tags: [Webhooks]
      security:
        - SecretKey: []
      responses:
        "200":
          description: Webhook config
          content:
            application/json:
              schema:
                type: object
                properties:
                  url:
                    type: string
                    nullable: true
                  has_secret:
                    type: boolean
                  previous_secret_until:
                    type: string
                    format: date-time
                    nullable: true
                    description: While a rotation's overlap runs, the replaced secret also signs until this time.

    delete:
      summary: Remove the webhook endpoint and its secrets
      description: Pending deliveries are cancelled.
      tags: [Webhooks]
      security:
        - SecretKey: []
      responses:
        "200":
          description: Removed

  /api/v1/webhooks/rotate-secret:
    post:
      summary: Replace the signing secret
      description: The new secret is returned once. The replaced one keeps signing (a second `v1`) for 24 hours.
      tags: [Webhooks]
      security:
        - SecretKey: []
      responses:
        "200":
          description: New secret
          content:
            application/json:
              schema:
                type: object
                properties:
                  secret:
                    type: string
                  previous_secret_until:
                    type: string
                    format: date-time
                    nullable: true

  /api/v1/webhooks/deliveries:
    get:
      summary: List webhook deliveries, newest first
      tags: [Webhooks]
      security:
        - SecretKey: []
      parameters:
        - { name: state, in: query, schema: { type: string, enum: [pending, sent, failed, cancelled] } }
        - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 500, default: 100 } }
      responses:
        "200":
          description: "`deliveries`: id, event, event_id, payment_id, sequence, state, attempts, http_status, last_error, next_retry, created_at, completed_at, redelivery_of"

  /api/v1/webhooks/deliveries/{id}/redeliver:
    post:
      summary: Send an event again (a new delivery, same event_id and body)
      tags: [Webhooks]
      security:
        - SecretKey: []
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
      responses:
        "201":
          description: "`delivery_id` of the new delivery"
        "404":
          description: "`not_found`"
        "409":
          description: "`already_pending`, `event_pruned` or `no_webhook_url`"

  /api/v1/webhooks/deliveries/redeliver-failed:
    post:
      summary: Redeliver every event whose latest delivery failed (at most 500 a call)
      tags: [Webhooks]
      security:
        - SecretKey: []
      responses:
        "200":
          description: "`queued`, `remaining`, `max_per_call`"

  /api/v1/events:
    get:
      summary: The store's events, oldest first — a moving stream that never skips an event
      description: |
        Same shape as the webhook body. Follow `next_cursor` while `has_more`; store the last
        cursor and call again later. An event is listed only once every older transaction has
        finished, so a slow one is never skipped. 410 `cursor_expired` (older than 90 days) and
        409 `cursor_reset`: resync from GET /api/v1/payments/list and start without a cursor.
      tags: [Webhooks]
      security:
        - SecretKey: []
      parameters:
        - { name: cursor, in: query, schema: { type: string } }
        - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 200, default: 100 } }
      responses:
        "200":
          description: "`events`, `next_cursor`, `has_more`"
        "400":
          description: "`invalid_cursor`"
        "409":
          description: "`cursor_reset`"
        "410":
          description: "`cursor_expired`"

  /api/v1/webhooks/test:
    post:
      summary: Send a signed test event (payment.test)
      description: Refused (400) when no URL is set or the URL has no signing secret.
      tags: [Webhooks]
      security:
        - SecretKey: []
      responses:
        "200":
          description: Test event sent; `ok` and the endpoint's `http_status`

  # ── Public Checkout ───────────────────────────────────────────────────────────

  /api/v1/checkout/{id}:
    get:
      summary: Get checkout data for payment page
      description: Called by the buyer's browser when loading the pay page, `/pay/{payment_id}`. No auth.
      tags: [Public Checkout]
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: "Checkout data (invoice, addresses, amounts). Includes `lightning_available` and `lbtc_available` (false above Indra's maximum and above the L-BTC direct maximum respectively), `usdt_available`, `usdt_amount`, `usdt_bip21_uri`, `settled_asset` once paid, and `branding` (`logo_url`, `logo_width`, `logo_height`, `attribution`, `store_name`; `attribution: false` means the store's own logo replaces AQUA Pay's)."
          content:
            application/json:
              schema:
                type: object

  /api/v1/checkout/{id}/status:
    get:
      summary: Poll checkout payment status
      description: Called by the buyer's browser. No auth.
      tags: [Public Checkout]
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Status
          content:
            application/json:
              schema:
                type: object
                properties:
                  payment_id:
                    type: string
                  status:
                    type: string
                    enum: [pending, paid, expired]
                  redirect_url:
                    type: string
                    nullable: true
                    description: The return page, or null when none is set or the store's plan has none
        "404":
          description: Payment not found

  /api/v1/checkout/{id}/bitcoin:
    post:
      summary: Allocate the Bitcoin address (buyer's browser)
      description: What the hosted checkout and the embed call when the buyer opens the Bitcoin tab. Same answer as `POST /api/v1/payments/{id}/bitcoin`, without auth.
      tags: [Public Checkout]
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: The payment's Bitcoin fields
        "404":
          description: Payment not found
        "409":
          description: "`bitcoin_not_available` or `payment_not_open`"
        "503":
          description: "`bitcoin_temporarily_unavailable`"

  /api/v1/checkout/{id}/btc-status:
    get:
      summary: Poll Bitcoin progress (buyer's browser)
      description: Read-only, from AQUA Pay's database. No auth.
      tags: [Public Checkout]
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Bitcoin progress
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    enum: [pending, paid, expired]
                  stage:
                    type: string
                    enum: [not_allocated, awaiting_payment, detected, paid, window_closed, closed]
                  confirmations:
                    type: integer
                    nullable: true
                  confirmations_required:
                    type: integer
                    nullable: true
                  txid:
                    type: string
                    nullable: true
                  window_ends_at:
                    type: string
                    nullable: true
        "404":
          description: Payment not found
        "429":
          description: Polled more than 30 times a minute

  # ── Public payment links ────────────────────────────────────────────────────

  /api/v1/checkout/link/{link_id}:
    get:
      summary: A payment link's public data
      description: |
        What the hosted pay page and the embed widget read before checkout. No auth.
        Fields: id, title, description, amount_fiat (null for an open amount), currency,
        min_amount_fiat, max_amount_fiat (in the link's currency), min_payable_fiat, status, kind,
        stock_limit, use_count, sold_out, due_date, settled_count, settled_fiat,
        checkout_options {theme, return_page}, and branding {logo_url, logo_width, logo_height,
        attribution, store_name} — attribution false means the store's own logo replaces AQUA Pay's
        (Enterprise with an uploaded logo); logo_url is a path on this origin.
      tags: [Public Checkout]
      parameters:
        - name: link_id
          in: path
          required: true
          schema:
            type: string
            example: lnk_abc
      responses:
        "200":
          description: The link's public data
        "404":
          description: Unknown or archived link, or a suspended store
        "410":
          description: "`already_paid` — a paid invoice link"

  /api/v1/checkout/link/{link_id}/pay:
    post:
      summary: Start a payment from a link
      description: |
        No auth. An open-amount link needs `amount_fiat` and `currency` (any supported currency:
        when it differs from the link's, the amount is converted at the current rate before it is
        checked against the link's minimum and maximum). A fixed-amount link ignores both. The
        buyer's details may be sent for the invoice.
      tags: [Public Checkout]
      parameters:
        - name: link_id
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                amount_fiat:
                  type: string
                  example: "10.00"
                currency:
                  type: string
                  example: EUR
                link_currency:
                  type: string
                  description: The link's own currency, echoed by the client. Required to pay a link priced in a currency added after the original nine in another currency; without it such a request gets 400 `currency_not_supported_by_client`.
                  example: EUR
                buyer_name:
                  type: string
                buyer_email:
                  type: string
                buyer_vat:
                  type: string
                buyer_address:
                  type: string
                buyer_city_zip:
                  type: string
                buyer_country:
                  type: string
      responses:
        "201":
          description: "`{payment_id, checkout_url}`"
        "400":
          description: Outside the link's minimum or maximum (stated in the link's currency), `amount_too_small`, `amount_precision`, a missing amount or currency, or below the 1000-sat minimum
        "402":
          description: "`payments_paused` — once paid plans start, the store's new payments are paused. The body carries only `error`, `message` and `buyer_message` (\"Payments are currently deactivated. Please contact the store.\")."
        "404":
          description: Unknown or archived link, or a suspended store
        "410":
          description: "`already_paid` or `sold_out: This item is sold out.`"
        "429":
          description: "`too_many_open_payments` or `link_busy` — see https://pay.aqua.net/docs#rate-limits"
        "503":
          description: The exchange rate or Indra could not be reached

  /api/v1/invoices:
    get:
      summary: List issued invoices
      description: |
        `{invoices, total, truncated}`, newest payment first; `format=csv` for CSV. `from` and `to`
        filter the paid date (inclusive). JSON is capped at 1000 rows and CSV at 10000 (CSV then
        carries `X-AQUA-Pay-Truncated: true`).
      tags: [Invoices]
      security:
        - SecretKey: []
      parameters:
        - { name: from, in: query, schema: { type: string, format: date-time } }
        - { name: to, in: query, schema: { type: string, format: date-time } }
        - { name: format, in: query, schema: { type: string, enum: [json, csv] } }
      responses:
        "200":
          description: The invoices

  /api/v1/invoices/export:
    get:
      summary: Accounting export
      description: |
        One row per document version (invoice versions, credit notes, replacements) with the rate,
        fees and their provenance. Filters `issued_from`/`issued_to`, `paid_from`/`paid_to` (UTC, end
        exclusive). JSON: `{documents, next_cursor}`, up to 1000 rows a page (`limit`, `cursor`);
        `format=csv` streams every row. Business and Enterprise once paid plans start.
      tags: [Invoices]
      security:
        - SecretKey: []
      responses:
        "200":
          description: The export

  /api/v1/payments/{id}/invoice:
    get:
      summary: Download the invoice PDF
      description: |
        `invoice-<number>.pdf` (`-v<N>` for a later version). `version` gives an earlier version,
        `number` an earlier invoice of the payment (one a replacement superseded).
      tags: [Invoices]
      security:
        - SecretKey: []
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
        - { name: version, in: query, schema: { type: integer, minimum: 1 } }
        - { name: number, in: query, schema: { type: string } }
      responses:
        "200":
          description: The PDF
          content:
            application/pdf: {}
        "400":
          description: "`version` is not a positive whole number"
        "404":
          description: Payment not found or not paid, or `No such invoice version`
        "409":
          description: "`invoice_not_issued` — retry in a minute"

  /api/v1/payments/{id}/credit-note:
    get:
      summary: Download a credit note PDF
      description: The latest credit note, or the one named by `number`.
      tags: [Invoices]
      security:
        - SecretKey: []
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
        - { name: number, in: query, schema: { type: string, example: CN-2026-00001 } }
      responses:
        "200":
          description: The PDF
          content:
            application/pdf: {}
        "404":
          description: Payment not found, `No credit note for this payment` or `No such credit note`

  /api/v1/payments/{id}/documents:
    get:
      summary: A payment's documents
      description: |
        `{documents, credit_state, current_invoice}`: every invoice version, credit note and
        replacement (kind, number, version, issued_at, content_hash, file_sha256, reconstructed, total,
        currency, and what it supersedes, credits or replaces), and the invoice in force.
      tags: [Invoices]
      security:
        - SecretKey: []
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
      responses:
        "200":
          description: The documents
        "404":
          description: Payment not found

  /api/v1/payments/{id}/resend-receipt:
    post:
      summary: Email the issued invoice to the buyer again
      tags: [Invoices]
      security:
        - SecretKey: []
      parameters:
        - { name: id, in: path, required: true, schema: { type: string } }
      responses:
        "200":
          description: "`{ok: true, sent_to}`"
        "400":
          description: "`Payment not yet confirmed` or `No buyer email on file for this payment`"
        "404":
          description: Payment not found
        "409":
          description: "`invoice_not_issued`"

  /api/v1/credit-notes:
    get:
      summary: List credit notes
      description: Filter by `source` (`refund` or `manual`), `payment_id`, `from`, `to`. Business and Enterprise once paid plans start.
      tags: [Invoices]
      security:
        - SecretKey: []
      responses:
        "200":
          description: "`{credit_notes}`"

  /api/v1/documents/deliveries:
    get:
      summary: Invoice and credit-note email deliveries
      description: "`state` = `pending`, `sent` or `failed`. Part of the accounting export feature."
      tags: [Invoices]
      security:
        - SecretKey: []
      responses:
        "200":
          description: The deliveries

  /api/v1/documents/failed-deliveries:
    get:
      summary: Document emails that could not be delivered
      tags: [Invoices]
      security:
        - SecretKey: []
      responses:
        "200":
          description: The failed deliveries

  /api/v1/documents/events:
    get:
      summary: Document audit log
      description: Every document issued, corrected, credited, delivered or exported, and by whom; `format=csv` for CSV. Enterprise once paid plans start.
      tags: [Invoices]
      security:
        - SecretKey: []
      responses:
        "200":
          description: The audit log

  /api/v1/invoice/{payment_id}:
    get:
      summary: The buyer's invoice PDF
      description: No auth. The paid payment's invoice as `receipt-<number>.pdf`, linked from the receipt email and the checkout page.
      tags: [Public Checkout]
      parameters:
        - { name: payment_id, in: path, required: true, schema: { type: string } }
      responses:
        "200":
          description: The PDF
          content:
            application/pdf: {}
        "404":
          description: Payment not found, or not paid yet
        "409":
          description: "`invoice_not_issued`"

  # ── Currencies ────────────────────────────────────────────────────────────────

  /api/v1/currencies:
    get:
      summary: Supported currencies
      description: |
        No auth, same origin. Every fiat currency a price can be set in, with its decimals and
        symbol, and whether it can be priced right now (`available`; false answers payments in it
        with 503 `currency_unavailable`). Cached for 60 seconds.
      tags: [System]
      responses:
        "200":
          description: The currencies
          content:
            application/json:
              schema:
                type: object
                properties:
                  currencies:
                    type: array
                    items:
                      type: object
                      properties:
                        code: { type: string, example: EUR }
                        name: { type: string, example: Euro }
                        decimals: { type: integer, example: 2 }
                        symbol: { type: string, example: "€" }
                        available: { type: boolean }

  # ── Health ────────────────────────────────────────────────────────────────────

  /health:
    get:
      summary: Health check
      tags: [System]
      responses:
        "200":
          description: API is healthy
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: ok
        "503":
          description: Database unavailable

tags:
  - name: Wallet
    description: Connect a store's wallet by API
  - name: Payments
    description: Create and track payments
  - name: Payment Links
    description: Shareable payment links with optional fixed amounts
  - name: Refunds
    description: Non-custodial refunds in the asset paid, over Lightning or Liquid — the merchant sends each one from their own wallet
  - name: Webhooks
    description: Receive real-time payment notifications
  - name: Public Checkout
    description: Buyer-facing endpoints (no auth — called from browser)
  - name: System
    description: Health and metadata
