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

# Mail letter

> Print and mail an `ESCROWED` letter through **Lob** and move it to
`MAILED`. `standard` is USPS First Class; `tracked` adds USPS
Certified for US destinations or Registered for international ones,
and populates `mail.trackingNumber` and tracking events. `courier` is
not offered (`400 delivery_method_unavailable`).

Requires the claim origin fixed at creation to be `https:`
(`400 claim_origin_not_public`); paper cannot be corrected later.
The submission is idempotent: retrying after a timeout adopts the
letter Lob already accepted instead of mailing a second copy. Provider
failures leave the letter `ESCROWED` with the attempt recorded.

With a Lob **test** key (`test_…`) letters are validated and priced
but never printed or mailed; the letter reports `mail.testMode: true`.




## OpenAPI

````yaml /api-reference/openapi.yaml post /transfer/letter/{id}/mail
openapi: 3.1.0
info:
  title: AroPay API
  version: 1.0.0
  description: |
    The AroPay API for orchestrating sealed, private payments on public
    ledgers, built on the Aro Confidential Rails (Zama Protocol FHE). Two
    environments run the same API: Production on Ethereum Mainnet
    (`aropay.aro.media`, real funds) and the Sandbox on Sepolia
    (`dev.aropay.aro.media`, test funds and a faucet). Integrations built
    against the sandbox carry over unchanged; the faucet (`POST /fund`) is
    sandbox-only and returns 404 on production.

    Every response (except the flat Sandbox probes)
    uses the shared envelope: `{ "ok": true, "data": … }` on success and
    `{ "ok": false, "error": { "code", "message", "details?" } }` on failure.

    Amounts are decimal strings in human units (e.g. `"125.50"`). Write
    requests must send `Content-Type: application/json`.
  contact:
    name: Aro Media
    url: https://aro.media
servers:
  - url: https://aropay.aro.media/api/v1
    description: Production (Ethereum Mainnet)
  - url: https://dev.aropay.aro.media/api/v1
    description: Sandbox (Sepolia)
  - url: http://aropay.localhost:3000/api/v1
    description: Local development
security:
  - apiKeyAuth: []
  - sessionCookie: []
tags:
  - name: Auth
    description: Password, TOTP, and passkey login; session inspection and logout.
  - name: Profile & security
    description: Profile, password, two-factor authentication, and passkey management.
    x-group: Profile & security
  - name: API keys
    description: Programmatic credentials. Creation and revocation are session-only.
  - name: Wallets
    description: Custodial and external (watch-only) wallets.
  - name: Balances
    description: Balance triples and lightweight gas reads.
  - name: Money movement
    description: |
      Faucet funding, minting, transfers, and redemptions. All four are
      asynchronous: the request is validated and recorded, the response is
      `201` with the transaction in status `QUEUED` (`txHash: null`), and a
      background worker executes it. Poll `GET /transactions/{id}` until
      `status` is `CONFIRMED`, `SETTLED`, or `FAILED`. Execution failures
      surface as status `FAILED` with `errorCode` on the transaction, never
      as an HTTP error on the POST.
  - name: Aro Mail
    description: >-
      Letters of value: escrow cAROUSD, print or mail through Lob, and let the
      recipient claim by QR or code.
  - name: Transactions
    description: >-
      History, single-transaction reads (pure database reads), and notarized
      receipts.
  - name: Sandbox
    description: Unauthenticated status and echo probes with a flat response shape.
paths:
  /transfer/letter/{id}/mail:
    post:
      tags:
        - Aro Mail
      summary: Mail letter
      description: |
        Print and mail an `ESCROWED` letter through **Lob** and move it to
        `MAILED`. `standard` is USPS First Class; `tracked` adds USPS
        Certified for US destinations or Registered for international ones,
        and populates `mail.trackingNumber` and tracking events. `courier` is
        not offered (`400 delivery_method_unavailable`).

        Requires the claim origin fixed at creation to be `https:`
        (`400 claim_origin_not_public`); paper cannot be corrected later.
        The submission is idempotent: retrying after a timeout adopts the
        letter Lob already accepted instead of mailing a second copy. Provider
        failures leave the letter `ESCROWED` with the attempt recorded.

        With a Lob **test** key (`test_…`) letters are validated and priced
        but never printed or mailed; the letter reports `mail.testMode: true`.
      operationId: mailLetter
      parameters:
        - $ref: '#/components/parameters/LetterId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MailLetterRequest'
            example:
              deliveryMethod: tracked
              provider: lob
      responses:
        '200':
          description: The letter as `MAILED`, with `mail` populated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LetterEnvelope'
              example:
                ok: true
                data:
                  letter:
                    id: cklet0001abcd
                    status: MAILED
                    chainId: 11155111
                    amount: '50.00'
                    token: cAROUSD
                    amountVisibility: sealed
                    memo: Thanks for the referral
                    recipient:
                      name: Jane Doe
                      address:
                        line1: 12 Adeola Odeku Street
                        line2: Victoria Island
                        landmark: Opposite Eko Hotel
                        city: Lagos
                        region: LA
                        postal: null
                        country: NG
                        countryName: Nigeria
                    isDomestic: false
                    expiresAt: '2026-10-22T09:45:00.000Z'
                    sender:
                      walletId: ckwlt0001abcd
                      address: '0x8Ba1f109551bD432803012645Ac136ddd64DBA72'
                    claimCode: 7K3M-Q9TX-2ABF-H8RD-5CWN-VGP4-0J6Y
                    claimUrl: >-
                      https://dev.aropay.aro.media/claim#7K3M-Q9TX-2ABF-H8RD-5CWN-VGP4-0J6Y
                    pdfUrl: >-
                      https://dev.aropay.aro.media/api/v1/transfer/letter/cklet0001abcd/pdf
                    escrow:
                      transactionId: cktxn0005abcd
                      txHash: 0x4d1e…
                      explorerUrl: https://sepolia.etherscan.io/tx/0x4d1e…
                      status: CONFIRMED
                      verified: true
                    claim: null
                    refund: null
                    mail:
                      provider: lob
                      providerId: ltr_4868c3b5655f1f5c
                      deliveryMethod: tracked
                      status: processed
                      trackingNumber: '9407300000000000000004'
                      expectedDeliveryDate: '2026-09-22'
                      mailedAt: '2026-09-07T10:02:11.000Z'
                      testMode: true
                    needsReview: false
                    error: null
                    createdAt: '2026-09-07T09:45:00.000Z'
                    updatedAt: '2026-09-07T10:02:11.000Z'
        '400':
          description: >
            Letter not `ESCROWED` (`letter_not_escrowed`,
            `letter_already_mailed`),

            `deliveryMethod: "courier"` (`delivery_method_unavailable`), a

            non-`https:` claim origin (`claim_origin_not_public`), Lob

            rejecting the address (`invalid_postal_address`), or validation.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                ok: false
                error:
                  code: letter_already_mailed
                  message: This letter has already been mailed.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          description: >-
            Lob could not accept the letter (outage, timeout, or a non-address
            rejection). The letter stays `ESCROWED`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                ok: false
                error:
                  code: postage_unavailable
                  message: >-
                    Lob rejected the letter: file must be a PDF with 8.5x11 inch
                    pages.
        '403':
          $ref: '#/components/responses/AccountDisabled'
        '404':
          $ref: '#/components/responses/LetterNotFound'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
        '503':
          description: >-
            Lob is not configured on this deployment (missing or rejected
            `LOB_API_KEY`, or incomplete return address).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                ok: false
                error:
                  code: mail_provider_not_configured
                  message: Mailing is not configured on this deployment.
components:
  parameters:
    LetterId:
      name: id
      in: path
      required: true
      schema:
        type: string
      description: Letter ID.
  schemas:
    MailLetterRequest:
      type: object
      required:
        - deliveryMethod
      properties:
        deliveryMethod:
          type: string
          enum:
            - standard
            - tracked
            - courier
          description: >
            `standard`: USPS First Class. `tracked`: First Class plus USPS

            Certified (US) or Registered (international), with tracking.

            `courier` is not offered and returns `400
            delivery_method_unavailable`.
        provider:
          type: string
          enum:
            - lob
          description: Optional; `lob` is the only provider.
    LetterEnvelope:
      type: object
      required:
        - ok
        - data
      properties:
        ok:
          const: true
        data:
          type: object
          required:
            - letter
          properties:
            letter:
              $ref: '#/components/schemas/Letter'
    ErrorResponse:
      type: object
      description: The shared failure envelope.
      required:
        - ok
        - error
      properties:
        ok:
          const: false
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              description: Machine-readable error code; match on this, not `message`.
            message:
              type: string
            details:
              description: Structured context, e.g. per-field validation issues.
    Letter:
      type: object
      description: |
        An Aro Mail letter: escrowed cAROUSD, a recipient address, a one-time
        claim code, and the legs that moved value.
      required:
        - id
        - status
        - chainId
        - amount
        - token
        - amountVisibility
        - memo
        - recipient
        - isDomestic
        - expiresAt
        - sender
        - claimCode
        - claimUrl
        - pdfUrl
        - escrow
        - claim
        - refund
        - mail
        - needsReview
        - error
        - createdAt
        - updatedAt
      properties:
        id:
          type: string
          examples:
            - cklet0001abcd
        status:
          type: string
          enum:
            - DRAFT
            - ESCROWED
            - MAILED
            - CLAIMING
            - CLAIMED
            - EXPIRED
            - VOIDED
            - FAILED
          description: |
            `DRAFT` (escrow submitted) → `ESCROWED` (escrow verified) →
            optional `MAILED` → `CLAIMING` → `CLAIMED`. `EXPIRED` and `VOIDED`
            carry a refund leg. `FAILED` means the escrow reverted, clamped or
            was never submitted: no value left the sender. Claimable:
            `ESCROWED`, `MAILED`. Terminal: `CLAIMED`, `EXPIRED`, `VOIDED`,
            `FAILED`.
        chainId:
          type: integer
          examples:
            - 11155111
        amount:
          type: string
          description: >-
            Decimal string in human units. Cleartext to the parties; encrypted
            on-chain.
        token:
          type: string
          examples:
            - cAROUSD
        amountVisibility:
          type: string
          enum:
            - sealed
            - visible
          description: >-
            Whether the printed letter shows the amount. Defaults to `visible`
            domestic, `sealed` international.
        memo:
          type:
            - string
            - 'null'
          description: Up to 200 characters, printed on the letter.
        recipient:
          type: object
          required:
            - name
            - address
          properties:
            name:
              type: string
            address:
              $ref: '#/components/schemas/LetterAddress'
        isDomestic:
          type: boolean
          description: >-
            True when the destination is the deployment's home country (`US` by
            default).
        expiresAt:
          type: string
          format: date-time
        sender:
          type: object
          required:
            - walletId
            - address
          properties:
            walletId:
              type:
                - string
                - 'null'
              description: >-
                The sending wallet; `null` if that wallet was later deleted
                (refunds still go to `address`).
            address:
              type: string
              description: EIP-55 address the escrow came from and refunds return to.
        claimCode:
          type:
            - string
            - 'null'
          description: |
            Display form (`XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX`, 28 Crockford
            base32 symbols incl. two check symbols). Owner-only: present on
            create and single reads while the letter is non-terminal; `null`
            in lists and once terminal.
        claimUrl:
          type:
            - string
            - 'null'
          description: >-
            `https://<aropay-host>/claim#<code>`; the QR payload. Same
            visibility as `claimCode`.
        pdfUrl:
          type: string
          description: >-
            Absolute URL of `GET /transfer/letter/{id}/pdf`, built from the
            claim origin fixed at creation.
        escrow:
          description: >-
            The `LETTER_ESCROW` leg (sender → vault); `null` only if the row was
            never created.
          oneOf:
            - $ref: '#/components/schemas/LetterLeg'
            - type: 'null'
        claim:
          description: >-
            The `LETTER_CLAIM` leg (vault → recipient wallet); `null` until
            someone claims.
          oneOf:
            - allOf:
                - $ref: '#/components/schemas/LetterLeg'
                - type: object
                  required:
                    - claimedAt
                    - walletAddress
                  properties:
                    claimedAt:
                      type:
                        - string
                        - 'null'
                      format: date-time
                      description: Set when the letter reaches `CLAIMED`.
                    walletAddress:
                      type:
                        - string
                        - 'null'
                      description: The wallet the value was released to.
            - type: 'null'
        refund:
          description: >-
            The `LETTER_REFUND` leg (vault → sender address); `null` unless the
            letter was voided or expired.
          oneOf:
            - allOf:
                - $ref: '#/components/schemas/LetterLeg'
                - type: object
                  required:
                    - reason
                  properties:
                    reason:
                      type: string
                      enum:
                        - voided
                        - expired
            - type: 'null'
        mail:
          description: >-
            Fulfilment details; `null` until `POST /transfer/letter/{id}/mail`
            is attempted.
          oneOf:
            - type: object
              required:
                - provider
                - providerId
                - deliveryMethod
                - status
                - trackingNumber
                - expectedDeliveryDate
                - mailedAt
                - testMode
              properties:
                provider:
                  type: string
                  examples:
                    - lob
                providerId:
                  type:
                    - string
                    - 'null'
                  description: Lob letter id once accepted.
                deliveryMethod:
                  type:
                    - string
                    - 'null'
                  enum:
                    - standard
                    - tracked
                    - courier
                    - null
                status:
                  type:
                    - string
                    - 'null'
                  description: >-
                    Lob letter status (`processed`, `rendered`, `failed`),
                    refreshed on owner reads.
                trackingNumber:
                  type:
                    - string
                    - 'null'
                  description: >-
                    USPS tracking number for `tracked` letters (dummy in test
                    mode).
                expectedDeliveryDate:
                  type:
                    - string
                    - 'null'
                  description: Lob's estimate, `YYYY-MM-DD`.
                mailedAt:
                  type:
                    - string
                    - 'null'
                  format: date-time
                testMode:
                  type: boolean
                  description: >-
                    True when the deployment uses a Lob test key; nothing is
                    printed or mailed.
            - type: 'null'
        needsReview:
          type: boolean
          description: >-
            True when a leg could not be verified automatically; nothing moves
            until an operator reviews `error`.
        error:
          type:
            - string
            - 'null'
          description: Failure or review context for the most recent leg.
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
    LetterAddress:
      type: object
      description: Recipient postal address as stored, with the resolved country name.
      required:
        - line1
        - line2
        - landmark
        - city
        - region
        - postal
        - country
        - countryName
      properties:
        line1:
          type: string
        line2:
          type:
            - string
            - 'null'
        landmark:
          type:
            - string
            - 'null'
          description: Printed as `Near …` on the letter.
        city:
          type: string
        region:
          type:
            - string
            - 'null'
        postal:
          type:
            - string
            - 'null'
        country:
          type: string
          description: ISO 3166-1 alpha-2, upper-case.
          examples:
            - NG
        countryName:
          type: string
          examples:
            - Nigeria
    LetterLeg:
      type: object
      description: >-
        One on-chain leg of a letter (escrow, release or refund), linked to its
        transaction row.
      required:
        - transactionId
        - txHash
        - explorerUrl
        - status
        - verified
      properties:
        transactionId:
          type: string
          description: The `Transaction` id; read it with `GET /transactions/{id}`.
          examples:
            - cktxn0005abcd
        txHash:
          type:
            - string
            - 'null'
        explorerUrl:
          type:
            - string
            - 'null'
        status:
          type: string
          enum:
            - PENDING
            - CONFIRMED
            - SETTLING
            - SETTLED
            - FAILED
          description: The linked transaction's status.
        verified:
          type: boolean
          description: |
            True once the leg's `ConfidentialTransfer` event was decrypted and
            matched the letter amount. The letter only changes status after
            verification, so `CONFIRMED` + `verified: false` means the receipt
            is in and verification is pending.
  responses:
    Unauthorized:
      description: Missing or invalid credential.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            ok: false
            error:
              code: invalid_api_key
              message: Invalid API key.
    AccountDisabled:
      description: The account has been deactivated.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            ok: false
            error:
              code: account_disabled
              message: This account is disabled.
    LetterNotFound:
      description: >-
        No letter with this id in your account (or no letter matches the claim
        code).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            ok: false
            error:
              code: letter_not_found
              message: Letter not found.
    RateLimited:
      description: Rate limit exceeded.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            ok: false
            error:
              code: rate_limited
              message: Too many requests. Try again shortly.
    InternalError:
      description: Unexpected server error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            ok: false
            error:
              code: internal_error
              message: An unexpected error occurred.
  securitySchemes:
    apiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: aro_sk_…
      description: |
        AroPay API key, sent as `Authorization: Bearer aro_sk_…`. Created in
        the dashboard under Settings → API keys. Takes precedence over a
        session cookie when both are present.
      x-default: aro_sk_your_key_here
    sessionCookie:
      type: apiKey
      in: cookie
      name: aropay_session
      description: |
        Browser session cookie minted by `POST /auth/login` (or passkey
        login). httpOnly, `SameSite=Lax`, 24 h TTL. Endpoints marked
        **Session-only** accept only this credential and return
        `403 session_required` for API keys.

````