openapi: 3.0.3

# ============================================================================
# Tan Partner API — v1. The surface businesses integrate against.
#
# Separate from contract/openapi.yaml (the apps' v0 contract) on purpose: v0
# changes whenever the apps do; this one is a promise to other people's code
# and only ever grows. Additions only — a field is never removed or renamed and
# an enum never loses a member within v1.
#
# The backend generates its DTOs from this file
# (src/LogiGo.Api/generate-dtos.sh → Generated/PartnerDtos.cs); the developer
# page (stage 5) renders docs and code samples from it.
# ============================================================================

info:
  title: Tan Partner API
  version: 1.0.0
  description: >
    Create deliveries from your own system and follow every change — by
    reading the event feed, or on a webhook.


    **Keys.** Create keys in the partner cabinet (Tan's operator enables API
    access for the business first). A key starts `tan_live_` or `tan_test_`
    and is shown once. Send it as `Authorization: Bearer <key>`. Keep it on
    your server — never in a browser or a mobile app.


    **Test mode.** A `tan_test_` key works exactly like a live one, except that
    its orders are never shown to couriers, nothing is charged, and each order
    moves through the delivery statuses by itself (about every 20 seconds),
    producing the same events a live order would. Test and live orders never
    see each other.


    **Payment.** A live order is paid like any order from the cabinet: its
    price is held on the business's default saved card when it is created and
    charged on delivery. A carrier never sees an unpaid order. When the bank
    asks for 3-D Secure, the order is created but waits (`status: Created`,
    `paymentStatus: Pending`) until it is paid from the cabinet; the webhook
    tells you when it is published.


    **Errors** always have the same shape: `{code, message, details}`.
    `code` is stable — switch on it, not on `message`.


    **Limits.** 60 requests a minute per key; above that, 429 `RATE_LIMITED`
    with a `Retry-After` header.


    **Following orders.** Every order status change and every payment status
    change is an event. Two ways to get them — use either, or both:


    *The event feed* — no server of yours needed. Call `GET /events?after=<id
    of the last event you handled>` every few seconds (or minutes); it returns
    what happened since, oldest first. Events are kept 30 days.


    *A webhook* — set one HTTPS URL in the cabinet, and each event is POSTed
    there as it happens, as a `WebhookEvent`
    (see the schema), with the header
    `Tan-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256>` — the HMAC of
    `<t>.<raw body>` keyed with the webhook's signing secret. Answer 2xx within
    10 seconds; anything else is retried after 1 min, 5 min, 30 min, 2 h, 6 h
    and 24 h. Events can arrive more than once and out of order: use
    `id` to drop repeats and the order's `updatedAt` to keep the newest.
  contact:
    name: Tan
    url: https://tandelivery.ge

servers:
  - url: /partner/v1
    description: Relative to the Tan API host.

security:
  - apiKey: []

tags:
  - name: Account
  - name: Pickup points
  - name: Orders
  - name: Events

paths:
  /me:
    get:
      tags: [Account]
      operationId: getPartnerAccount
      summary: Who this key belongs to, and whether it is a test key.
      responses:
        '200':
          description: The business and the key's mode.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PartnerAccount'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/ApiDisabled'
        '429':
          $ref: '#/components/responses/RateLimited'

  /pickup-points:
    get:
      tags: [Pickup points]
      operationId: listPartnerPickupPoints
      summary: The business's pickup points (set up in the cabinet).
      responses:
        '200':
          description: Every pickup point, the default first.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PartnerPickupPointList'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/ApiDisabled'
        '429':
          $ref: '#/components/responses/RateLimited'

  /quotes:
    post:
      tags: [Orders]
      operationId: createPartnerQuote
      summary: The price of a delivery, without creating it.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PartnerQuoteRequest'
      responses:
        '200':
          description: The price an order with these details would have now.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PartnerQuote'
        '400':
          $ref: '#/components/responses/ValidationError'
        '422':
          $ref: '#/components/responses/AddressNotFound'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/ApiDisabled'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimited'

  /orders:
    get:
      tags: [Orders]
      operationId: listPartnerOrders
      summary: The business's orders made with keys of this key's mode, newest first.
      description: >
        Orders made in the cabinet or by import are included (they are live);
        a test key sees test orders only.
      parameters:
        - name: externalRef
          in: query
          required: false
          description: Your own order number, exactly.
          schema:
            type: string
            maxLength: 64
        - name: status
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/OrderStatus'
        - name: page
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            default: 1
        - name: pageSize
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 20
      responses:
        '200':
          description: One page of orders.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PartnerOrderList'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/ApiDisabled'
        '429':
          $ref: '#/components/responses/RateLimited'
    post:
      tags: [Orders]
      operationId: createPartnerOrder
      summary: Create a delivery — paid and published in the same call when it can be.
      description: >
        Live key: the price is held on the default saved card and the order is
        published at once; if the bank asks for 3-D Secure the order stays
        `Created` with `paymentStatus: Pending` until it is paid in the cabinet.
        Test key: nothing is charged and the order is published at once.


        Send an `Idempotency-Key` to make a retry safe: the same key returns
        the order the first request made (200, not 201) — a key is the
        order's for good, in its mode — and the same key with a different
        body is 409 `CONFLICT`.
        An `externalRef` already used by the business (in this mode) is 409
        `EXTERNAL_REF_TAKEN`.


        The recipient gets a text with a link to follow the delivery when a
        courier takes the order.
      parameters:
        - name: Idempotency-Key
          in: header
          required: false
          schema:
            type: string
            minLength: 1
            maxLength: 100
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PartnerCreateOrderRequest'
      responses:
        '200':
          description: A retry with the same Idempotency-Key — the order the first request made.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PartnerOrder'
        '201':
          description: Created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PartnerOrder'
        '400':
          $ref: '#/components/responses/ValidationError'
        '422':
          $ref: '#/components/responses/AddressNotFound'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/ApiDisabled'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          description: >
            EXTERNAL_REF_TAKEN, CONFLICT (an Idempotency-Key reused with a
            different body), PAYMENT_REQUIRED (payments are on and the business
            has no saved card), or BUSINESS_NOT_ACTIVE.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          $ref: '#/components/responses/RateLimited'

  /orders/{id}:
    parameters:
      - $ref: '#/components/parameters/OrderId'
    get:
      tags: [Orders]
      operationId: getPartnerOrder
      summary: One order.
      responses:
        '200':
          description: The order.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PartnerOrder'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/ApiDisabled'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimited'

  /orders/{id}/cancel:
    parameters:
      - $ref: '#/components/parameters/OrderId'
    post:
      tags: [Orders]
      operationId: cancelPartnerOrder
      summary: Cancel an order that has not been picked up yet.
      description: >
        Allowed until the courier has the parcel (`PickedUp`). A held payment is
        released. Cancelling an order that is already `Cancelled` returns it
        unchanged.
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PartnerCancelRequest'
      responses:
        '200':
          description: The cancelled order.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PartnerOrder'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/ApiDisabled'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          description: INVALID_TRANSITION — the parcel is already picked up, or the order ended.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          $ref: '#/components/responses/RateLimited'

  /events:
    get:
      tags: [Events]
      operationId: listPartnerEvents
      summary: What happened to this key's mode's orders since the event you name, oldest first.
      description: >
        The same events a webhook receives (`ping` aside), for this key's mode
        — a test key sees test events only. Start without `after` to read
        from the oldest kept (30 days); then always pass the `next` you were
        given. An event shows up here a few seconds after it happens, never
        out of order. With no webhook set nothing else is needed: poll this
        every few seconds, or as often as your system can wait.
      parameters:
        - name: after
          in: query
          required: false
          description: >
            The `id` of the last event you handled (the previous call's
            `next`). An id that is unknown — older than 30 days, or of another
            business or mode — is a 400 VALIDATION_ERROR: start again without
            it.
          schema:
            type: string
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 50
      responses:
        '200':
          description: Up to `limit` events after `after`, oldest first.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PartnerEventList'
        '400':
          $ref: '#/components/responses/ValidationError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/ApiDisabled'
        '429':
          $ref: '#/components/responses/RateLimited'

components:
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      bearerFormat: tan_live_… / tan_test_…

  parameters:
    OrderId:
      name: id
      in: path
      required: true
      schema:
        type: string

  responses:
    Unauthorized:
      description: UNAUTHORIZED — no key, an unknown key, or a revoked one.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    ApiDisabled:
      description: API_DISABLED — API access is switched off for the business.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: NOT_FOUND.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    ValidationError:
      description: VALIDATION_ERROR — `details.fields` names each bad field.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    AddressNotFound:
      description: >
        ADDRESS_NOT_FOUND — the drop-off came without coordinates and its
        address could not be placed on the map precisely enough to deliver to
        (no such street, or only a town). Send `lat` and `lng`, or a fuller
        address.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    RateLimited:
      description: RATE_LIMITED — more than 60 requests a minute on this key.
      headers:
        Retry-After:
          description: Seconds to wait.
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'

  schemas:
    Error:
      type: object
      required: [code, message]
      properties:
        code:
          type: string
          description: >
            Stable: UNAUTHORIZED, API_DISABLED, VALIDATION_ERROR, NOT_FOUND,
            CONFLICT, EXTERNAL_REF_TAKEN, PAYMENT_REQUIRED, BUSINESS_NOT_ACTIVE,
            INVALID_TRANSITION, ADDRESS_NOT_FOUND, RATE_LIMITED, INTERNAL_ERROR.
        message:
          type: string
        details:
          type: object
          nullable: true
          additionalProperties: true

    KeyMode:
      type: string
      enum: [live, test]

    PartnerAccount:
      type: object
      required: [businessId, name, mode]
      properties:
        businessId:
          type: string
        name:
          type: string
          description: The name couriers and recipients see as the sender.
        mode:
          $ref: '#/components/schemas/KeyMode'

    PartnerPickupPoint:
      type: object
      required: [id, name, address, lat, lng, isDefault]
      properties:
        id:
          type: string
        name:
          type: string
        address:
          type: string
        lat:
          type: number
          format: double
        lng:
          type: number
          format: double
        isDefault:
          type: boolean

    PartnerPickupPointList:
      type: object
      required: [items]
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/PartnerPickupPoint'

    OrderStatus:
      type: string
      description: >
        Happy path, in order: Created → Published → Accepted → EnRouteToPickup →
        NearPickup → AtPickup → PickedUp → InTransit → ArrivingAtDestination →
        AtDestination → Delivered. Ends: Delivered, Cancelled, Expired (nobody
        took it in time; only from Published).
      enum:
        - Created
        - Published
        - Accepted
        - EnRouteToPickup
        - NearPickup
        - AtPickup
        - PickedUp
        - InTransit
        - ArrivingAtDestination
        - AtDestination
        - Delivered
        - Cancelled
        - Expired

    PaymentStatus:
      type: string
      description: >
        Pending (waiting for 3-D Secure or the bank) → Authorized (held) →
        Captured (charged on delivery). Ends: Captured, Declined, Reversed
        (released on cancel/expiry), Expired.
      enum: [Pending, Authorized, Captured, Declined, Reversed, Expired]

    ServiceTier:
      type: string
      description: express — picked up at once, 1.5× the price.
      enum: [standard, express]

    PackageCategory:
      type: string
      enum: [document, parcel, food, fragile, electronics, other]

    Money:
      type: object
      required: [amount, currency]
      properties:
        amount:
          type: number
          format: double
          example: 12.5
        currency:
          type: string
          example: GEL

    PartnerDropoff:
      type: object
      description: >
        Where the parcel goes. `lat` and `lng` are optional: without them Tan
        finds `address` in `city` (Georgia only) and answers 422
        `ADDRESS_NOT_FOUND` when it cannot place it precisely enough to
        deliver. Coordinates you send are used as they are — send them when you
        have a map pin, they are always more exact. Responses always carry the
        coordinates the order is delivered to.
      required: [address, city]
      properties:
        address:
          type: string
          maxLength: 300
        city:
          type: string
          maxLength: 100
        lat:
          type: number
          format: double
          nullable: true
          description: Optional — see above.
        lng:
          type: number
          format: double
          nullable: true
          description: Optional — see above.
        entrance:
          type: string
          nullable: true
          maxLength: 20
        floor:
          type: string
          nullable: true
          maxLength: 20
        apartment:
          type: string
          nullable: true
          maxLength: 20
        note:
          type: string
          nullable: true
          maxLength: 300
          description: For the courier.

    PartnerRecipient:
      type: object
      required: [name, phone]
      properties:
        name:
          type: string
          maxLength: 120
        phone:
          type: string
          maxLength: 32
          description: A Georgian mobile number, any common spelling (stored as +9955XXXXXXXX).

    PartnerPackage:
      type: object
      required: [weightKg]
      properties:
        weightKg:
          type: number
          format: double
          description: Greater than 0, at most 30.
        category:
          allOf:
            - $ref: '#/components/schemas/PackageCategory'
          nullable: true
          description: Default parcel.
        description:
          type: string
          nullable: true
          maxLength: 200

    PartnerQuoteRequest:
      type: object
      required: [dropoff, package]
      properties:
        pickupPointId:
          type: string
          nullable: true
          description: Default — the business's default pickup point.
        dropoff:
          $ref: '#/components/schemas/PartnerQuoteDropoff'
        package:
          $ref: '#/components/schemas/PartnerPackage'
        insured:
          type: boolean
          default: false
        serviceTier:
          $ref: '#/components/schemas/ServiceTier'

    PartnerQuoteDropoff:
      type: object
      description: >
        Where the parcel would go: `lat` and `lng`, or — without them — an
        `address` (and its `city`) that Tan finds, as for an order. A checkout
        that only has the customer's typed address can price with it directly.
      properties:
        lat:
          type: number
          format: double
          nullable: true
        lng:
          type: number
          format: double
          nullable: true
        address:
          type: string
          nullable: true
          maxLength: 300
        city:
          type: string
          nullable: true
          maxLength: 100

    PartnerQuote:
      type: object
      required: [price, distanceKm]
      properties:
        price:
          $ref: '#/components/schemas/Money'
        distanceKm:
          type: number
          format: double

    PartnerCreateOrderRequest:
      type: object
      required: [recipient, dropoff, package]
      properties:
        externalRef:
          type: string
          nullable: true
          maxLength: 64
          description: Your own order number; unique within the business (test and live apart).
        pickupPointId:
          type: string
          nullable: true
          description: Default — the business's default pickup point.
        recipient:
          $ref: '#/components/schemas/PartnerRecipient'
        dropoff:
          $ref: '#/components/schemas/PartnerDropoff'
        package:
          $ref: '#/components/schemas/PartnerPackage'
        insured:
          type: boolean
          default: false
        declaredValue:
          type: number
          format: double
          nullable: true
          description: Required when insured; GEL.
        serviceTier:
          $ref: '#/components/schemas/ServiceTier'
        scheduledPickupAt:
          type: string
          format: date-time
          nullable: true
          description: A later pickup (standard only); null — as soon as a courier takes it.

    PartnerCancelRequest:
      type: object
      properties:
        reason:
          type: string
          nullable: true
          maxLength: 300

    PartnerStatusEvent:
      type: object
      required: [status, at]
      properties:
        status:
          $ref: '#/components/schemas/OrderStatus'
        at:
          type: string
          format: date-time

    PartnerOrder:
      type: object
      required:
        - id
        - reference
        - livemode
        - status
        - price
        - pickup
        - recipient
        - dropoff
        - package
        - insured
        - serviceTier
        - createdAt
        - updatedAt
        - statusHistory
      properties:
        id:
          type: string
        reference:
          type: string
          description: Tan's short order number, as the apps and invoices show it (e.g. #3FA9C2).
        externalRef:
          type: string
          nullable: true
        livemode:
          type: boolean
          description: False for an order made with a test key.
        status:
          $ref: '#/components/schemas/OrderStatus'
        paymentStatus:
          allOf:
            - $ref: '#/components/schemas/PaymentStatus'
          nullable: true
          description: Null when the order has no payment (test orders; payments switched off).
        carrier:
          allOf:
            - $ref: '#/components/schemas/PartnerCarrier'
          nullable: true
          description: >
            The courier delivering it. Null until a courier accepts the order
            (Published and before), and always null on test orders — test mode
            has no courier.
        price:
          $ref: '#/components/schemas/Money'
        pickup:
          $ref: '#/components/schemas/PartnerPickup'
        recipient:
          $ref: '#/components/schemas/PartnerRecipient'
        dropoff:
          $ref: '#/components/schemas/PartnerDropoff'
        package:
          $ref: '#/components/schemas/PartnerPackage'
        insured:
          type: boolean
        declaredValue:
          type: number
          format: double
          nullable: true
        serviceTier:
          $ref: '#/components/schemas/ServiceTier'
        scheduledPickupAt:
          type: string
          format: date-time
          nullable: true
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        statusHistory:
          type: array
          items:
            $ref: '#/components/schemas/PartnerStatusEvent'

    CarrierVehicle:
      type: string
      description: >
        How the courier gets around, from their profile. `motorcycle` covers
        mopeds and scooters.
      enum: [foot, bicycle, motorcycle, car, van]

    PartnerCarrier:
      type: object
      description: >
        The courier who accepted the order — as the sender sees them in the
        Tan app, so your support team or your customer can reach them.
      required: [name]
      properties:
        name:
          type: string
          description: First name and last initial, e.g. "Irakli G.".
          example: Irakli G.
        vehicle:
          allOf:
            - $ref: '#/components/schemas/CarrierVehicle'
          nullable: true
          description: Null when the courier has not said.
        phone:
          type: string
          nullable: true
          example: '+995599123456'
          description: >
            The courier's phone, E.164 — only while the order is running
            (accepted, not yet Delivered, Cancelled or Expired); null before
            and after, and when the courier's account has been closed. Like
            every field of the order it is as of the moment you read it: GET
            /orders, GET /orders/{id}, a webhook and GET /events all build the
            order when they are answered or sent, so an event read after the
            delivery carries no phone. Do not keep it past the delivery.

    PartnerPickup:
      type: object
      required: [address, lat, lng]
      properties:
        pickupPointId:
          type: string
          nullable: true
        address:
          type: string
        lat:
          type: number
          format: double
        lng:
          type: number
          format: double

    PartnerOrderList:
      type: object
      required: [items, page, pageSize, total]
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/PartnerOrder'
        page:
          type: integer
        pageSize:
          type: integer
        total:
          type: integer

    WebhookEventType:
      type: string
      description: >
        order.status_changed — the order moved (data.order.status is the new
        status); order.payment_changed — its payment did (data.order.paymentStatus);
        ping — sent from the cabinet's "send a test event".
      enum: [order.status_changed, order.payment_changed, ping]

    WebhookEvent:
      type: object
      description: >
        One event: the body POSTed to the business's webhook URL, and an item
        of GET /events.
      required: [id, type, livemode, createdAt, data]
      properties:
        id:
          type: string
          description: Unique per event; the same on every retry of it.
        type:
          $ref: '#/components/schemas/WebhookEventType'
        livemode:
          type: boolean
        createdAt:
          type: string
          format: date-time
        data:
          $ref: '#/components/schemas/WebhookEventData'

    WebhookEventData:
      type: object
      properties:
        status:
          allOf:
            - $ref: '#/components/schemas/OrderStatus'
          nullable: true
          description: order.status_changed — the status this event is about.
        paymentStatus:
          allOf:
            - $ref: '#/components/schemas/PaymentStatus'
          nullable: true
          description: order.payment_changed — the payment status this event is about.
        order:
          allOf:
            - $ref: '#/components/schemas/PartnerOrder'
          nullable: true
          description: >
            The order as it is when the event is sent or read (it may have
            moved on since — a retry carries the newest state); null for ping.

    PartnerEventList:
      type: object
      required: [data, hasMore]
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/WebhookEvent'
        hasMore:
          type: boolean
          description: More events are waiting — call again with `next` right away.
        next:
          type: string
          nullable: true
          description: >
            Pass as `after` on the next call: the last event's id, or the
            `after` you sent when there was nothing new. Null only when there
            has been no event at all yet.
