{
  "openapi": "3.1.0",
  "info": {
    "title": "PayDM API",
    "version": "1.2.0",
    "description": "Escrow payments for sellers in Turkey. Money is integer kuruş (1 TL = 100). Order code flow (2026-11-13): POST /orders returns an order code (PDM-XXXXXX), never a payment link. Show or send the code to the buyer; the buyer writes it to PayDM's official WhatsApp number and PayDM sends the payment link there. Payment status reaches you only through the API and webhooks, never through the buyer. The old /links endpoints answer 410 Gone. Live keys start with pdm_, test keys with pdm_test_ (test keys create test orders: simulated payment, no money moves). POST requests accept an Idempotency-Key header. After payment the seller confirms the order within 48 hours (POST /transactions/{id}/accept, deadline acceptDueAt); without confirmation the buyer is refunded. Errors are { \"error\": \"...\" } in the language of Accept-Language (tr by default, en, ar). An order of another seller, or of the other mode (test or live), answers 404."
  },
  "servers": [{ "url": "https://{deployment}.convex.site/api/v1", "variables": { "deployment": { "default": "terrific-grasshopper-146" } } }],
  "security": [{ "bearer": [] }],
  "components": {
    "securitySchemes": { "bearer": { "type": "http", "scheme": "bearer", "description": "API key from Panel > Ayarlar > Geliştirici" } },
    "parameters": {
      "IdempotencyKey": { "name": "Idempotency-Key", "in": "header", "required": false, "schema": { "type": "string", "maxLength": 100 }, "description": "A retry with the same key and the same body returns the first successful answer (header Idempotent-Replayed: true). The same key with a different body, or on another route: 422. The same key while the first request still runs: 409. Error answers are not stored, so a fixed request can reuse the key." },
      "AcceptLanguage": { "name": "Accept-Language", "in": "header", "required": false, "schema": { "type": "string", "enum": ["tr", "en", "ar"], "default": "tr" }, "description": "Language of error messages. Without it, or for another language, errors are in Turkish." }
    },
    "schemas": {
      "Error": { "type": "object", "properties": { "error": { "type": "string" } }, "required": ["error"] },
      "Gone": { "type": "object", "properties": { "error": { "type": "string" }, "replacement": { "type": "string", "const": "/api/v1/orders" } }, "required": ["error", "replacement"] },
      "OrderCode": { "type": "string", "pattern": "^PDM-[2-9A-HJKMNP-Z]{6}$", "examples": ["PDM-7K2Q9X"], "description": "6 characters after PDM-, without 0, O, 1, I and L." },
      "WhatsApp": {
        "type": ["object", "null"],
        "description": "PayDM's official WhatsApp number. url is a wa.me link with the order code typed in. null when PayDM's number is not configured.",
        "properties": { "number": { "type": "string", "examples": ["+908501234567"] }, "url": { "type": "string", "format": "uri", "examples": ["https://wa.me/908501234567?text=PDM-7K2Q9X"] } },
        "required": ["number", "url"]
      },
      "OrderStatus": { "type": "string", "enum": ["open", "claimed", "paid"], "description": "open: no buyer wrote the code yet. claimed: a buyer wrote the code on WhatsApp and got the payment link. paid: the buyer paid; transactionId is set." },
      "Item": { "type": "object", "properties": { "title": { "type": "string" }, "unitPrice": { "type": "integer", "minimum": 100 }, "quantity": { "type": "integer", "minimum": 1, "maximum": 999 } }, "required": ["title", "unitPrice", "quantity"] },
      "Milestone": { "type": "object", "properties": { "title": { "type": "string" }, "amount": { "type": "integer", "minimum": 1000 } }, "required": ["title", "amount"] },
      "OrderCreate": {
        "type": "object",
        "required": ["title"],
        "properties": {
          "title": { "type": "string", "minLength": 2, "maxLength": 80 },
          "description": { "type": "string", "maxLength": 1000 },
          "price": { "type": "integer", "minimum": 1000, "description": "Kuruş. Not needed when items or milestones are given (their total is used)." },
          "shippingFee": { "type": "integer", "minimum": 0, "default": 0 },
          "deliveryDays": { "type": "integer", "enum": [1, 2, 3, 5, 7, 10, 14], "default": 3 },
          "delivery": { "type": "string", "enum": ["shipping", "in_person", "digital"], "default": "shipping" },
          "feePayer": { "type": "string", "enum": ["seller", "buyer", "split"], "default": "seller" },
          "items": { "type": "array", "maxItems": 20, "items": { "$ref": "#/components/schemas/Item" } },
          "deposit": { "type": "integer", "description": "Kapora: 5-50% of price, at least 1000." },
          "depositDays": { "type": "integer", "enum": [3, 7, 14, 30] },
          "milestones": { "type": "array", "minItems": 2, "maxItems": 10, "items": { "$ref": "#/components/schemas/Milestone" }, "description": "Staged payment. delivery must be digital or in_person, otherwise 400. Not combined with deposit; no shipping fee." },
          "returnUrl": { "type": "string", "format": "uri", "description": "https only. The buyer can go back to it from the PayDM order page after paying." },
          "metadata": { "type": "object", "additionalProperties": { "type": "string", "maxLength": 500 }, "maxProperties": 20 }
        }
      },
      "OrderCreated": {
        "type": "object",
        "properties": {
          "id": { "type": "string" }, "code": { "$ref": "#/components/schemas/OrderCode" }, "whatsapp": { "$ref": "#/components/schemas/WhatsApp" },
          "status": { "type": "string", "const": "open" }, "livemode": { "type": "boolean" }
        },
        "required": ["id", "code", "whatsapp", "status", "livemode"]
      },
      "Order": {
        "type": "object",
        "description": "An order by its code. No buyer data and no payment link. Buyer details come in the transaction after payment.",
        "properties": {
          "id": { "type": "string" }, "code": { "$ref": "#/components/schemas/OrderCode" }, "livemode": { "type": "boolean" },
          "status": { "$ref": "#/components/schemas/OrderStatus" }, "transactionId": { "type": ["string", "null"], "description": "Set when status is paid. Use it with GET /transactions/{id}." },
          "whatsapp": { "$ref": "#/components/schemas/WhatsApp" }, "title": { "type": "string" }, "price": { "type": "integer" },
          "shippingFee": { "type": "integer" }, "deliveryDays": { "type": "integer" }, "delivery": { "type": "string", "enum": ["shipping", "in_person", "digital"] },
          "feePayer": { "type": "string", "enum": ["seller", "buyer", "split"] }, "deposit": { "type": ["integer", "null"] },
          "items": { "type": ["array", "null"], "items": { "$ref": "#/components/schemas/Item" } }, "active": { "type": "boolean", "description": "false after POST /orders/{code}/close: the buyer can no longer pay with this code." },
          "metadata": { "type": "object", "additionalProperties": { "type": "string" } }, "createdAt": { "type": "integer" }
        }
      },
      "Transaction": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "livemode": { "type": "boolean" },
          "number": { "type": ["string", "null"], "examples": ["#PD-24801"] },
          "status": { "type": "string", "enum": ["held", "shipped", "delivered", "disputed", "returning", "released", "refunded"] },
          "title": { "type": "string" },
          "items": { "type": ["array", "null"], "items": { "$ref": "#/components/schemas/Item" } },
          "currency": { "type": "string", "const": "TRY" },
          "amounts": {
            "type": "object",
            "properties": {
              "price": { "type": "integer" }, "shipping": { "type": "integer" }, "buyerFee": { "type": "integer" }, "total": { "type": "integer" },
              "commission": { "type": "integer" }, "sellerNet": { "type": "integer" }, "refunded": { "type": "integer" }
            }
          },
          "feePayer": { "type": "string" },
          "delivery": { "type": "string" },
          "stage": { "type": ["string", "null"], "enum": ["deposit", "balance", "milestone", null] },
          "milestoneIndex": { "type": ["integer", "null"] },
          "buyer": { "type": "object", "properties": { "name": { "type": "string" }, "email": { "type": "string" }, "phone": { "type": "string" }, "address": { "type": "string" } } },
          "shipment": { "type": ["object", "null"], "properties": { "carrier": { "type": "string" }, "trackingNumber": { "type": "string" } } },
          "orderCode": { "type": ["string", "null"], "description": "Code of the order this transaction paid (replaces link, 2026-11-13).", "examples": ["PDM-7K2Q9X"] },
          "metadata": { "type": "object", "additionalProperties": { "type": "string" } },
          "createdAt": { "type": "integer" }, "paidAt": { "type": ["integer", "null"] }, "acceptedAt": { "type": ["integer", "null"] },
          "acceptDueAt": { "type": ["integer", "null"], "description": "Unix ms deadline for POST /transactions/{id}/accept (48 hours after payment). If it passes, the buyer is refunded. null after acceptance or when no confirmation is needed (rest of a kapora, later milestones)." },
          "shippedAt": { "type": ["integer", "null"] }, "deliveredAt": { "type": ["integer", "null"] }, "autoReleaseAt": { "type": ["integer", "null"] },
          "closedAt": { "type": ["integer", "null"] }
        }
      },
      "ShipmentInput": { "type": "object", "required": ["carrier", "trackingNumber"], "properties": { "carrier": { "type": "string", "examples": ["Yurtiçi Kargo"] }, "trackingNumber": { "type": "string", "examples": ["123456789012"] } } },
      "Fees": {
        "type": "object",
        "properties": {
          "price": { "type": "integer" }, "shipping": { "type": "integer" }, "feePayer": { "type": "string" }, "buyerPays": { "type": "integer" },
          "buyerFee": { "type": "integer" }, "commission": { "type": "integer" }, "sellerReceives": { "type": "integer" }, "currency": { "type": "string" }
        }
      }
    },
    "responses": {
      "Unauthorized": { "description": "Missing or wrong API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "TooMany": { "description": "Rate limit reached. Retry after the Retry-After seconds.", "headers": { "Retry-After": { "schema": { "type": "integer" }, "description": "Real wait in seconds until the limit opens again." } } },
      "NotFound": { "description": "Not found, not the caller's, or of the other mode (test or live)", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "IdemRunning": { "description": "A request with this Idempotency-Key is still running", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "IdemConflict": { "description": "Idempotency-Key used with another body or on another route", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "BadRequest": { "description": "Validation error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "Gone": { "description": "Removed on 2026-11-13. Payment links were replaced by order codes; use /orders.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Gone" } } } }
    }
  },
  "paths": {
    "/fees": {
      "get": {
        "summary": "Fee calculator",
        "security": [],
        "parameters": [
          { "name": "price", "in": "query", "required": true, "schema": { "type": "integer" } },
          { "name": "shipping", "in": "query", "schema": { "type": "integer", "default": 0 } },
          { "name": "feePayer", "in": "query", "schema": { "type": "string", "enum": ["seller", "buyer", "split"] } }
        ],
        "responses": { "200": { "description": "Amounts", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Fees" } } } } }
      }
    },
    "/orders": {
      "post": {
        "summary": "Create an order and get its order code",
        "description": "Show or send the code to the buyer. The buyer writes it to PayDM's WhatsApp number (whatsapp.url opens WhatsApp with the code typed in) and PayDM sends the payment link to that number. The response never contains a payment link. Put your own order id in metadata: paid transactions and webhooks carry the same metadata.",
        "parameters": [{ "$ref": "#/components/parameters/IdempotencyKey" }, { "$ref": "#/components/parameters/AcceptLanguage" }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/OrderCreate" } } } },
        "responses": {
          "201": { "description": "Created", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/OrderCreated" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" }, "401": { "$ref": "#/components/responses/Unauthorized" },
          "409": { "$ref": "#/components/responses/IdemRunning" }, "422": { "$ref": "#/components/responses/IdemConflict" },
          "429": { "$ref": "#/components/responses/TooMany" }
        }
      }
    },
    "/orders/{code}": {
      "get": {
        "summary": "Get an order by its code",
        "description": "Status only: open, claimed or paid (with transactionId). A test key sees test orders, a live key live orders. The code is not case sensitive.",
        "parameters": [{ "name": "code", "in": "path", "required": true, "schema": { "type": "string", "examples": ["PDM-7K2Q9X"] } }],
        "responses": { "200": { "description": "Order", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Order" } } } }, "404": { "description": "Not found" }, "401": { "$ref": "#/components/responses/Unauthorized" } }
      }
    },
    "/orders/{code}/close": {
      "post": {
        "summary": "Close an unpaid order",
        "description": "No body. The buyer can no longer pay with this code; a buyer who writes it on WhatsApp is told the order no longer takes payments. Close the old order before you create a new one for a changed cart. Already closed: 200 with the same order. Already paid: 400.",
        "parameters": [{ "name": "code", "in": "path", "required": true, "schema": { "type": "string", "examples": ["PDM-7K2Q9X"] } }, { "$ref": "#/components/parameters/IdempotencyKey" }, { "$ref": "#/components/parameters/AcceptLanguage" }],
        "responses": {
          "200": { "description": "Closed order (active false)", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Order" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" }, "401": { "$ref": "#/components/responses/Unauthorized" }, "404": { "$ref": "#/components/responses/NotFound" },
          "409": { "$ref": "#/components/responses/IdemRunning" }, "422": { "$ref": "#/components/responses/IdemConflict" }, "429": { "$ref": "#/components/responses/TooMany" }
        }
      }
    },
    "/links": {
      "post": {
        "summary": "Removed: use POST /orders",
        "deprecated": true,
        "responses": { "410": { "$ref": "#/components/responses/Gone" } }
      }
    },
    "/links/{slug}": {
      "get": {
        "summary": "Removed: use GET /orders/{code}",
        "deprecated": true,
        "parameters": [{ "name": "slug", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "410": { "$ref": "#/components/responses/Gone" } }
      }
    },
    "/transactions": {
      "get": {
        "summary": "List paid orders, newest first",
        "description": "A test key lists test orders, a live key live orders.",
        "parameters": [
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 20 } },
          { "name": "before", "in": "query", "schema": { "type": "integer" }, "description": "nextBefore from the previous page" }
        ],
        "responses": {
          "200": { "description": "Page", "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "type": "array", "items": { "$ref": "#/components/schemas/Transaction" } }, "nextBefore": { "type": ["integer", "null"] } } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" }, "429": { "$ref": "#/components/responses/TooMany" }
        }
      }
    },
    "/transactions/{id}": {
      "get": {
        "summary": "Get an order",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Order", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Transaction" } } } }, "404": { "description": "Not found" }, "401": { "$ref": "#/components/responses/Unauthorized" } }
      }
    },
    "/transactions/{id}/accept": {
      "post": {
        "summary": "Confirm a paid order",
        "description": "No body. The seller confirms a paid order (status held) before acceptDueAt (48 hours after payment); otherwise the buyer is refunded. Already accepted: 200 with the same object, nothing changes. Status not held: 400.",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }, { "$ref": "#/components/parameters/IdempotencyKey" }, { "$ref": "#/components/parameters/AcceptLanguage" }],
        "responses": {
          "200": { "description": "Confirmed order (acceptedAt set, acceptDueAt null)", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Transaction" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" }, "401": { "$ref": "#/components/responses/Unauthorized" }, "404": { "$ref": "#/components/responses/NotFound" },
          "409": { "$ref": "#/components/responses/IdemRunning" }, "422": { "$ref": "#/components/responses/IdemConflict" }, "429": { "$ref": "#/components/responses/TooMany" }
        }
      }
    },
    "/transactions/{id}/ship": {
      "post": {
        "summary": "Mark an order shipped",
        "description": "The response is the transaction with its real orderCode.",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }, { "$ref": "#/components/parameters/IdempotencyKey" }, { "$ref": "#/components/parameters/AcceptLanguage" }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ShipmentInput" } } } },
        "responses": {
          "200": { "description": "Updated order", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Transaction" } } } }, "400": { "$ref": "#/components/responses/BadRequest" }, "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" }, "409": { "$ref": "#/components/responses/IdemRunning" }, "422": { "$ref": "#/components/responses/IdemConflict" }, "429": { "$ref": "#/components/responses/TooMany" }
        }
      }
    },
    "/transactions/{id}/shipment": {
      "post": {
        "summary": "Correct the carrier or tracking number",
        "description": "For a shipped order (status shipped or disputed). Sends the transaction.shipment_updated webhook with the new shipment. 400 when the order is not shipped, a field is missing, or the order has a Geliver label bought through PayDM (the carrier sets the number).",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }, { "$ref": "#/components/parameters/IdempotencyKey" }, { "$ref": "#/components/parameters/AcceptLanguage" }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ShipmentInput" } } } },
        "responses": {
          "200": { "description": "Updated order", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Transaction" } } } }, "400": { "$ref": "#/components/responses/BadRequest" }, "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" }, "409": { "$ref": "#/components/responses/IdemRunning" }, "422": { "$ref": "#/components/responses/IdemConflict" }, "429": { "$ref": "#/components/responses/TooMany" }
        }
      }
    },
    "/transactions/{id}/deliver": {
      "post": {
        "summary": "Deliver a digital order",
        "description": "Only for delivery digital and status held. Confirms the order if needed and records the delivery; the status becomes delivered, a short inspection window starts, then the money is released. 400 for another delivery type, an order that is not ready, a missing or too long note, or an unpaid kapora balance.",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }, { "$ref": "#/components/parameters/IdempotencyKey" }, { "$ref": "#/components/parameters/AcceptLanguage" }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["note"], "properties": { "note": { "type": "string", "minLength": 3, "maxLength": 2000, "description": "Download link, code or a summary of the delivery.", "examples": ["Download: https://example.com/files/logo-final.zip"] } } } } } },
        "responses": {
          "200": { "description": "Delivered order", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Transaction" } } } }, "400": { "$ref": "#/components/responses/BadRequest" }, "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" }, "409": { "$ref": "#/components/responses/IdemRunning" }, "422": { "$ref": "#/components/responses/IdemConflict" }, "429": { "$ref": "#/components/responses/TooMany" }
        }
      }
    }
  },
  "webhooks": {
    "transaction": {
      "post": {
        "summary": "Order changed (transaction.held | shipped | shipment_updated | delivered | disputed | returning | released | refunded)",
        "description": "Header PayDM-Signature: t=<unix ms>,v1=<hex HMAC-SHA256(secret, \"<t>.<raw body>\")>. Reject when t is older than 5 minutes. Retries keep the original created time; ignore events older than the last one you applied. data is the transaction: data.orderCode is the order code and data.metadata the metadata you sent with POST /orders (data.link was removed on 2026-11-13). Webhooks start at transaction.held: there are no events for open or claimed orders. transaction.shipment_updated is sent after POST /transactions/{id}/shipment; data.shipment has the new carrier and tracking number.",
        "requestBody": { "content": { "application/json": { "schema": { "type": "object", "properties": { "id": { "type": "string" }, "type": { "type": "string", "enum": ["transaction.held", "transaction.shipped", "transaction.shipment_updated", "transaction.delivered", "transaction.disputed", "transaction.returning", "transaction.released", "transaction.refunded", "ping"] }, "created": { "type": "integer" }, "data": { "$ref": "#/components/schemas/Transaction" } } } } } },
        "responses": { "200": { "description": "Received" } }
      }
    }
  }
}
