openapi: 3.1.0
info:
  title: Wasabi API
  version: '1.0'
  description: |
    API พาร์ทเนอร์ของร้านค้าดิจิทัล **Wasabi**: แคตตาล็อกสมาชิก เกม และโค้ดเติมเงิน
    การสั่งซื้อ การหักเงินจากยอดคงเหลือของพาร์ทเนอร์ และการส่งมอบสินค้าเกิดขึ้นใน **คำขอเดียว** —
    การตอบกลับของ `POST /v1/orders` จะมีบัญชี โค้ด หรือการยืนยันการเติมเงินทันที

    ## การยืนยันตัวตน

    ทุกคำขอต้องมีคีย์ API ในเฮดเดอร์ `Authorization`:

    ```http
    Authorization: Bearer wsb_live_9f2c4a7e1b8d3f6a
    ```

    คีย์มีสองแบบ: `wsb_live_…` สำหรับใช้งานจริง และ `wsb_test_…` สำหรับทดสอบ
    สร้างและเพิกถอนคีย์ได้ในแดชบอร์ดพาร์ทเนอร์ ห้ามเปิดเผยคีย์
    ในโค้ดฝั่งหน้าเว็บ และห้ามเก็บคีย์ไว้ในรีโพสิทอรี

    ## Idempotency

    ส่งเฮดเดอร์ `Idempotency-Key` (สตริงที่ไม่ซ้ำใดก็ได้ ยาวไม่เกิน 64 ตัวอักษร เช่น UUID)
    เมื่อสร้างคำสั่งซื้อ คำขอซ้ำด้วยคีย์เดิมจะคืนคำสั่งซื้อที่สร้างไว้แล้ว
    และ **จะไม่หักเงินซ้ำ** — จึงส่งคำขอซ้ำได้อย่างปลอดภัยเมื่อเครือข่ายขัดข้อง
    คีย์ถูกเก็บไว้ 24 ชั่วโมง หากส่งเนื้อหาคำขอที่ต่างออกไปด้วยคีย์เดิม API จะคืน `409 idempotency_conflict`

    ## Webhook

    ระบุ URL ในแดชบอร์ดพาร์ทเนอร์ แล้ว Wasabi จะส่งเหตุการณ์ด้วย `POST`
    (`order.delivered`, `order.processing`, `order.failed`, `balance.topup`)
    ทุกคำขอมีลายเซ็น: เฮดเดอร์ `X-Wasabi-Signature` มีค่า HMAC-SHA256
    ของเนื้อหาคำขอ ซึ่งคำนวณด้วยความลับของ webhook (`whsec_…`) ในรูปแบบ hex

    ```
    X-Wasabi-Signature: t=1764763200,v1=5f8a3c…e91b
    ```

    ลายเซ็นคำนวณจากสตริง `{t}.{raw_body}` ให้เปรียบเทียบลายเซ็นแบบเวลาคงที่
    และปฏิเสธเหตุการณ์ที่เก่ากว่า 5 นาที หากเซิร์ฟเวอร์ของคุณไม่ตอบ `2xx` ระบบจะส่งซ้ำ
    โดยเว้นระยะเพิ่มขึ้นเรื่อย ๆ (1 นาที, 5 นาที, 30 นาที, 2 ชม., 6 ชม.…) นานสูงสุด 24 ชั่วโมงจนกว่าจะได้รับ `2xx`
    เหตุการณ์อาจมาซ้ำได้ — ให้ประมวลผลแบบ idempotent ตาม `data.id`

    ## โหมดทดสอบ

    เมื่อใช้คีย์ `wsb_test_…` API จะทำงานเหมือนโหมดจริงทุกอย่าง แต่ไม่มีการหักเงินหรือซื้อสินค้าจริง:
    คำสั่งซื้อจะคืนข้อมูลทดสอบ ยอดคงเหลือเป็นแบบเสมือน และ webhook ถูกส่งไปยัง URL ทดสอบ
    ข้อมูลทดสอบและข้อมูลจริงแยกจากกันโดยสมบูรณ์

    ## MCP

    มีเซิร์ฟเวอร์ MCP สำหรับเอเจนต์ AI (Claude, ChatGPT, Cursor และอื่น ๆ):

    ```
    https://api.wasabi.guru/mcp
    ```

    ยืนยันตัวตนด้วยคีย์ Bearer เดียวกัน เครื่องมือ:

    | เครื่องมือ | ทำอะไร |
    |---|---|
    | `search_products` | ค้นหาแคตตาล็อกพร้อมตัวกรองหมวดหมู่ |
    | `create_order` | สร้างคำสั่งซื้อและส่งมอบสินค้า |
    | `get_order` | สถานะและรายละเอียดคำสั่งซื้อ |
    | `get_balance` | ยอดคงเหลือปัจจุบันของพาร์ทเนอร์ |

    แนะนำให้เอเจนต์ใช้คีย์ทดสอบจนกว่าขั้นตอนจะทำงานได้สมบูรณ์
  contact:
    name: ฝ่ายสนับสนุน Wasabi
    url: https://wasabi.guru
servers:
- url: https://api.wasabi.guru
  description: โหมดจริงและโหมดทดสอบ (กำหนดโดยคีย์)
security:
- bearerAuth: []
tags:
- name: แคตตาล็อก
  description: สินค้า ราคา สถานะสินค้า และข้อมูลที่จำเป็นสำหรับการสั่งซื้อ
- name: คำสั่งซื้อ
  description: สร้างคำสั่งซื้อพร้อมส่งมอบทันทีและดูประวัติ
- name: ยอดคงเหลือ
  description: ยอดคงเหลือของพาร์ทเนอร์และประวัติธุรกรรม
- name: Webhook
  description: เหตุการณ์ที่ Wasabi ส่งไปยังเซิร์ฟเวอร์ของคุณ
paths:
  /v1/products:
    get:
      tags:
      - แคตตาล็อก
      operationId: listProducts
      summary: รายการสินค้า
      description: คืนสินค้าในแคตตาล็อกพร้อมราคาสำหรับพาร์ทเนอร์ รองรับการกรองตามหมวดหมู่ การค้นหา และการแบ่งหน้า
      parameters:
      - name: category
        in: query
        description: หมวดหมู่สินค้า
        schema:
          $ref: '#/components/schemas/Category'
        example: ai
      - name: q
        in: query
        description: ค้นหาตามชื่อ
        schema:
          type: string
        example: chatgpt
      - name: page
        in: query
        description: หมายเลขหน้า เริ่มจาก 1
        schema:
          type: integer
          minimum: 1
          default: 1
      - name: limit
        in: query
        description: จำนวนสินค้าต่อหน้า
        schema:
          type: integer
          minimum: 1
          maximum: 100
          default: 20
      responses:
        '200':
          description: รายการสินค้า
          content:
            application/json:
              schema:
                type: object
                required:
                - data
                - page
                - limit
                - total
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Product'
                  page:
                    type: integer
                    example: 1
                  limit:
                    type: integer
                    example: 20
                  total:
                    type: integer
                    description: จำนวนสินค้าทั้งหมดตามตัวกรอง
                    example: 3
              example:
                data:
                - id: chatgpt-plus-1m
                  name: ChatGPT Plus — 1 เดือน
                  category: ai
                  type: account
                  price: 1990
                  currency: RUB
                  in_stock: true
                  fields:
                  - name: email
                    label: อีเมลของบัญชี
                    type: email
                    required: true
                - id: claude-pro-1m
                  name: Claude Pro — 1 เดือน
                  category: ai
                  type: account
                  price: 2190
                  currency: RUB
                  in_stock: true
                  fields:
                  - name: email
                    label: อีเมลของบัญชี
                    type: email
                    required: true
                - id: midjourney-basic-1m
                  name: Midjourney Basic — 1 เดือน
                  category: ai
                  type: code
                  price: 1090
                  currency: RUB
                  in_stock: false
                  fields: []
                page: 1
                limit: 20
                total: 3
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimited'
  /v1/products/{id}:
    get:
      tags:
      - แคตตาล็อก
      operationId: getProduct
      summary: สินค้าตาม ID
      description: คืนข้อมูลสินค้าพร้อมราคา สถานะสินค้า และรายการฟิลด์ที่ต้องส่งเมื่อสั่งซื้อ
      parameters:
      - name: id
        in: path
        required: true
        description: ID สินค้า
        schema:
          type: string
        example: steam-topup
      responses:
        '200':
          description: สินค้า
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Product'
              examples:
                topup:
                  summary: เติมเงิน Steam
                  value:
                    id: steam-topup
                    name: เติมเงิน Steam
                    category: topup
                    type: topup
                    price: null
                    currency: RUB
                    min_amount: 100
                    max_amount: 50000
                    fee_percent: 6
                    in_stock: true
                    fields:
                    - name: login
                      label: ล็อกอิน Steam
                      type: string
                      required: true
                    - name: region
                      label: ภูมิภาคของบัญชี
                      type: string
                      required: false
                      enum:
                      - RU
                      - KZ
                      - CIS
                account:
                  summary: ChatGPT Plus
                  value:
                    id: chatgpt-plus-1m
                    name: ChatGPT Plus — 1 เดือน
                    category: ai
                    type: account
                    price: 1990
                    currency: RUB
                    in_stock: true
                    fields:
                    - name: email
                      label: อีเมลของบัญชี
                      type: email
                      required: true
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimited'
  /v1/orders:
    post:
      tags:
      - คำสั่งซื้อ
      operationId: createOrder
      summary: สร้างคำสั่งซื้อ
      description: |
        สร้างคำสั่งซื้อ หักเงินจากยอดคงเหลือของพาร์ทเนอร์ และส่งมอบสินค้าทันที
        สำหรับสินค้าส่วนใหญ่ การตอบกลับจะมีสถานะ `delivered` และมี `item` ครบถ้วน
        หากการส่งมอบต้องใช้เวลา คำสั่งซื้อจะคืนสถานะ `processing` — สถานะสุดท้ายจะส่งมาทาง webhook
        หรือผ่าน `GET /v1/orders/{id}` หากส่งมอบไม่สำเร็จ เงินจะคืนเข้ายอดคงเหลือ (`refunded`)
      parameters:
      - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateOrderRequest'
            examples:
              chatgpt:
                summary: ChatGPT Plus 1 เดือน
                value:
                  product: chatgpt-plus-1m
                  qty: 1
                  fields:
                    email: anna@example.com
                  external_id: shop-10482
              steam:
                summary: เติมเงิน Steam 1000 ₽
                value:
                  product: steam-topup
                  amount: 1000
                  fields:
                    login: player_one
                  external_id: shop-10483
      responses:
        '201':
          description: สร้างคำสั่งซื้อแล้ว
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Order'
              examples:
                chatgpt:
                  summary: ส่งมอบบัญชี ChatGPT Plus แล้ว
                  value:
                    id: ord_8KQ2
                    status: delivered
                    product: chatgpt-plus-1m
                    qty: 1
                    external_id: shop-10482
                    charged: 1990
                    currency: RUB
                    balance: 86400
                    item:
                      type: account
                      login: anna@example.com
                      password: Wq7!rP2m-x9L
                      expires_at: '2027-01-03T12:00:00Z'
                      instructions: เข้าสู่ระบบ chatgpt.com ด้วยข้อมูลนี้แล้วเปลี่ยนรหัสผ่าน
                    created_at: '2026-12-03T12:00:00Z'
                    delivered_at: '2026-12-03T12:00:02Z'
                steam:
                  summary: เติมเงิน Steam สำเร็จแล้ว
                  value:
                    id: ord_8KQ3
                    status: delivered
                    product: steam-topup
                    qty: 1
                    amount: 1000
                    external_id: shop-10483
                    charged: 1060
                    currency: RUB
                    balance: 85340
                    item:
                      type: topup
                      login: player_one
                      amount: 1000
                      currency: RUB
                    created_at: '2026-12-03T12:05:00Z'
                    delivered_at: '2026-12-03T12:05:04Z'
        '200':
          description: คำขอซ้ำด้วย `Idempotency-Key` เดิม — คืนคำสั่งซื้อที่สร้างไว้ก่อนหน้า ไม่มีการหักเงินซ้ำ
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Order'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/InsufficientBalance'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/IdempotencyConflict'
        '429':
          $ref: '#/components/responses/RateLimited'
    get:
      tags:
      - คำสั่งซื้อ
      operationId: listOrders
      summary: รายการคำสั่งซื้อ
      description: คืนคำสั่งซื้อของพาร์ทเนอร์จากใหม่ไปเก่า แบ่งหน้าแบบเคอร์เซอร์ — ส่ง `next_cursor` จากการตอบกลับไปในพารามิเตอร์ `cursor`
      parameters:
      - name: status
        in: query
        description: กรองตามสถานะ
        schema:
          $ref: '#/components/schemas/OrderStatus'
      - $ref: '#/components/parameters/Cursor'
      - $ref: '#/components/parameters/Limit'
      responses:
        '200':
          description: หน้ารายการคำสั่งซื้อ
          content:
            application/json:
              schema:
                type: object
                required:
                - data
                - has_more
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Order'
                  has_more:
                    type: boolean
                  next_cursor:
                    type:
                    - string
                    - 'null'
              example:
                data:
                - id: ord_8KQ3
                  status: delivered
                  product: steam-topup
                  qty: 1
                  amount: 1000
                  external_id: shop-10483
                  charged: 1060
                  currency: RUB
                  balance: 85340
                  item:
                    type: topup
                    login: player_one
                    amount: 1000
                    currency: RUB
                  created_at: '2026-12-03T12:05:00Z'
                  delivered_at: '2026-12-03T12:05:04Z'
                - id: ord_8KQ2
                  status: delivered
                  product: chatgpt-plus-1m
                  qty: 1
                  external_id: shop-10482
                  charged: 1990
                  currency: RUB
                  balance: 86400
                  item:
                    type: account
                    login: anna@example.com
                    password: Wq7!rP2m-x9L
                    expires_at: '2027-01-03T12:00:00Z'
                  created_at: '2026-12-03T12:00:00Z'
                  delivered_at: '2026-12-03T12:00:02Z'
                has_more: true
                next_cursor: ord_8KQ1
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimited'
  /v1/orders/{id}:
    get:
      tags:
      - คำสั่งซื้อ
      operationId: getOrder
      summary: คำสั่งซื้อตาม ID
      description: คืนคำสั่งซื้อพร้อมสถานะปัจจุบันและสินค้าที่ส่งมอบแล้ว
      parameters:
      - name: id
        in: path
        required: true
        description: ID คำสั่งซื้อ
        schema:
          type: string
        example: ord_8KQ2
      responses:
        '200':
          description: คำสั่งซื้อ
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Order'
              examples:
                code:
                  summary: ส่งมอบโค้ดแล้ว
                  value:
                    id: ord_8KR7
                    status: delivered
                    product: spotify-premium-3m
                    qty: 1
                    external_id: shop-10501
                    charged: 1290
                    currency: RUB
                    balance: 84050
                    item:
                      type: code
                      code: SPOT-7QH4-K9XM-2LPA
                      expires_at: '2027-12-31T23:59:59Z'
                      instructions: เปิดใช้งานโค้ดที่ spotify.com/redeem
                    created_at: '2026-12-03T13:10:00Z'
                    delivered_at: '2026-12-03T13:10:01Z'
                processing:
                  summary: คำสั่งซื้อกำลังดำเนินการ
                  value:
                    id: ord_8KR8
                    status: processing
                    product: steam-topup
                    qty: 1
                    amount: 500
                    external_id: shop-10502
                    charged: 530
                    currency: RUB
                    balance: 83520
                    item: null
                    created_at: '2026-12-03T13:12:00Z'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/RateLimited'
  /v1/balance:
    get:
      tags:
      - ยอดคงเหลือ
      operationId: getBalance
      summary: ยอดคงเหลือปัจจุบัน
      description: คืนยอดคงเหลือที่ใช้ได้ของพาร์ทเนอร์และยอดที่กันไว้สำหรับคำสั่งซื้อที่กำลังดำเนินการ
      responses:
        '200':
          description: ยอดคงเหลือ
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Balance'
              example:
                balance: 85340
                currency: RUB
                held: 530
                updated_at: '2026-12-03T12:05:04Z'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimited'
  /v1/balance/transactions:
    get:
      tags:
      - ยอดคงเหลือ
      operationId: listBalanceTransactions
      summary: ประวัติธุรกรรม
      description: การเติมเงิน การหักเงินค่าคำสั่งซื้อ และการคืนเงิน เรียงจากใหม่ไปเก่า แบ่งหน้าแบบเคอร์เซอร์
      parameters:
      - name: type
        in: query
        description: กรองตามประเภทธุรกรรม
        schema:
          $ref: '#/components/schemas/TransactionType'
      - $ref: '#/components/parameters/Cursor'
      - $ref: '#/components/parameters/Limit'
      responses:
        '200':
          description: หน้ารายการธุรกรรม
          content:
            application/json:
              schema:
                type: object
                required:
                - data
                - has_more
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Transaction'
                  has_more:
                    type: boolean
                  next_cursor:
                    type:
                    - string
                    - 'null'
              example:
                data:
                - id: txn_5Hd2
                  type: charge
                  amount: -1060
                  currency: RUB
                  balance_after: 85340
                  order_id: ord_8KQ3
                  description: เติมเงิน Steam — 1000 ₽
                  created_at: '2026-12-03T12:05:00Z'
                - id: txn_5Hd1
                  type: charge
                  amount: -1990
                  currency: RUB
                  balance_after: 86400
                  order_id: ord_8KQ2
                  description: ChatGPT Plus — 1 เดือน
                  created_at: '2026-12-03T12:00:00Z'
                - id: txn_5Hc9
                  type: topup
                  amount: 50000
                  currency: RUB
                  balance_after: 88390
                  order_id: null
                  description: 'เติมยอดคงเหลือตามใบแจ้งหนี้ #2471'
                  created_at: '2026-12-02T09:30:00Z'
                has_more: false
                next_cursor: null
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimited'
webhooks:
  order.delivered:
    post:
      tags:
      - Webhook
      operationId: webhookOrderDelivered
      summary: ส่งมอบคำสั่งซื้อแล้ว
      description: ส่งมอบสินค้าสำเร็จ ส่งทั้งสำหรับคำสั่งซื้อที่ส่งมอบทันทีและคำสั่งซื้อที่อยู่ระหว่างดำเนินการ
      parameters:
      - $ref: '#/components/parameters/WebhookSignature'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OrderEvent'
            example:
              event: order.delivered
              created_at: '2026-12-03T12:05:04Z'
              data:
                id: ord_8KQ3
                status: delivered
                product: steam-topup
                qty: 1
                amount: 1000
                external_id: shop-10483
                charged: 1060
                currency: RUB
                balance: 85340
                item:
                  type: topup
                  login: player_one
                  amount: 1000
                  currency: RUB
                created_at: '2026-12-03T12:05:00Z'
                delivered_at: '2026-12-03T12:05:04Z'
      responses:
        '200':
          description: รับเหตุการณ์แล้ว การตอบกลับ `2xx` ใด ๆ จะหยุดการส่งซ้ำ
  order.processing:
    post:
      tags:
      - Webhook
      operationId: webhookOrderProcessing
      summary: คำสั่งซื้อกำลังดำเนินการ
      description: การส่งมอบสินค้าต้องใช้เวลา ยอดเงินถูกกันไว้แล้ว รอ `order.delivered` หรือ `order.failed`
      parameters:
      - $ref: '#/components/parameters/WebhookSignature'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OrderEvent'
            example:
              event: order.processing
              created_at: '2026-12-03T13:12:00Z'
              data:
                id: ord_8KR8
                status: processing
                product: steam-topup
                qty: 1
                amount: 500
                external_id: shop-10502
                charged: 530
                currency: RUB
                balance: 83520
                item: null
                created_at: '2026-12-03T13:12:00Z'
      responses:
        '200':
          description: รับเหตุการณ์แล้ว
  order.failed:
    post:
      tags:
      - Webhook
      operationId: webhookOrderFailed
      summary: คำสั่งซื้อไม่สำเร็จ
      description: ส่งมอบสินค้าไม่สำเร็จ ยอดที่หักไปจะคืนเข้ายอดคงเหลือ และคำสั่งซื้อเปลี่ยนเป็นสถานะ `refunded`
      parameters:
      - $ref: '#/components/parameters/WebhookSignature'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OrderEvent'
            example:
              event: order.failed
              created_at: '2026-12-03T13:20:00Z'
              data:
                id: ord_8KR8
                status: refunded
                product: steam-topup
                qty: 1
                amount: 500
                external_id: shop-10502
                charged: 0
                currency: RUB
                balance: 84050
                item: null
                failure:
                  code: account_not_found
                  message: ไม่พบบัญชี Steam ที่มีล็อกอิน player_two
                created_at: '2026-12-03T13:12:00Z'
      responses:
        '200':
          description: รับเหตุการณ์แล้ว
  balance.topup:
    post:
      tags:
      - Webhook
      operationId: webhookBalanceTopup
      summary: เติมยอดคงเหลือแล้ว
      description: มีการเติมเงินเข้ายอดคงเหลือของพาร์ทเนอร์
      parameters:
      - $ref: '#/components/parameters/WebhookSignature'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BalanceTopupEvent'
            example:
              event: balance.topup
              created_at: '2026-12-02T09:30:00Z'
              data:
                id: txn_5Hc9
                type: topup
                amount: 50000
                currency: RUB
                balance_after: 88390
                order_id: null
                description: 'เติมยอดคงเหลือตามใบแจ้งหนี้ #2471'
                created_at: '2026-12-02T09:30:00Z'
      responses:
        '200':
          description: รับเหตุการณ์แล้ว
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: wsb_live_… / wsb_test_…
      description: คีย์ API ของพาร์ทเนอร์ `wsb_live_…` สำหรับใช้งานจริง `wsb_test_…` สำหรับทดสอบ
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      description: คีย์คำขอที่ไม่ซ้ำ การส่งซ้ำด้วยคีย์เดิมจะคืนคำสั่งซื้อเดิมโดยไม่หักเงินซ้ำ
      schema:
        type: string
        maxLength: 64
      example: 3f1c9a52-7d4e-4b8a-9c21-6e0f5b7a8d13
    Cursor:
      name: cursor
      in: query
      description: เคอร์เซอร์ของหน้าถัดไป (`next_cursor` จากการตอบกลับก่อนหน้า)
      schema:
        type: string
      example: ord_8KQ1
    Limit:
      name: limit
      in: query
      description: จำนวนรายการต่อหน้า
      schema:
        type: integer
        minimum: 1
        maximum: 100
        default: 20
    WebhookSignature:
      name: X-Wasabi-Signature
      in: header
      required: true
      description: 'ลายเซ็น HMAC-SHA256: `t={unix_time},v1={hex(hmac_sha256(secret, t + "." + raw_body))}`'
      schema:
        type: string
      example: t=1764763504,v1=5f8a3c0d2b9e47a1c6f3e8d0b5a7294c1e6f8a3d0b2c9e47a15f8a3c0d2be91b
  schemas:
    Category:
      type: string
      description: |
        หมวดหมู่สินค้า:
        - `ai` — เครื่องมือ AI
        - `music` — เพลง
        - `games` — เกม
        - `topup` — เติมเงิน
        - `telegram` — Telegram
        - `study` — การเรียน
      enum:
      - ai
      - music
      - games
      - topup
      - telegram
      - study
    ProductType:
      type: string
      description: |
        วิธีส่งมอบสินค้า:
        - `account` — ข้อมูลบัญชี (ล็อกอินและรหัสผ่าน)
        - `code` — โค้ดเปิดใช้งาน
        - `topup` — เติมเงินให้ล็อกอินที่ระบุ
      enum:
      - account
      - code
      - topup
    ProductField:
      type: object
      description: ฟิลด์ที่ต้องส่งใน `fields` เมื่อสั่งซื้อ
      required:
      - name
      - label
      - type
      - required
      properties:
        name:
          type: string
          description: คีย์ในออบเจ็กต์ `fields`
          example: login
        label:
          type: string
          description: ชื่อฟิลด์ที่แสดงให้ผู้ซื้อ
          example: ล็อกอิน Steam
        type:
          type: string
          enum:
          - string
          - email
          - phone
          example: string
        required:
          type: boolean
          example: true
        enum:
          type: array
          description: ค่าที่อนุญาต หากรายการถูกจำกัด
          items:
            type: string
          example:
          - RU
          - KZ
          - CIS
    Product:
      type: object
      required:
      - id
      - name
      - category
      - type
      - price
      - currency
      - in_stock
      - fields
      properties:
        id:
          type: string
          description: ID สินค้า
          example: chatgpt-plus-1m
        name:
          type: string
          example: ChatGPT Plus — 1 เดือน
        category:
          $ref: '#/components/schemas/Category'
        type:
          $ref: '#/components/schemas/ProductType'
        price:
          type:
          - number
          - 'null'
          description: ราคาสำหรับพาร์ทเนอร์เป็นรูเบิล เป็น `null` สำหรับการเติมเงิน — ยอดรวมคำนวณจาก `amount` รวม `fee_percent`
          example: 1990
        currency:
          type: string
          const: RUB
          example: RUB
        min_amount:
          type: number
          description: เฉพาะ `topup` — ยอดเติมเงินขั้นต่ำ
          example: 100
        max_amount:
          type: number
          description: เฉพาะ `topup` — ยอดเติมเงินสูงสุด
          example: 50000
        fee_percent:
          type: number
          description: เฉพาะ `topup` — ค่าธรรมเนียมเป็นเปอร์เซ็นต์ของยอดเงิน
          example: 6
        in_stock:
          type: boolean
          description: สินค้ามีพร้อมจำหน่ายตอนนี้หรือไม่
          example: true
        fields:
          type: array
          description: ข้อมูลที่ต้องใช้ในการสั่งซื้อ (อีเมล ล็อกอิน ภูมิภาค…)
          items:
            $ref: '#/components/schemas/ProductField'
    CreateOrderRequest:
      type: object
      required:
      - product
      properties:
        product:
          type: string
          description: ID สินค้า
          example: steam-topup
        qty:
          type: integer
          minimum: 1
          maximum: 50
          default: 1
          description: จำนวน สำหรับการเติมเงินเป็น 1 เสมอ
          example: 1
        amount:
          type: number
          description: ยอดเติมเงินเป็นรูเบิล จำเป็นสำหรับสินค้าประเภท `topup`
          example: 1000
        fields:
          type: object
          description: ข้อมูลสำหรับการส่งมอบ — คีย์จาก `Product.fields`
          additionalProperties:
            type: string
          example:
            login: player_one
        external_id:
          type: string
          maxLength: 128
          description: รหัสคำสั่งซื้อของคุณ — จะส่งกลับในการตอบกลับและ webhook
          example: shop-10483
    OrderStatus:
      type: string
      description: |
        - `processing` — กันยอดเงินแล้ว กำลังส่งมอบสินค้า
        - `delivered` — ส่งมอบสินค้าแล้ว
        - `failed` — ส่งมอบไม่สำเร็จ
        - `refunded` — คืนเงินเข้ายอดคงเหลือแล้ว
      enum:
      - processing
      - delivered
      - failed
      - refunded
    OrderItem:
      type: object
      description: สินค้าที่ส่งมอบแล้ว ชุดฟิลด์ขึ้นอยู่กับ `type`
      required:
      - type
      properties:
        type:
          $ref: '#/components/schemas/ProductType'
        code:
          type: string
          description: โค้ดเปิดใช้งาน (`code`)
          example: SPOT-7QH4-K9XM-2LPA
        login:
          type: string
          description: ล็อกอินของบัญชี (`account`) หรือบัญชีที่ถูกเติมเงิน (`topup`)
          example: anna@example.com
        password:
          type: string
          description: รหัสผ่านบัญชี (`account`)
          example: Wq7!rP2m-x9L
        amount:
          type: number
          description: ยอดเงินที่เติมเข้า (`topup`)
          example: 1000
        currency:
          type: string
          example: RUB
        expires_at:
          type:
          - string
          - 'null'
          format: date-time
          description: วันหมดอายุของสมาชิกหรือโค้ด
          example: '2027-01-03T12:00:00Z'
        instructions:
          type: string
          description: คำแนะนำสำหรับผู้ซื้อ
          example: เข้าสู่ระบบ chatgpt.com ด้วยข้อมูลนี้แล้วเปลี่ยนรหัสผ่าน
    Order:
      type: object
      required:
      - id
      - status
      - product
      - qty
      - charged
      - currency
      - balance
      - created_at
      properties:
        id:
          type: string
          example: ord_8KQ2
        status:
          $ref: '#/components/schemas/OrderStatus'
        product:
          type: string
          example: chatgpt-plus-1m
        qty:
          type: integer
          example: 1
        amount:
          type: number
          description: ยอดเติมเงิน (สำหรับ `topup`)
          example: 1000
        external_id:
          type:
          - string
          - 'null'
          example: shop-10482
        charged:
          type: number
          description: หักจากยอดคงเหลือ, ₽
          example: 1990
        currency:
          type: string
          example: RUB
        balance:
          type: number
          description: ยอดคงเหลือของพาร์ทเนอร์หลังทำรายการ, ₽
          example: 86400
        item:
          description: สินค้าที่ส่งมอบแล้ว เป็น `null` จนกว่าจะส่งมอบคำสั่งซื้อ
          oneOf:
          - $ref: '#/components/schemas/OrderItem'
          - type: 'null'
        failure:
          type: object
          description: สาเหตุที่ไม่สำเร็จ (สำหรับ `failed` และ `refunded`)
          properties:
            code:
              type: string
              example: account_not_found
            message:
              type: string
              example: ไม่พบบัญชี Steam ที่มีล็อกอิน player_two
        created_at:
          type: string
          format: date-time
          example: '2026-12-03T12:00:00Z'
        delivered_at:
          type: string
          format: date-time
          example: '2026-12-03T12:00:02Z'
    Balance:
      type: object
      required:
      - balance
      - currency
      - held
      properties:
        balance:
          type: number
          description: ใช้สั่งซื้อได้, ₽
          example: 85340
        currency:
          type: string
          example: RUB
        held:
          type: number
          description: ยอดที่กันไว้สำหรับคำสั่งซื้อที่กำลังดำเนินการ, ₽
          example: 530
        updated_at:
          type: string
          format: date-time
          example: '2026-12-03T12:05:04Z'
    TransactionType:
      type: string
      description: |
        - `topup` — เติมเงินเข้ายอดคงเหลือ
        - `charge` — หักเงินค่าคำสั่งซื้อ
        - `refund` — คืนเงินสำหรับคำสั่งซื้อที่ไม่สำเร็จ
      enum:
      - topup
      - charge
      - refund
    Transaction:
      type: object
      required:
      - id
      - type
      - amount
      - currency
      - balance_after
      - created_at
      properties:
        id:
          type: string
          example: txn_5Hd2
        type:
          $ref: '#/components/schemas/TransactionType'
        amount:
          type: number
          description: ยอดธุรกรรม, ₽ การหักเงินเป็นค่าติดลบ
          example: -1060
        currency:
          type: string
          example: RUB
        balance_after:
          type: number
          example: 85340
        order_id:
          type:
          - string
          - 'null'
          example: ord_8KQ3
        description:
          type: string
          example: เติมเงิน Steam — 1000 ₽
        created_at:
          type: string
          format: date-time
          example: '2026-12-03T12:05:00Z'
    OrderEvent:
      type: object
      required:
      - event
      - created_at
      - data
      properties:
        event:
          type: string
          enum:
          - order.delivered
          - order.processing
          - order.failed
          example: order.delivered
        created_at:
          type: string
          format: date-time
          example: '2026-12-03T12:05:04Z'
        data:
          $ref: '#/components/schemas/Order'
    BalanceTopupEvent:
      type: object
      required:
      - event
      - created_at
      - data
      properties:
        event:
          type: string
          const: balance.topup
        created_at:
          type: string
          format: date-time
          example: '2026-12-02T09:30:00Z'
        data:
          $ref: '#/components/schemas/Transaction'
    Error:
      type: object
      required:
      - error
      properties:
        error:
          type: object
          required:
          - code
          - message
          properties:
            code:
              type: string
              description: รหัสข้อผิดพลาดสำหรับโปรแกรม
              example: insufficient_balance
            message:
              type: string
              description: คำอธิบายข้อผิดพลาดสำหรับนักพัฒนา
              example: ยอดคงเหลือไม่พอ
  responses:
    BadRequest:
      description: คำขอไม่ถูกต้อง — ขาดฟิลด์หรือกรอกฟิลด์ไม่ถูกต้อง
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: invalid_fields
              message: ต้องระบุฟิลด์ fields.login สำหรับสินค้า steam-topup
    Unauthorized:
      description: ไม่ได้ส่งคีย์ หรือคีย์ถูกเพิกถอนหรือไม่ถูกต้อง
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: unauthorized
              message: คีย์ API ไม่ถูกต้องหรือถูกเพิกถอน
    InsufficientBalance:
      description: ยอดคงเหลือไม่พอสำหรับคำสั่งซื้อ
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: insufficient_balance
              message: 'ยอดเงินไม่พอ: ต้องใช้ 1060 ₽ มีอยู่ 420 ₽'
    NotFound:
      description: ไม่พบทรัพยากร
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: not_found
              message: ไม่พบสินค้า netflix-premium-12m
    IdempotencyConflict:
      description: คีย์ idempotency ถูกใช้กับเนื้อหาคำขออื่นไปแล้ว
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: idempotency_conflict
              message: Idempotency-Key ถูกใช้กับคำขออื่นไปแล้ว
    RateLimited:
      description: เกินขีดจำกัดคำขอ ลองใหม่หลังจาก `Retry-After` วินาที
      headers:
        Retry-After:
          description: จำนวนวินาทีที่ต้องรอก่อนส่งคำขอใหม่
          schema:
            type: integer
          example: 2
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: rate_limited
              message: คำขอมากเกินไป จำกัด 60 ครั้งต่อนาที
