openapi: 3.1.0
info:
  title: FLOWR HAUS API for IMT (Impression Smart)
  version: 1.0.0
  summary: Endpoints FLOWR HAUS hosts for the IMT platform to call, for preorders picked up from IMT flower lockers.
  description: |
    FLOWR HAUS sells bouquets online for pickup from IMT flower vending machines. This document covers
    the endpoints on our side that the IMT platform calls. The calls we make to IMT are the ones in
    the IMT API document (2.1, 2.13, 2.15 and so on).

    ## Preorder flow

    1. Our florist restocks the machine on its own screen, and the stock syncs to the IMT cloud.
    2. A customer preorders on our website or app. We read the machine's channels with
       `/ei/get_device_info` (2.1) and push the order with `/ei/third_push/success_order` (2.13),
       passing the `orderNo`, a 6-digit `puCode`, the `commodityList` and, as `noticeUrl`, our
       **Delivery result** endpoint below. This locks the inventory.
    3. We text the customer their pickup code.
    4. The customer enters the code on the machine. The machine opens the locker and the platform
       calls our **Delivery result** endpoint (2.14).
    5. If the customer never comes, we cancel with `/ei/third_push/cancel_order` (2.15), which
       releases the inventory.

    We also host the **Pickup lookup** (2.21) and **Pickup notice** (2.22) endpoints, in case the
    platform looks pickup codes up from us instead of storing the `puCode` we pushed. Please tell us
    which of the two your platform uses for our machines.

    ## Products

    `thirdId` is our product ID, the same value we send in `/ei/sync_commodity` (2.4). It is a
    lowercase bouquet name such as `classic`, `signature` or `luxe`.

    ## Authentication

    Every request to us must do one of these:

    - **Carry our key in the URL.** We give you each endpoint's full URL with a `key` query
      parameter, for example `https://app.flowrhaus.com/api/imt/pickup?key=...`. Call exactly the
      URL we give you and add your own parameters to it. Nothing needs to be signed. Use this if
      your platform calls third-party URLs without signing them.
    - **Be signed** as described below.

    A request with a wrong `key` is refused, even if it is also signed.

    ## Signing

    A signed request is signed the same way as requests to IMT (section 1.2 of the IMT API
    document), with the same `encryptKey` and including `ownedUserId` and `timestamp`:

    1. Take every request parameter (query parameters for GET, top-level JSON fields for POST)
       except `sign`, and drop any with an empty value.
    2. Sort them by name and join them as `name=value&`.
    3. Append `key=<encryptKey>`.
    4. `sign` is the lowercase hex MD5 of that string.

    Arrays and objects in a JSON body (for example `commodityList`) are included as compact JSON
    with no spaces. If your platform signs nested fields another way, tell us and we will match it.

    `timestamp` may be in milliseconds or seconds. We reject requests whose timestamp is more than
    5 minutes from our clock, and unsigned requests that don't carry our key.

    ## Responses

    Following the IMT convention, we always answer with HTTP 200 and put the result in `code`:
    `200` is success and anything else is an error, with the reason in `msg`. The one exception is
    the Delivery result endpoint, which answers with the plain text `success` as section 2.14
    requires.

    ## Retries

    All three endpoints are safe to call again with the same data. A repeat returns the same answer
    and does not change anything twice.
  contact:
    name: FLOWR HAUS
    url: https://flowrhaus.com
servers:
  - url: https://app.flowrhaus.com/api/imt
    description: Production
# No header auth: every request carries its own sign, timestamp and ownedUserId (see Signing).
security: []
tags:
  - name: Preorder pickup
    description: Calls the IMT platform makes when a customer collects a preorder.
paths:
  /delivery:
    post:
      tags: [Preorder pickup]
      operationId: deliveryResult
      parameters:
        - $ref: '#/components/parameters/Key'
      summary: Delivery result for a pushed order (IMT 2.14)
      description: |
        The `noticeUrl` we pass to `/ei/third_push/success_order` (2.13). Call it after the machine
        opens the locker for a pushed order. `successCount` tells us how many items were actually
        delivered, so a failed or partial delivery is reported with a lower `successCount`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DeliveryResult'
            example:
              sign: 9b2c4f0e1a7d3c5b8e6f2a1d0c9b8a7e
              timestamp: 1764000000000
              ownedUserId: '100245'
              puCode: '482913'
              orderNo: FH-20261127-0042
              orderTime: 1763990000000
              rtuNumber: '8883327'
              commodityList:
                - buyCount: 1
                  cargoId: 8883327C4
                  commodityId: '100000000'
                  thirdId: signature
                  commodityName: Frost
                  successCount: 1
      responses:
        '200':
          description: The plain text `success` once we have recorded the result, or an error message.
          content:
            text/plain:
              schema:
                type: string
              examples:
                recorded:
                  value: success
                badSign:
                  value: invalid sign
  /pickup:
    get:
      tags: [Preorder pickup]
      operationId: getPickupOrder
      summary: Look up a preorder by pickup code (IMT 2.21)
      description: |
        Call this when a customer enters a pickup code on the machine, if the platform looks codes
        up from us. We return the order only if it belongs to that machine and has not been picked
        up, cancelled or refunded.

        Codes: `200` found, `400` code not 6 digits (or `rtuNumber` needed), `401` bad or old
        signature or wrong key, `403` order is for another machine, `404` no such code, `409` already picked up,
        `410` cancelled or refunded.
      parameters:
        - name: puCode
          in: query
          required: true
          description: The pickup code the customer entered.
          schema:
            type: string
            pattern: '^[0-9]{6}$'
          example: '482913'
        - name: rtuNumber
          in: query
          required: false
          description: The machine the code was entered on. Please send it, so a code only works on its own machine.
          schema:
            type: string
          example: '8883327'
        - $ref: '#/components/parameters/Key'
        - $ref: '#/components/parameters/OwnedUserId'
        - $ref: '#/components/parameters/Timestamp'
        - $ref: '#/components/parameters/Sign'
      responses:
        '200':
          description: The order, or an error in `code` and `msg`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PickupOrderResponse'
              examples:
                found:
                  value:
                    code: 200
                    msg: ok
                    data:
                      rtuNumber: '8883327'
                      name: Sarah
                      phone: '****0100'
                      drugList:
                        - thridId: signature
                          medName: Frost
                          count: 1
                notFound:
                  value:
                    code: 404
                    msg: Pickup code not found
                alreadyCollected:
                  value:
                    code: 409
                    msg: Already picked up
                wrongMachine:
                  value:
                    code: 403
                    msg: This order is for another machine
  /picked-up:
    post:
      tags: [Preorder pickup]
      operationId: notifyPickedUp
      parameters:
        - $ref: '#/components/parameters/Key'
      summary: Pickup notice (IMT 2.22)
      description: Call this after the locker opens for an order found with the pickup lookup. We mark the order collected.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PickupNotice'
            example:
              sign: 3f1e0d9c8b7a6f5e4d3c2b1a0f9e8d7c
              timestamp: 1764000000000
              ownedUserId: '100245'
              rtuNumber: '8883327'
              puCode: '482913'
      responses:
        '200':
          description: Recorded, or an error in `code` and `msg`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Result'
              examples:
                recorded:
                  value:
                    code: 200
                    msg: ok
                notFound:
                  value:
                    code: 404
                    msg: Pickup code not found
components:
  parameters:
    Key:
      name: key
      in: query
      required: false
      description: Our key, already in the URL we give you. Send it, or sign the request instead.
      schema:
        type: string
    OwnedUserId:
      name: ownedUserId
      in: query
      required: false
      description: Our operator ID on the IMT platform. Required when the request is signed.
      schema:
        type: string
    Timestamp:
      name: timestamp
      in: query
      required: false
      description: Time of the request, in milliseconds (seconds also accepted).
      schema:
        type: integer
        format: int64
    Sign:
      name: sign
      in: query
      required: false
      description: Request signature, required unless the URL carries our key. See Signing above.
      schema:
        type: string
        pattern: '^[0-9a-f]{32}$'
  schemas:
    Signed:
      type: object
      description: sign, timestamp and ownedUserId are required unless the URL carries our key.
      properties:
        sign:
          type: string
          pattern: '^[0-9a-f]{32}$'
          description: Request signature. See Signing above.
        timestamp:
          type: integer
          format: int64
          description: Time of the request, in milliseconds (seconds also accepted).
        ownedUserId:
          type: string
          description: Our operator ID on the IMT platform.
    DeliveryResult:
      allOf:
        - $ref: '#/components/schemas/Signed'
        - type: object
          required: [orderNo, rtuNumber, commodityList]
          properties:
            orderNo:
              type: string
              description: Our order number, as pushed in 2.13.
            puCode:
              type: string
              description: The pickup code, as pushed in 2.13.
            orderTime:
              type: integer
              format: int64
              description: When the locker opened, in milliseconds.
            rtuNumber:
              type: string
              description: Machine (device) number.
            commodityList:
              type: array
              minItems: 1
              items:
                $ref: '#/components/schemas/DeliveredItem'
    DeliveredItem:
      type: object
      required: [buyCount, successCount]
      properties:
        buyCount:
          type: integer
          minimum: 1
          description: How many were ordered.
        successCount:
          type: integer
          minimum: 0
          description: How many were actually delivered.
        cargoId:
          type: string
          description: The channel (locker) the item came from.
        commodityId:
          type: string
          description: IMT product ID.
        thirdId:
          type: string
          description: Our product ID.
        commodityName:
          type: string
    PickupNotice:
      allOf:
        - $ref: '#/components/schemas/Signed'
        - type: object
          required: [rtuNumber, puCode]
          properties:
            rtuNumber:
              type: string
              description: Machine (device) number.
            puCode:
              type: string
              description: The pickup code that was used.
    Result:
      type: object
      required: [code, msg]
      properties:
        code:
          type: integer
          description: 200 = success, anything else = error.
        msg:
          type: string
    PickupOrderResponse:
      allOf:
        - $ref: '#/components/schemas/Result'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/PickupOrder'
    PickupOrder:
      type: object
      required: [rtuNumber, drugList]
      properties:
        rtuNumber:
          type: string
          description: The machine the order is for.
        name:
          type: string
          description: Customer first name, for the machine screen.
        phone:
          type: string
          description: Last 4 digits of the customer's phone, masked.
        drugList:
          type: array
          description: Items in the order. The field names follow section 2.21 exactly, including the spelling `thridId`.
          items:
            type: object
            required: [thridId, count]
            properties:
              thridId:
                type: string
                description: Our product ID (the product's thirdId).
              medName:
                type: string
                description: Product name.
              count:
                type: integer
                minimum: 1
