{
 "openapi": "3.0.3",
 "info": {
  "title": "OpenUPI merchant gateway",
  "version": "2026-10-31",
  "description": "Shop API of the OpenUPI gateway (docs/GATEWAY.md, ADR-032, ADR-038). A demo network: demo banks, no real money.\nAn order is paid only when the switch says its payment succeeded; a payment in doubt keeps the order PROCESSING.\nAlways confirm a payment with GET /gw/v1/orders/{id} before shipping. Webhooks are described under x-webhooks.\n\nSend OpenUPI-Version: 2026-10-31 to pin this version (ADR-055). Test keys (gk_test_, rk_test_) make test orders paid only by the simulator (ADR-048)."
 },
 "servers": [
  {
   "url": "http://localhost:9000"
  }
 ],
 "security": [
  {
   "shopKey": []
  }
 ],
 "components": {
  "securitySchemes": {
   "shopKey": {
    "type": "http",
    "scheme": "bearer",
    "description": "The shop's API key (the development shop uses dev-shop-key)."
   }
  },
  "schemas": {
   "Error": {
    "type": "object",
    "required": [
     "error"
    ],
    "properties": {
     "error": {
      "type": "string"
     },
     "code": {
      "type": "string",
      "example": "ORDER_AMOUNT_MISMATCH"
     },
     "status": {
      "type": "string",
      "description": "Present on ORDER_NOT_CANCELLABLE; the order's current status."
     }
    }
   },
   "Metadata": {
    "type": "object",
    "description": "Up to 10 keys; key 1-40 chars; string values up to 200 chars.",
    "maxProperties": 10,
    "additionalProperties": {
     "type": "string",
     "maxLength": 200
    }
   },
   "Order": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "example": "order_f7c14b38ec5a7854e2888dfa",
      "description": "The gateway's id. Use it in /orders/{id}."
     },
     "orderId": {
      "type": "string",
      "description": "Your reference."
     },
     "status": {
      "type": "string",
      "enum": [
       "CREATED",
       "PROCESSING",
       "PAID",
       "FAILED",
       "EXPIRED",
       "REVERSED",
       "CANCELLED"
      ]
     },
     "message": {
      "type": "string"
     },
     "amount": {
      "type": "string",
      "example": "99.00"
     },
     "amountPaise": {
      "type": "integer",
      "example": 9900
     },
     "amountRefunded": {
      "type": "string",
      "example": "0.00"
     },
     "checkoutUrl": {
      "type": "string",
      "format": "uri"
     },
     "createdAt": {
      "type": "string",
      "format": "date-time"
     },
     "expiresAt": {
      "type": "string",
      "format": "date-time"
     },
     "paymentIds": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "refunds": {
      "type": "array",
      "nullable": true,
      "items": {
       "type": "object"
      }
     },
     "webhooks": {
      "type": "array",
      "nullable": true,
      "items": {
       "type": "object"
      }
     },
     "metadata": {
      "$ref": "#/components/schemas/Metadata"
     }
    }
   }
  },
  "responses": {
   "Error": {
    "description": "Error",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      }
     }
    }
   }
  }
 },
 "paths": {
  "/gw/v1/orders": {
   "post": {
    "summary": "Make an order (idempotent on orderId + amount)",
    "description": "The same orderId and amount returns the same order (metadata of a repeat request is ignored). Another amount is 409 ORDER_AMOUNT_MISMATCH. currency is ISO 4217 (default INR); the amount takes that currency's decimals (JPY none, BHD three). A currency no rail on this gateway takes is refused with 400 CURRENCY_NOT_SUPPORTED; today only INR, over UPI. Orders, their webhooks and checkout all say the currency.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "orderId",
         "amount"
        ],
        "properties": {
         "orderId": {
          "type": "string"
         },
         "amount": {
          "type": "string",
          "example": "499.00",
          "description": "Rupees as text."
         },
         "note": {
          "type": "string"
         },
         "ttlSeconds": {
          "type": "integer",
          "minimum": 60,
          "maximum": 3600,
          "default": 300
         },
         "returnUrl": {
          "type": "string",
          "format": "uri"
         },
         "metadata": {
          "$ref": "#/components/schemas/Metadata"
         }
        }
       },
       "example": {
        "orderId": "ORD-1001",
        "amount": "499.00",
        "note": "T-shirt",
        "returnUrl": "https://shop.example/thanks",
        "metadata": {
         "sku": "tee"
        },
        "currency": "INR"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The order",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/Error"
     },
     "401": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "$ref": "#/components/responses/Error"
     }
    },
    "tags": [
     "Orders"
    ]
   },
   "get": {
    "summary": "List orders",
    "parameters": [
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "CREATED",
        "PROCESSING",
        "PAID",
        "FAILED",
        "EXPIRED",
        "REVERSED",
        "CANCELLED"
       ]
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Orders",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "orders": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Order"
           }
          }
         }
        }
       }
      }
     }
    },
    "tags": [
     "Orders"
    ]
   }
  },
  "/gw/v1/orders/{id}": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string"
     }
    }
   ],
   "get": {
    "summary": "Read an order (confirm payment here before shipping)",
    "responses": {
     "200": {
      "description": "The order",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        }
       }
      }
     },
     "404": {
      "$ref": "#/components/responses/Error"
     }
    },
    "tags": [
     "Orders"
    ]
   }
  },
  "/gw/v1/orders/{id}/cancel": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string"
     }
    }
   ],
   "post": {
    "summary": "Cancel an order nobody has started paying",
    "description": "Only from CREATED with no payment attempt. Idempotent. Queues the order.cancelled webhook once.",
    "responses": {
     "200": {
      "description": "The cancelled order",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        }
       }
      }
     },
     "404": {
      "$ref": "#/components/responses/Error"
     },
     "409": {
      "description": "ORDER_NOT_CANCELLABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "tags": [
     "Orders"
    ]
   }
  },
  "/gw/v1/orders/{id}/refunds": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string"
     }
    }
   ],
   "post": {
    "summary": "Refund (needs the shop's UPI PIN, used once, never stored)",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "refundId",
         "pin"
        ],
        "properties": {
         "refundId": {
          "type": "string"
         },
         "amount": {
          "type": "string",
          "description": "Defaults to what is left."
         },
         "reason": {
          "type": "string"
         },
         "pin": {
          "type": "string",
          "format": "password"
         }
        }
       },
       "example": {
        "refundId": "rf-1",
        "amount": "100.00",
        "reason": "size exchange",
        "pin": "1234"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The refund"
     },
     "400": {
      "description": "REFUND_EXCEEDS_PAYMENT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "REFUND_AMOUNT_MISMATCH",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "tags": [
     "Refunds"
    ]
   }
  },
  "/gw/v1/links": {
   "post": {
    "summary": "Make a single-use payment link",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "linkId",
         "amount"
        ],
        "properties": {
         "linkId": {
          "type": "string"
         },
         "amount": {
          "type": "string"
         },
         "note": {
          "type": "string"
         },
         "ttlSeconds": {
          "type": "integer"
         }
        }
       },
       "example": {
        "linkId": "INV-12",
        "amount": "250.00",
        "note": "Invoice 12",
        "ttlSeconds": 604800
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The link"
     },
     "409": {
      "$ref": "#/components/responses/Error"
     }
    },
    "tags": [
     "Links"
    ]
   },
   "get": {
    "summary": "List links",
    "responses": {
     "200": {
      "description": "Links",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "links": {
           "type": "array",
           "items": {
            "type": "object"
           }
          }
         }
        }
       }
      }
     }
    },
    "tags": [
     "Links"
    ]
   }
  },
  "/gw/v1/links/{id}/cancel": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string"
     }
    }
   ],
   "post": {
    "summary": "Cancel a link",
    "responses": {
     "200": {
      "description": "The link"
     }
    },
    "tags": [
     "Links"
    ]
   }
  },
  "/gw/v1/webhooks": {
   "get": {
    "summary": "Webhook deliveries",
    "parameters": [
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Deliveries",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "webhooks": {
           "type": "array",
           "items": {
            "type": "object"
           }
          }
         }
        }
       }
      }
     }
    },
    "tags": [
     "Webhooks"
    ]
   }
  },
  "/gw/v1/orders/{id}/webhooks/{deliveryId}/resend": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string"
     }
    },
    {
     "name": "deliveryId",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string"
     }
    }
   ],
   "post": {
    "summary": "Send an abandoned delivery again",
    "responses": {
     "200": {
      "description": "Queued"
     }
    },
    "tags": [
     "Webhooks"
    ]
   }
  },
  "/gw/v1/webhooks/test": {
   "post": {
    "summary": "Send a test ping (400 if the shop has no webhook address)",
    "responses": {
     "200": {
      "description": "Sent"
     },
     "400": {
      "$ref": "#/components/responses/Error"
     }
    },
    "tags": [
     "Webhooks"
    ]
   }
  },
  "/gw/v1/keys": {
   "get": {
    "summary": "List API keys (no secrets)",
    "responses": {
     "200": {
      "description": "Keys",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "keys": {
           "type": "array",
           "items": {
            "type": "object"
           }
          }
         }
        }
       }
      }
     }
    },
    "tags": [
     "Keys"
    ]
   }
  },
  "/gw/v1/keys/rotate": {
   "post": {
    "summary": "Make a new key (shown once); old keys end after the grace period (default 24 hours)",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "graceHours": {
          "type": "integer",
          "minimum": 0
         }
        }
       },
       "example": {
        "graceHours": 24
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The new key",
      "shown once": null
     }
    },
    "tags": [
     "Keys"
    ]
   }
  },
  "/gw/v1/public/orders/{id}": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string"
     }
    }
   ],
   "get": {
    "summary": "The customer's view of an order (no key; used by the hosted checkout). Includes brand when the shop has branding.",
    "security": [],
    "responses": {
     "200": {
      "description": "Public order",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "brand": {
           "type": "object",
           "properties": {
            "name": {
             "type": "string"
            },
            "color": {
             "type": "string",
             "example": "#0f766e"
            },
            "logoUrl": {
             "type": "string",
             "format": "uri"
            }
           }
          }
         }
        }
       }
      }
     }
    },
    "tags": [
     "Public"
    ]
   }
  },
  "/gw/v1/keys/test": {
   "post": {
    "tags": [
     "Keys"
    ],
    "summary": "Issue a test key",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "description": "Orders made with it are test orders, paid only by the simulator: success@sandbox, decline@sandbox, nofunds@sandbox, slow@sandbox, deemed@sandbox; PIN 0000 is wrong."
   }
  },
  "/gw/v1/keys/restricted": {
   "post": {
    "tags": [
     "Keys"
    ],
    "summary": "Issue a restricted key",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "name": "warehouse",
        "scopes": [
         "orders:read",
         "orders:write"
        ]
       }
      }
     }
    }
   }
  },
  "/gw/v1/keys/{id}/revoke": {
   "post": {
    "tags": [
     "Keys"
    ],
    "summary": "Revoke a restricted or test key",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/events": {
   "get": {
    "tags": [
     "Webhooks"
    ],
    "summary": "The event catalogue, versions, scopes and signature format",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "description": "No key needed."
   }
  },
  "/gw/v1/settings": {
   "get": {
    "tags": [
     "Settings"
    ],
    "summary": "Read the shop's settings and billing profile",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    }
   },
   "post": {
    "tags": [
     "Settings"
    ],
    "summary": "Set the amount above which a refund needs a second person",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "refundApprovalOver": "5000.00"
       }
      }
     }
    }
   }
  },
  "/gw/v1/billing": {
   "post": {
    "tags": [
     "Settings"
    ],
    "summary": "Set the billing profile for invoices",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "legalName": "Dev Shop Pvt Ltd",
        "gstin": "29ABCDE1234F1Z5",
        "address": "12 MG Road, Bengaluru",
        "invoicePrefix": "DS"
       }
      }
     }
    }
   }
  },
  "/gw/v1/refund-requests": {
   "get": {
    "tags": [
     "Refunds"
    ],
    "summary": "Refunds waiting for a second person",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    }
   }
  },
  "/gw/v1/refund-requests/{id}/approve": {
   "post": {
    "tags": [
     "Refunds"
    ],
    "summary": "Approve a held refund (a different person, with the shop's PIN)",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "pin": "1234"
       }
      }
     }
    }
   }
  },
  "/gw/v1/refund-requests/{id}/reject": {
   "post": {
    "tags": [
     "Refunds"
    ],
    "summary": "Reject a held refund",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/customers": {
   "get": {
    "tags": [
     "Customers"
    ],
    "summary": "List customers",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "q",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      }
     }
    ]
   },
   "post": {
    "tags": [
     "Customers"
    ],
    "summary": "Add a customer",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "name": "Asha Traders",
        "email": "accounts@asha.example",
        "phone": "+919876543210",
        "vpa": "asha@beta",
        "gstin": "29ABCDE1234F1Z5"
       }
      }
     }
    }
   }
  },
  "/gw/v1/customers/{id}": {
   "get": {
    "tags": [
     "Customers"
    ],
    "summary": "Read a customer",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   },
   "post": {
    "tags": [
     "Customers"
    ],
    "summary": "Change a customer",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "name": "Asha Traders Pvt Ltd"
       }
      }
     }
    }
   }
  },
  "/gw/v1/products": {
   "get": {
    "tags": [
     "Products"
    ],
    "summary": "List products",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "all",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      }
     }
    ]
   },
   "post": {
    "tags": [
     "Products"
    ],
    "summary": "Add a product (price before GST)",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "name": "Cotton tee",
        "price": "499.00",
        "gstRate": 5,
        "hsn": "6109",
        "unit": "piece"
       }
      }
     }
    }
   }
  },
  "/gw/v1/products/{id}": {
   "get": {
    "tags": [
     "Products"
    ],
    "summary": "Read a product",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   },
   "post": {
    "tags": [
     "Products"
    ],
    "summary": "Change or archive a product",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "name": "Cotton tee",
        "price": "499.00",
        "gstRate": 5,
        "active": false
       }
      }
     }
    }
   }
  },
  "/gw/v1/invoices": {
   "get": {
    "tags": [
     "Invoices"
    ],
    "summary": "List invoices",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    }
   },
   "post": {
    "tags": [
     "Invoices"
    ],
    "summary": "Draft an invoice",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "customerId": "cus_…",
        "lines": [
         {
          "productId": "prod_…",
          "qty": 2
         }
        ],
        "dueDays": 15
       }
      }
     }
    }
   }
  },
  "/gw/v1/invoices/{id}": {
   "get": {
    "tags": [
     "Invoices"
    ],
    "summary": "Read an invoice",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/invoices/{id}/issue": {
   "post": {
    "tags": [
     "Invoices"
    ],
    "summary": "Issue: number it and make its payment link",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/invoices/{id}/void": {
   "post": {
    "tags": [
     "Invoices"
    ],
    "summary": "Void an unpaid invoice",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/invoices/{id}/remind": {
   "post": {
    "tags": [
     "Invoices"
    ],
    "summary": "Remind the customer (email when on, and a WhatsApp link)",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/invoices/{id}/pdf": {
   "get": {
    "tags": [
     "Invoices"
    ],
    "summary": "The invoice as a PDF",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/public/invoices/{id}": {
   "get": {
    "tags": [
     "Public"
    ],
    "summary": "The customer's view of an issued invoice",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/public/invoices/{id}/pdf": {
   "get": {
    "tags": [
     "Public"
    ],
    "summary": "The customer's PDF",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/plans": {
   "get": {
    "tags": [
     "Subscriptions"
    ],
    "summary": "List plans",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    }
   },
   "post": {
    "tags": [
     "Subscriptions"
    ],
    "summary": "Add a plan",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "name": "Monthly box",
        "amount": "199.00",
        "interval": "MONTHLY",
        "trialDays": 7
       }
      }
     }
    }
   }
  },
  "/gw/v1/subscriptions": {
   "get": {
    "tags": [
     "Subscriptions"
    ],
    "summary": "List subscriptions",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    }
   },
   "post": {
    "tags": [
     "Subscriptions"
    ],
    "summary": "Ask a payer for an autopay mandate for a plan",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "planId": "plan_…",
        "payer": "alice@alpha"
       }
      }
     }
    }
   }
  },
  "/gw/v1/subscriptions/{id}/{action}": {
   "post": {
    "tags": [
     "Subscriptions"
    ],
    "summary": "pause, resume, cancel, cancel_at_period_end, or plan (with {planId})",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "action",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/reports/statement": {
   "get": {
    "tags": [
     "Statements"
    ],
    "summary": "Statement of settled payments and refunds",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "description": "format=csv or xlsx for a file.",
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "to",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "format",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/sellers": {
   "get": {
    "tags": [
     "Splits"
    ],
    "summary": "List sellers",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    }
   },
   "post": {
    "tags": [
     "Splits"
    ],
    "summary": "Add a seller",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "name": "Asha Crafts",
        "vpa": "asha@beta"
       }
      }
     }
    }
   }
  },
  "/gw/v1/splits": {
   "get": {
    "tags": [
     "Splits"
    ],
    "summary": "Sellers' parts of orders and their state",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    }
   }
  },
  "/gw/v1/splits/payout": {
   "post": {
    "tags": [
     "Splits"
    ],
    "summary": "Pay every due part from the shop's account",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "pin": "1234"
       }
      }
     }
    }
   }
  },
  "/gw/v1/disputes": {
   "get": {
    "tags": [
     "Disputes"
    ],
    "summary": "Disputes about the shop's payments",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    }
   }
  },
  "/gw/v1/disputes/{id}/evidence": {
   "post": {
    "tags": [
     "Disputes"
    ],
    "summary": "Add the shop's evidence",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "text": "Delivered on 28 Oct; invoice DS/2026-27/0001"
       }
      }
     }
    }
   }
  },
  "/gw/v1/offers": {
   "get": {
    "tags": [
     "Offers"
    ],
    "summary": "The shop's offers",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    }
   },
   "post": {
    "tags": [
     "Offers"
    ],
    "summary": "Post an offer",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "title": "10% off tees",
        "details": "Orders over ₹500",
        "code": "TEE10",
        "until": "2026-11-30"
       }
      }
     }
    }
   }
  },
  "/gw/v1/offers/{id}/withdraw": {
   "post": {
    "tags": [
     "Offers"
    ],
    "summary": "Withdraw an offer",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/shop/qr": {
   "get": {
    "tags": [
     "Orders"
    ],
    "summary": "The shop's static UPI QR (PNG, or ?format=link)",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "format",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/public/orders/{id}/qr": {
   "get": {
    "tags": [
     "Public"
    ],
    "summary": "An open order's UPI QR (PNG)",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/public/orders/{id}/pay": {
   "post": {
    "tags": [
     "Public"
    ],
    "summary": "Pay an order from the hosted checkout",
    "description": "Used by the checkout page; a payer locked to a phone also sends X-Device-Proof (ADR-058).",
    "security": [],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "from": "alice@alpha",
        "pin": "1234"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The order as the checkout page sees it"
     },
     "400": {
      "description": "Invalid request"
     },
     "409": {
      "description": "Already paid, being paid, or over"
     }
    }
   }
  },
  "/gw/v1/public/orders/{id}/otp": {
   "post": {
    "tags": [
     "Public"
    ],
    "summary": "Send or check the phone code on checkout",
    "description": "Send {phone} to get a code, then {code} to check it, when the operator turned the phone check on.",
    "security": [],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "phone": "+919876543210"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The order as the checkout page sees it"
     },
     "400": {
      "description": "Invalid request"
     },
     "409": {
      "description": "Already paid, being paid, or over"
     }
    }
   }
  },
  "/gw/v1/webhooks/stream": {
   "get": {
    "tags": [
     "Webhooks"
    ],
    "summary": "Stream test-mode webhooks (server-sent events), for openupi listen",
    "description": "Test keys only. Each event carries the webhook's event, deliveryId, timestamp, signature (X-Gateway-Signature-V2) and raw body, signed as the gateway signs deliveries. Live webhooks never go here.",
    "responses": {
     "200": {
      "description": "text/event-stream"
     },
     "403": {
      "description": "Not a test key"
     }
    }
   }
  },
  "/gw/v1/requests": {
   "get": {
    "tags": [
     "Keys"
    ],
    "summary": "The request log: recent API calls made with your keys",
    "description": "The last 500 calls made with any of the shop's keys, newest first, in the mode of the key or view asking (live or test). Each has its Request-Id (also sent as a response header on every keyed call), the key's id, route, status, duration and, for errors, the gateway's code and message. Bodies are never kept. Kept in memory: a restart empties it. Not for restricted keys.",
    "parameters": [
     {
      "name": "key",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "only this key id (configured, or an issued key's id)"
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "an exact status like 403, or a class like 4xx"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "The requests",
      "content": {
       "application/json": {
        "example": {
         "mode": "live",
         "kept": 500,
         "requests": [
          {
           "id": "req_8c1f0e2a9b7d4c3e5f6a7b8c",
           "at": "2026-10-31T10:00:00Z",
           "keyId": "configured",
           "mode": "live",
           "method": "POST",
           "route": "POST /gw/v1/orders",
           "path": "/gw/v1/orders",
           "status": 409,
           "durationMs": 3,
           "version": "2026-10-31",
           "code": "ORDER_AMOUNT_MISMATCH",
           "error": "this orderId was already used with another amount"
          }
         ]
        }
       }
      }
     }
    }
   }
  },
  "/gw/v1/public/status": {
   "get": {
    "tags": [
     "Public"
    ],
    "summary": "Service status (no key)",
    "description": "The state of each part (api, payments, webhooks, test) and overall: operational, degraded or outage, with the operator's message when there is one. Payments show degraded when a live payment has waited more than five minutes for its answer; such a payment is not failed. Never shows a shop, an order or a count. The page is at /status.",
    "security": [],
    "responses": {
     "200": {
      "description": "The status",
      "content": {
       "application/json": {
        "example": {
         "state": "operational",
         "checkedAt": "2026-10-31T10:00:00Z",
         "parts": [
          {
           "id": "api",
           "name": "API and checkout",
           "state": "operational"
          },
          {
           "id": "payments",
           "name": "Payments",
           "state": "operational"
          },
          {
           "id": "webhooks",
           "name": "Webhooks",
           "state": "operational"
          },
          {
           "id": "test",
           "name": "Test mode",
           "state": "operational"
          }
         ],
         "notices": null
        }
       }
      }
     }
    }
   }
  },
  "/gw/v1/brand": {
   "get": {
    "tags": [
     "Settings"
    ],
    "summary": "Your brand: how checkout, links and invoices look",
    "description": "The brand you saved and the brand customers see (yours over the operator's). Not for restricted keys.",
    "responses": {
     "200": {
      "description": "The brand",
      "content": {
       "application/json": {
        "example": {
         "brand": {
          "name": "Chai Corner",
          "logoUrl": "https://cdn.example/logo.png",
          "color": "#0f766e",
          "color2": "#14b8a6",
          "radius": 8,
          "font": "rounded",
          "appearance": "auto",
          "receiptNote": "Thanks for visiting {shop}! Show this receipt for {amount} at the counter.",
          "support": "help@chaicorner.example · +91 98xxxxxx10"
         },
         "shown": {
          "name": "Chai Corner",
          "logoUrl": "https://cdn.example/logo.png",
          "color": "#0f766e",
          "color2": "#14b8a6",
          "radius": 8,
          "font": "rounded",
          "appearance": "auto",
          "support": "help@chaicorner.example · +91 98xxxxxx10"
         },
         "fonts": [
          "system",
          "rounded",
          "serif",
          "mono"
         ]
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Settings"
    ],
    "summary": "Set your brand and receipt",
    "description": "Every field is optional; an empty one falls back to the operator's file, then to OpenUPI's look. Colours #rgb or #rrggbb; radius 0 to 24; font system, rounded, serif or mono; appearance auto, light or dark; receiptNote (up to 280 characters) is shown once paid, with {shop}, {amount} and {order} filled in; support (up to 120) is shown on the receipt. All text is plain text. Owners and admins only; not for restricted keys.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "example": {
        "name": "Chai Corner",
        "logoUrl": "https://cdn.example/logo.png",
        "color": "#0f766e",
        "color2": "#14b8a6",
        "radius": 8,
        "font": "rounded",
        "appearance": "auto",
        "receiptNote": "Thanks for visiting {shop}! Show this receipt for {amount} at the counter.",
        "support": "help@chaicorner.example · +91 98xxxxxx10"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Saved",
      "content": {
       "application/json": {
        "example": {
         "brand": {
          "name": "Chai Corner",
          "logoUrl": "https://cdn.example/logo.png",
          "color": "#0f766e",
          "color2": "#14b8a6",
          "radius": 8,
          "font": "rounded",
          "appearance": "auto",
          "receiptNote": "Thanks for visiting {shop}! Show this receipt for {amount} at the counter.",
          "support": "help@chaicorner.example · +91 98xxxxxx10"
         },
         "shown": {
          "name": "Chai Corner",
          "logoUrl": "https://cdn.example/logo.png",
          "color": "#0f766e",
          "color2": "#14b8a6",
          "radius": 8,
          "font": "rounded",
          "appearance": "auto",
          "support": "help@chaicorner.example · +91 98xxxxxx10"
         }
        }
       }
      }
     },
     "400": {
      "description": "A field is not allowed"
     }
    }
   }
  },
  "/gw/v1/domain": {
   "get": {
    "tags": [
     "Settings"
    ],
    "summary": "Your custom domain",
    "description": "The domain you claimed, whether it is verified, the TXT record that proves it, and base: where your checkout, link and invoice addresses point now. Not for restricted keys.",
    "responses": {
     "200": {
      "description": "The domain",
      "content": {
       "application/json": {
        "example": {
         "domain": {
          "domain": "pay.chaicorner.in",
          "status": "PENDING",
          "createdAt": "2026-10-31T10:00:00Z",
          "txtName": "_openupi-verify.pay.chaicorner.in",
          "txtValue": "openupi-verify=3f9c2a7d1e8b4c6a9d0e1f2a3b4c5d6e"
         },
         "base": "https://pay.example"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Settings"
    ],
    "summary": "Claim a custom domain",
    "description": "Claim one domain for your customer pages, like pay.yourshop.in. Publish the TXT record it returns, then verify. Until verified nothing changes. Claiming the same domain again keeps the same record. Point the domain at the gateway (a CNAME to its address); the operator serves it over TLS. Owners and admins only; not for restricted keys.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "example": {
        "domain": "pay.chaicorner.in"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The domain",
      "content": {
       "application/json": {
        "example": {
         "domain": {
          "domain": "pay.chaicorner.in",
          "status": "PENDING",
          "createdAt": "2026-10-31T10:00:00Z",
          "txtName": "_openupi-verify.pay.chaicorner.in",
          "txtValue": "openupi-verify=3f9c2a7d1e8b4c6a9d0e1f2a3b4c5d6e"
         },
         "base": "https://pay.example"
        }
       }
      }
     },
     "400": {
      "description": "Not a domain, or the gateway's own"
     },
     "409": {
      "description": "Another shop has verified it"
     }
    }
   }
  },
  "/gw/v1/domain/verify": {
   "post": {
    "tags": [
     "Settings"
    ],
    "summary": "Verify your custom domain",
    "description": "Looks up the TXT record. Once found, your checkout, link and invoice addresses use the domain, and that domain serves only your shop's public pages. 409 DOMAIN_NOT_VERIFIED while the record is not visible yet.",
    "responses": {
     "200": {
      "description": "The domain",
      "content": {
       "application/json": {
        "example": {
         "domain": {
          "domain": "pay.chaicorner.in",
          "status": "VERIFIED",
          "createdAt": "2026-10-31T10:00:00Z",
          "txtName": "_openupi-verify.pay.chaicorner.in",
          "txtValue": "openupi-verify=3f9c2a7d1e8b4c6a9d0e1f2a3b4c5d6e",
          "verifiedAt": "2026-10-31T10:05:00Z"
         },
         "base": "https://pay.chaicorner.in"
        }
       }
      }
     },
     "409": {
      "description": "The record is not there yet"
     }
    }
   }
  },
  "/gw/v1/domain/remove": {
   "post": {
    "tags": [
     "Settings"
    ],
    "summary": "Stop using your custom domain",
    "description": "Addresses go back to the gateway's own at once.",
    "responses": {
     "200": {
      "description": "The domain",
      "content": {
       "application/json": {
        "example": {
         "domain": null,
         "base": "https://pay.example"
        }
       }
      }
     }
    }
   }
  },
  "/gw/v1/rules": {
   "get": {
    "tags": [
     "Settings"
    ],
    "summary": "Your rules",
    "description": "A rule waits for an order event (order.paid, order.failed, order.expired, order.reversed), optionally narrowed by amountOver (in the order's own currency), payerLike (a pattern like *@newbank), metaKey/metaValue, and repeat ({count, window}: the same payer's Nth paid order within the window). Then it can tag the order, hold it (onward payments to sellers wait until a person releases it), notify (a rule.matched webhook) or proposeRefund (order.paid only: a full refund joins the two-person queue; a person approves it with the PIN). A rule never declines a payment or moves money by itself. Rules run on test and live orders alike. At most 20 per shop. Owners and admins; never restricted keys.",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "example": {
         "rules": [
          {
           "name": "Big first orders",
           "when": {
            "event": "order.paid",
            "amountOver": "20000",
            "payerLike": "*@newbank"
           },
           "then": {
            "tag": "review",
            "hold": true,
            "notify": true
           },
           "id": "rule_3f9c2a7d1e8b",
           "enabled": true,
           "createdAt": "2026-10-31T10:00:00Z",
           "matched": 0
          }
         ]
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Settings"
    ],
    "summary": "Create a rule",
    "description": "A rule waits for an order event (order.paid, order.failed, order.expired, order.reversed), optionally narrowed by amountOver (in the order's own currency), payerLike (a pattern like *@newbank), metaKey/metaValue, and repeat ({count, window}: the same payer's Nth paid order within the window). Then it can tag the order, hold it (onward payments to sellers wait until a person releases it), notify (a rule.matched webhook) or proposeRefund (order.paid only: a full refund joins the two-person queue; a person approves it with the PIN). A rule never declines a payment or moves money by itself. Rules run on test and live orders alike. At most 20 per shop. Owners and admins; never restricted keys.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "example": {
        "name": "Big first orders",
        "when": {
         "event": "order.paid",
         "amountOver": "20000",
         "payerLike": "*@newbank"
        },
        "then": {
         "tag": "review",
         "hold": true,
         "notify": true
        },
        "enabled": true
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "example": {
         "name": "Big first orders",
         "when": {
          "event": "order.paid",
          "amountOver": "20000",
          "payerLike": "*@newbank"
         },
         "then": {
          "tag": "review",
          "hold": true,
          "notify": true
         },
         "id": "rule_3f9c2a7d1e8b",
         "enabled": true,
         "createdAt": "2026-10-31T10:00:00Z",
         "matched": 0
        }
       }
      }
     },
     "400": {
      "description": "A field is not allowed"
     }
    }
   }
  },
  "/gw/v1/rules/{id}": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string"
     }
    }
   ],
   "post": {
    "tags": [
     "Settings"
    ],
    "summary": "Change a rule (or turn it on or off)",
    "description": "Send the whole rule; enabled false turns it off.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "example": {
        "name": "Big first orders",
        "when": {
         "event": "order.paid",
         "amountOver": "20000",
         "payerLike": "*@newbank"
        },
        "then": {
         "tag": "review",
         "hold": true,
         "notify": true
        },
        "enabled": false
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "example": {
         "name": "Big first orders",
         "when": {
          "event": "order.paid",
          "amountOver": "20000",
          "payerLike": "*@newbank"
         },
         "then": {
          "tag": "review",
          "hold": true,
          "notify": true
         },
         "id": "rule_3f9c2a7d1e8b",
         "enabled": false,
         "createdAt": "2026-10-31T10:00:00Z",
         "matched": 0
        }
       }
      }
     },
     "404": {
      "description": "No such rule"
     }
    }
   }
  },
  "/gw/v1/rules/{id}/delete": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string"
     }
    }
   ],
   "post": {
    "tags": [
     "Settings"
    ],
    "summary": "Delete a rule",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "example": {
         "deleted": true
        }
       }
      }
     },
     "404": {
      "description": "No such rule"
     }
    }
   }
  },
  "/gw/v1/rules/backtest": {
   "post": {
    "tags": [
     "Settings"
    ],
    "summary": "Backtest a rule over your past orders",
    "description": "Replays the rule over your orders in this mode where its event happened, and reports how many it would have matched, what it would have done, and the first 20 orders. Changes nothing.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "example": {
        "name": "Big first orders",
        "when": {
         "event": "order.paid",
         "amountOver": "20000",
         "payerLike": "*@newbank"
        },
        "then": {
         "tag": "review",
         "hold": true,
         "notify": true
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "example": {
         "considered": 120,
         "matched": 3,
         "actions": {
          "tag": 3,
          "hold": 3,
          "notify": 3
         },
         "orders": [
          {
           "id": "order_77f199938ee3ffddb87d33ac",
           "orderId": "INV-1009",
           "amount": "24999.00",
           "currency": "INR",
           "createdAt": "2026-10-30T18:12:00Z"
          }
         ]
        }
       }
      }
     }
    }
   }
  },
  "/gw/v1/orders/{id}/release": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string"
     }
    }
   ],
   "post": {
    "tags": [
     "Orders"
    ],
    "summary": "Release an order a rule held",
    "description": "Onward payments to sellers can go again. Owners, admins and finance; never restricted keys.",
    "responses": {
     "200": {
      "description": "The order",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        }
       }
      }
     },
     "404": {
      "$ref": "#/components/responses/Error"
     }
    }
   }
  },
  "/gw/v1/apps": {
   "get": {
    "tags": [
     "Apps"
    ],
    "summary": "Apps you built and apps installed at your shop",
    "description": "mine: apps this shop registered (listed says whether the operator approved them for /apps). installed: apps with access to this shop, their scopes and who approved them. Not for restricted keys.",
    "responses": {
     "200": {
      "description": "Apps",
      "content": {
       "application/json": {
        "example": {
         "mine": [],
         "installed": [
          {
           "appId": "app_3f9c2a7d1e8b4c6a9d0e1f2a",
           "name": "Ledger Sync",
           "scopes": [
            "orders:read"
           ],
           "by": "owner@shop.example",
           "at": "2026-10-31T10:00:00Z",
           "webhooks": true
          }
         ]
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Apps"
    ],
    "summary": "Register an app (OAuth client)",
    "description": "An app other shops can add with OAuth 2.0 (authorization code with PKCE S256). redirectUris are exact https addresses (http only for localhost). scopes are what it may ask for. With webhookUrl, an installed app receives each installing shop's live webhooks there, signed with the webhookSecret returned here. clientSecret and webhookSecret are shown once. Flow: send the shop's owner or admin to /oauth/authorize?response_type=code&client_id=…&redirect_uri=…&scope=orders:read&state=…&code_challenge=…&code_challenge_method=S256; they approve on a consent page listing the scopes; exchange the code at POST /oauth/token (grant_type=authorization_code, code, redirect_uri, code_verifier, with client_id and client_secret) for an access token: a restricted key for that shop. Owners, admins, developers; not for restricted keys.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "example": {
        "name": "Ledger Sync",
        "description": "Copies paid orders into your accounting books every night.",
        "homepage": "https://ledgersync.example",
        "redirectUris": [
         "https://ledgersync.example/oauth/callback"
        ],
        "scopes": [
         "orders:read"
        ],
        "webhookUrl": "https://ledgersync.example/hooks/openupi"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Registered",
      "content": {
       "application/json": {
        "example": {
         "clientId": "app_3f9c2a7d1e8b4c6a9d0e1f2a",
         "clientSecret": "appsec_…",
         "webhookSecret": "whsec_…",
         "note": "This is the only time the client secret and webhook secret are shown."
        }
       }
      }
     },
     "400": {
      "description": "A field is not allowed"
     }
    }
   }
  },
  "/gw/v1/apps/{id}/uninstall": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string"
     }
    }
   ],
   "post": {
    "tags": [
     "Apps"
    ],
    "summary": "Remove an app from your shop",
    "description": "Its access token stops at once and it gets no more webhooks. Owners and admins.",
    "responses": {
     "200": {
      "description": "Removed",
      "content": {
       "application/json": {
        "example": {
         "removed": true
        }
       }
      }
     },
     "404": {
      "description": "Not installed"
     }
    }
   }
  },
  "/gw/v1/public/apps": {
   "get": {
    "tags": [
     "Public"
    ],
    "summary": "Apps the operator has approved (no key)",
    "security": [],
    "responses": {
     "200": {
      "description": "Listed apps",
      "content": {
       "application/json": {
        "example": {
         "apps": [
          {
           "id": "app_3f9c2a7d1e8b4c6a9d0e1f2a",
           "name": "Ledger Sync",
           "description": "Copies paid orders into your accounting books every night.",
           "homepage": "https://ledgersync.example",
           "scopes": [
            "orders:read"
           ],
           "by": "Ledger Sync Pvt Ltd",
           "webhooks": true
          }
         ]
        }
       }
      }
     }
    }
   }
  },
  "/gw/v1/assistant": {
   "post": {
    "tags": [
     "Orders"
    ],
    "summary": "Ask your books (the owner assistant)",
    "description": "A question in plain words about this shop's orders in the mode of the key or view asking: totals, an order's state and why, what is waiting on a person. It only reads; it cannot refund, cancel, release or send anything. engine is rules (the built-in planner) or the configured model; tools lists what it looked at. Every role may ask; not for restricted keys.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "example": {
        "question": "Why did INV-1009 fail?"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The answer",
      "content": {
       "application/json": {
        "example": {
         "answer": "Here is what I found:\norder=order_77f199938ee3ffddb87d33ac ref=INV-1009 amount=499.00 INR status=FAILED …\nmeaning: The last payment did not go through, and no money was taken. …",
         "tools": [
          "get_order"
         ],
         "engine": "rules"
        }
       }
      }
     },
     "429": {
      "description": "Too many questions; wait a moment"
     }
    }
   }
  },
  "/gw/v1/digest": {
   "get": {
    "tags": [
     "Statements"
    ],
    "summary": "A day's summary",
    "description": "Money taken (by currency) and paid, failed and pending orders on one day in the shop's zone (India), against the day before, with refunds, what is waiting on a person, and how many follow-ups are drafted. lines is the same in sentences. day defaults to yesterday.",
    "parameters": [
     {
      "name": "day",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "YYYY-MM-DD"
     }
    ],
    "responses": {
     "200": {
      "description": "The summary",
      "content": {
       "application/json": {
        "example": {
         "day": "2026-10-30",
         "takenMinor": {
          "INR": 165000
         },
         "taken": "1650.00 INR",
         "paid": 2,
         "failed": 1,
         "pending": 0,
         "refundedMinor": {},
         "changePercent": 12,
         "attention": "Nothing is waiting on a person.",
         "followUps": 1,
         "lines": [
          "On Fri 30 Oct you took 1650.00 INR from 2 paid order(s).",
          "That is 12% more than the day before (in rupees).",
          "1 payment(s) failed and 0 are still being confirmed by the banks (not failed; do not ask for them again).",
          "1 follow-up(s) are drafted for you to review."
         ]
        }
       }
      }
     }
    }
   }
  },
  "/gw/v1/notifications": {
   "get": {
    "tags": [
     "Statements"
    ],
    "summary": "What is waiting on a person",
    "description": "Each kind of thing waiting on a person at the shop: refunds to approve, orders held by a rule, overdue invoices, webhooks the shop's server never accepted. Each item has a count, a sentence and the console tab where it is dealt with. items is empty when nothing waits.",
    "responses": {
     "200": {
      "description": "The items",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "items": {
           "type": "array",
           "items": {
            "type": "object",
            "properties": {
             "kind": {
              "type": "string",
              "enum": [
               "refunds",
               "held",
               "overdue",
               "webhooks"
              ]
             },
             "count": {
              "type": "integer"
             },
             "text": {
              "type": "string"
             },
             "tab": {
              "type": "string"
             }
            }
           }
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/gw/v1/followups": {
   "get": {
    "tags": [
     "Statements"
    ],
    "summary": "Drafted follow-ups",
    "description": "Messages drafted for customers whose payment failed on an order in the last 7 days, and for overdue invoices. Each has text, a WhatsApp share link (you pick the chat) and, for invoices, action remind_invoice (POST /gw/v1/invoices/{id}/remind, which emails when mail is set up). Nothing is sent until a person sends it. Not for restricted keys.",
    "responses": {
     "200": {
      "description": "Drafts",
      "content": {
       "application/json": {
        "example": {
         "followUps": [
          {
           "key": "failed:order_77f199938ee3ffddb87d33ac",
           "kind": "payment_failed",
           "title": "Payment failed: INV-1003 (80.00 INR)",
           "to": "bob@beta",
           "text": "Hi, your payment of 80.00 INR to Chai Corner didn't go through, and nothing was taken. You can try again here: https://pay.example/checkout/order_77f199938ee3ffddb87d33ac",
           "whatsapp": "https://wa.me/?text=…",
           "target": "order_77f199938ee3ffddb87d33ac",
           "at": "2026-10-30T18:00:00Z"
          }
         ],
         "note": "Drafts only: nothing is sent until a person sends it."
        }
       }
      }
     }
    }
   }
  },
  "/gw/v1/followups/dismiss": {
   "post": {
    "tags": [
     "Statements"
    ],
    "summary": "Dismiss a follow-up",
    "description": "It does not come back.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "example": {
        "key": "failed:order_77f199938ee3ffddb87d33ac"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Dismissed",
      "content": {
       "application/json": {
        "example": {
         "dismissed": true
        }
       }
      }
     }
    }
   }
  },
  "/gw/v1/invoices/propose": {
   "post": {
    "tags": [
     "Invoices"
    ],
    "summary": "Draft an invoice from a pasted message",
    "description": "Reads a customer's message (up to 2000 characters): the customer (matched by email, phone, GSTIN or name, or proposed as new), items with quantities and prices (matched to your catalogue), and a due date like 'due in 15 days'. Returns a proposal with what it could not read and what to check. Nothing is saved; save it with POST /gw/v1/invoices. The message is data; nothing in it is followed.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "example": {
        "text": "Hi, this is Asha Traders (a@asha.example). Please send 2 cotton tees and 1 kurta @ 899, due in 15 days."
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The proposal",
      "content": {
       "application/json": {
        "example": {
         "proposal": {
          "customerId": "cus_3f9c2a7d1e8b",
          "customer": "Asha Traders",
          "lines": [
           {
            "productId": "prod_77f1999",
            "name": "Cotton tee",
            "qty": 2
           },
           {
            "name": "kurta",
            "qty": 1,
            "price": "899"
           }
          ],
          "dueDays": 15
         },
         "note": "Nothing was saved. Check it, then save it as a draft invoice."
        }
       }
      }
     }
    }
   }
  },
  "/gw/v1/disputes/{id}/draft": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string"
     }
    }
   ],
   "get": {
    "tags": [
     "Disputes"
    ],
    "summary": "Draft a reply to a dispute",
    "description": "Facts from your own records about the disputed payment (the order, when and by whom it was paid, refunds already made, delivery details in the order's metadata, whether the payer confirmed their phone) and a reply shaped by the dispute's reason, with what would make it stronger. Nothing is sent: edit it and add it with POST /gw/v1/disputes/{id}/evidence.",
    "responses": {
     "200": {
      "description": "The draft",
      "content": {
       "application/json": {
        "example": {
         "disputeId": "dsp_1",
         "facts": [
          "Order INV-1009 for 499.00 INR, transaction 7f3a…, paid on 30 Oct 2026 18:12 IST.",
          "Paid from alice@alpha.",
          "Delivery record on the order: tracking: DTDC 7781234."
         ],
         "draft": "Chai Corner responds to this dispute about transaction 7f3a… The goods were delivered: tracking: DTDC 7781234. …",
         "missing": []
        }
       }
      }
     },
     "404": {
      "description": "Not a dispute about your payments"
     }
    }
   }
  },
  "/gw/v1/rules/suggestions": {
   "get": {
    "tags": [
     "Settings"
    ],
    "summary": "Rules your history suggests",
    "description": "Patterns in your orders worth a rule (payments far above your usual, disputes clustering at one payer handle), each with its backtest on the same history. Nothing is made: create one with POST /gw/v1/rules. Not for restricted keys.",
    "responses": {
     "200": {
      "description": "Suggestions",
      "content": {
       "application/json": {
        "example": {
         "suggestions": [
          {
           "why": "Only 1 in 20 of your paid orders is above ₹4999.00. …",
           "rule": {
            "name": "Large order: check before shipping",
            "enabled": true,
            "when": {
             "event": "order.paid",
             "amountOver": "4999.00"
            },
            "then": {
             "tag": "large",
             "notify": true
            }
           },
           "backtest": {
            "considered": 120,
            "matched": 6,
            "actions": {
             "tag": 6,
             "notify": 6
            },
            "orders": []
           }
          }
         ],
         "note": "Suggestions only: a person makes a rule."
        }
       }
      }
     }
    }
   }
  },
  "/gw/v1/public/orders/{id}/ask": {
   "parameters": [
    {
     "name": "id",
     "in": "path",
     "required": true,
     "schema": {
      "type": "string"
     }
    }
   ],
   "post": {
    "tags": [
     "Public"
    ],
    "summary": "A customer's question about this payment (no key)",
    "description": "Answers from the order's real state and refunds: paid, being confirmed (never 'pay again'), failed, returned, and where a refund is. It talks only about this order, never shows the payer's address or the shop's references, cannot refund or cancel, and gives the shop's support contact when set. Rate-limited per order.",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "example": {
        "question": "Where is my refund?"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The answer",
      "content": {
       "application/json": {
        "example": {
         "answer": "Refund: 15.00 INR SENT back to the customer's account. Most banks show it at once; some take up to 5 working days.",
         "engine": "rules"
        }
       }
      }
     },
     "404": {
      "description": "No such order"
     },
     "429": {
      "description": "Too many questions; wait a moment"
     }
    }
   }
  },
  "/gw/v1/agent/audit": {
   "get": {
    "tags": [
     "Keys"
    ],
    "summary": "What AI tools did through /mcp",
    "description": "The latest 200 calls made to the merchant MCP server (POST /mcp, Model Context Protocol over JSON-RPC) with this shop's restricted keys or app tokens: tool, outcome (ok, denied, error, started) and why, with a hash of the arguments, never the arguments. Read tools need orders:read; propose_refund needs refunds:write and waits for a person with the PIN; propose_rule needs orders:write and is saved switched off. Nothing through /mcp acts by itself. Full keys are refused at /mcp. Not for restricted keys.",
    "responses": {
     "200": {
      "description": "Calls, newest first",
      "content": {
       "application/json": {
        "example": {
         "calls": [
          {
           "at": "2026-10-31T10:00:00Z",
           "agent": "shop:m1:live:key_3f9c2a7d",
           "tool": "propose_refund",
           "argsSha256": "…",
           "outcome": "ok"
          }
         ]
        }
       }
      }
     }
    }
   }
  },
  "/gw/v1/public/orders/{id}/agent-token": {
   "post": {
    "tags": [
     "Public"
    ],
    "summary": "Pay an order with an AI agent's one-time token",
    "description": "The token comes from POST /agent/v1/tokens on the payer's PSP. It is for one payee and one amount, works once and expires within an hour; the payer's bank checks the payment against the agent's reserve (ADR-087, ADR-088).",
    "security": [],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "token": {
          "type": "string"
         }
        },
        "required": [
         "token"
        ]
       },
       "example": {
        "token": "apt_..."
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The order as the checkout page sees it"
     },
     "400": {
      "description": "Unknown, used or expired token, or another payee or amount"
     },
     "404": {
      "description": "No such order"
     },
     "409": {
      "description": "Already paid or no longer payable"
     }
    }
   }
  },
  "/gw/v1/sessions": {
   "post": {
    "tags": [
     "Orders"
    ],
    "summary": "Ask for a payment inside a chat or voice conversation",
    "description": "Creates an order and answers with what a chat or voice agent shows or says: the checkout link, the standard UPI link, and words to use. With sendTo, the link is also sent by message. The order is paid like any other; the webhook says when (ADR-089).",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "orderId": {
          "type": "string"
         },
         "amount": {
          "type": "string"
         },
         "note": {
          "type": "string"
         },
         "channel": {
          "type": "string",
          "enum": [
           "chat",
           "voice"
          ]
         },
         "sendTo": {
          "type": "string"
         }
        },
        "required": [
         "orderId",
         "amount",
         "channel"
        ]
       },
       "example": {
        "orderId": "CALL-1001",
        "amount": "499.00",
        "channel": "voice",
        "sendTo": "+919800000000"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The order, checkoutUrl, upiLink, and say (voice) or show (chat); sent and sendError when sendTo was given"
     },
     "400": {
      "description": "Invalid request"
     },
     "401": {
      "description": "Missing or wrong key"
     }
    }
   }
  },
  "/gw/v1/bills": {
   "get": {
    "tags": [
     "Books"
    ],
    "summary": "List the shop's bills",
    "description": "Bills the shop owes, with the state of any payment (ADR-092).",
    "security": [],
    "responses": {
     "200": {
      "description": "{bills: [...]}"
     },
     "400": {
      "description": "Invalid request"
     },
     "401": {
      "description": "Missing or wrong key"
     },
     "403": {
      "description": "Not allowed for this key or role"
     }
    }
   },
   "post": {
    "tags": [
     "Books"
    ],
    "summary": "Add a bill to pay",
    "description": "An agent with bills:write or a person adds a bill. It is not paid until an owner or finance person pays it in the console with the shop's PIN.",
    "security": [],
    "responses": {
     "200": {
      "description": "The bill"
     },
     "400": {
      "description": "Invalid request"
     },
     "401": {
      "description": "Missing or wrong key"
     },
     "403": {
      "description": "Not allowed for this key or role"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "vendor": "Sharma Dairy",
        "payTo": "sharma@bank",
        "amount": "4200.00",
        "due": "2026-11-30",
        "note": "November milk"
       }
      }
     }
    }
   }
  },
  "/gw/v1/bills/{id}/pay": {
   "post": {
    "tags": [
     "Books"
    ],
    "summary": "Pay a bill",
    "description": "Only a signed-in person with the owner or finance role, never a key; the shop's UPI PIN is used for this one payment.",
    "security": [],
    "responses": {
     "200": {
      "description": "The bill"
     },
     "400": {
      "description": "Invalid request"
     },
     "401": {
      "description": "Missing or wrong key"
     },
     "403": {
      "description": "Not allowed for this key or role"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "pin": "1234"
       }
      }
     }
    }
   }
  },
  "/gw/v1/bills/{id}/decline": {
   "post": {
    "tags": [
     "Books"
    ],
    "summary": "Decline a bill",
    "description": "Only a signed-in person with the owner or finance role.",
    "security": [],
    "responses": {
     "200": {
      "description": "The bill"
     },
     "400": {
      "description": "Invalid request"
     },
     "401": {
      "description": "Missing or wrong key"
     },
     "403": {
      "description": "Not allowed for this key or role"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/forecast": {
   "get": {
    "tags": [
     "Books"
    ],
    "summary": "Cash-flow forecast and flags",
    "description": "The next 14 days of money expected in (issued invoices, subscription charges, the median day's takings) and out (open bills), and flags about unusual takings, refunds, failures or bills larger than income. Not a bank balance.",
    "security": [],
    "responses": {
     "200": {
      "description": "The forecast"
     },
     "400": {
      "description": "Invalid request"
     },
     "401": {
      "description": "Missing or wrong key"
     },
     "403": {
      "description": "Not allowed for this key or role"
     }
    }
   }
  },
  "/gw/v1/agent/audit.csv": {
   "get": {
    "tags": [
     "Agents"
    ],
    "summary": "Export the agent log",
    "description": "Every MCP call on the shop and every bill an agent proposed, as CSV, with emails, UPI addresses, PANs, 12-digit numbers and phone numbers removed.",
    "security": [],
    "responses": {
     "200": {
      "description": "text/csv"
     },
     "400": {
      "description": "Invalid request"
     },
     "401": {
      "description": "Missing or wrong key"
     },
     "403": {
      "description": "Not allowed for this key or role"
     }
    }
   }
  },
  "/gw/v1/shop": {
   "get": {
    "tags": [
     "Settings"
    ],
    "summary": "Read the shop: its id, name, UPI address, and whether it is a sandbox shop made at sign-up (test mode only)",
    "responses": {
     "200": {
      "description": "OK"
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "Missing or unknown key"
     },
     "403": {
      "description": "A role or a restricted key's scope does not allow it"
     }
    }
   }
  },
  "/gw/v1/acp/checkout_sessions": {
   "post": {
    "tags": [
     "Agent checkout (ACP)"
    ],
    "summary": "Start a checkout session",
    "description": "The merchant side of the Agentic Commerce Protocol's checkout. An agent platform, calling with a key you gave it (orders:write is enough), starts a session from products in your catalogue. Lines carry each product's GST; amounts are integers in paise, currency inr. The same Idempotency-Key returns the same session. API-Version and Request-Id are echoed.",
    "responses": {
     "200": {
      "description": "The checkout session"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "items": {
          "type": "array",
          "items": {
           "type": "object",
           "properties": {
            "id": {
             "type": "string",
             "description": "A product id from your catalogue"
            },
            "quantity": {
             "type": "integer"
            }
           }
          }
         },
         "buyer": {
          "type": "object"
         },
         "fulfillment_address": {
          "type": "object"
         }
        }
       },
       "example": {
        "items": [
         {
          "id": "prod_tee",
          "quantity": 2
         }
        ],
        "buyer": {
         "first_name": "Asha",
         "email": "asha@example.com"
        }
       }
      }
     }
    }
   }
  },
  "/gw/v1/acp/checkout_sessions/{id}": {
   "get": {
    "tags": [
     "Agent checkout (ACP)"
    ],
    "summary": "Read a checkout session",
    "description": "The session: status (not_ready_for_payment, ready_for_payment, completed, canceled), line_items, totals, messages and, once completed, the order.",
    "responses": {
     "200": {
      "description": "The checkout session"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   },
   "post": {
    "tags": [
     "Agent checkout (ACP)"
    ],
    "summary": "Update a checkout session",
    "description": "Change the items or the buyer of an open session; totals are worked out again.",
    "responses": {
     "200": {
      "description": "The checkout session"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "items": {
          "type": "array",
          "items": {
           "type": "object",
           "properties": {
            "id": {
             "type": "string",
             "description": "A product id from your catalogue"
            },
            "quantity": {
             "type": "integer"
            }
           }
          }
         },
         "buyer": {
          "type": "object"
         }
        }
       },
       "example": {
        "items": [
         {
          "id": "prod_tee",
          "quantity": 3
         }
        ]
       }
      }
     }
    }
   }
  },
  "/gw/v1/acp/checkout_sessions/{id}/complete": {
   "post": {
    "tags": [
     "Agent checkout (ACP)"
    ],
    "summary": "Complete a checkout session",
    "description": "Pay with payment_data: {token, provider: \"agentgrid\"}. The token is a one-time Agentgrid agent token (apt_…) for exactly your shop and the session's total; completing spends it and pays from the agent's reserve, which the payer's bank checks. Makes your order (orderId = the session id, metadata acp_session) and answers with the completed session and its order. Completing again answers the same. A refused payment answers 402 with type processing_error.",
    "responses": {
     "200": {
      "description": "The checkout session"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "payment_data": {
          "type": "object",
          "properties": {
           "token": {
            "type": "string"
           },
           "provider": {
            "type": "string"
           }
          }
         },
         "buyer": {
          "type": "object"
         }
        }
       },
       "example": {
        "payment_data": {
         "token": "apt_…",
         "provider": "agentgrid"
        }
       }
      }
     }
    }
   }
  },
  "/gw/v1/acp/checkout_sessions/{id}/cancel": {
   "post": {
    "tags": [
     "Agent checkout (ACP)"
    ],
    "summary": "Cancel a checkout session",
    "description": "Cancel an open session. A completed one cannot be canceled (405): refund its order instead.",
    "responses": {
     "200": {
      "description": "The checkout session"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/public/orders/{id}/ap2-cart": {
   "get": {
    "tags": [
     "Agent checkout (ACP)"
    ],
    "summary": "An order as an AP2 CartMandate",
    "description": "An open order as a CartMandate in the format of Google's Agent Payments Protocol (AP2). merchant_authorization is a JWT, EdDSA by the PSP's record key (kid psp-records in /.well-known/agent-keys), with cart_hash: SHA-256, base64url, of the contents as canonical JSON (keys sorted, no spaces). It lasts 15 minutes or until the order expires. An agent pays it at POST /agent/v1/ap2/pay. No key: like the checkout page, the order id is the secret.",
    "responses": {
     "200": {
      "description": "The CartMandate"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/activation": {
   "get": {
    "tags": [
     "Account"
    ],
    "summary": "Your request to go live",
    "description": "state is none, draft, submitted, changes_requested, approved, rejected, or live for a shop that never was a sandbox. The account number is masked but for its last four digits; note is the operator's reason. Signed-in people only: no key may read it.",
    "responses": {
     "200": {
      "description": "The state and the request"
     }
    }
   },
   "post": {
    "tags": [
     "Account"
    ],
    "summary": "Ask to go live",
    "description": "A sandbox shop's owner or an admin, signed in to the console, sends the business's details and its settlement account. With submit true it goes to the operator for review; without, it is kept as a draft. An operator approves (the shop leaves the sandbox: live keys and live mode open), asks for changes with a note, or refuses with a reason. No API key can send it. A masked account number sent back unchanged keeps the stored one.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "legalName": "Chai Corner LLP",
        "businessType": "llp",
        "pan": "ABCDE1234F",
        "gstin": "27ABCDE1234F1Z5",
        "address": "12 MG Road",
        "city": "Pune",
        "stateName": "Maharashtra",
        "pinCode": "411001",
        "sells": "Tea and snacks",
        "phone": "+919876543210",
        "accountHolder": "Chai Corner LLP",
        "accountNumber": "123456789012",
        "ifsc": "HDFC0001234",
        "submit": true
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The saved request, account masked"
     },
     "400": {
      "description": "What is missing or wrong"
     },
     "403": {
      "description": "Sent with a key, not by a person"
     }
    }
   }
  },
  "/gw/v1/vendors": {
   "get": {
    "tags": [
     "Bills & cash"
    ],
    "summary": "Saved vendors",
    "description": "The shop's vendors: a name and a UPI address, kept once so a bill or a recurring bill names the vendor.",
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   },
   "post": {
    "tags": [
     "Bills & cash"
    ],
    "summary": "Save a vendor",
    "description": "Add a vendor, or change one by its id. A person signed in to the console (owner, admin or finance) does this; no key can, because it decides where money goes.",
    "responses": {
     "200": {
      "description": "OK"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "name": "Sharma Dairy",
        "payTo": "sharmadairy@bank",
        "note": "Milk, daily"
       }
      }
     }
    }
   }
  },
  "/gw/v1/bills/recurring": {
   "get": {
    "tags": [
     "Bills & cash"
    ],
    "summary": "Recurring bills",
    "description": "Each schedule: the vendor, amount, how often (weekly, monthly, quarterly) and the next due date.",
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   },
   "post": {
    "tags": [
     "Bills & cash"
    ],
    "summary": "Start a recurring bill",
    "description": "For a saved vendor. A week before each due date it adds an ordinary OPEN bill; a person still pays every one with the shop's PIN. Nothing pays itself. People only.",
    "responses": {
     "200": {
      "description": "OK"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "vendorId": "vnd_…",
        "amount": "25000.00",
        "every": "monthly",
        "firstDue": "2026-12-01",
        "note": "Rent"
       }
      }
     }
    }
   }
  },
  "/gw/v1/bills/recurring/{id}/stop": {
   "post": {
    "tags": [
     "Bills & cash"
    ],
    "summary": "Stop a recurring bill",
    "description": "No more bills are made; the ones already made stay.",
    "responses": {
     "200": {
      "description": "OK"
     }
    },
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ]
   }
  },
  "/gw/v1/balance": {
   "get": {
    "tags": [
     "Bills & cash"
    ],
    "summary": "The shop's bank balance, if known",
    "description": "The bank's figure when a bank offers it, or the one a person entered, with its date and source. known is false when there is none. People only.",
    "responses": {
     "200": {
      "description": "OK"
     }
    }
   },
   "post": {
    "tags": [
     "Bills & cash"
    ],
    "summary": "Enter the bank balance",
    "description": "A person enters the balance as their bank shows it, with the date (today if empty). The forecast runs it forward day by day and flags a day it would go below zero. A minus sign marks an overdrawn account.",
    "responses": {
     "200": {
      "description": "OK"
     }
    },
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object"
       },
       "example": {
        "amount": "84250.00",
        "asOf": "2026-11-17"
       }
      }
     }
    }
   }
  }
 },
 "x-webhooks": {
  "description": "JSON POSTs to the shop's webhook address. Events: order.paid, order.failed, order.expired, order.reversed,\norder.cancelled, refund.processed, refund.failed, ping. Body: event, id, orderId, amount, amountPaise, status,\npaymentId, deliveryId, timestamp, and metadata when the order has any.\nHeaders: X-Gateway-Signature-V2 = hex HMAC-SHA256(secret, timestamp + \".\" + rawBody) (prefer this; reject old timestamps),\nX-Gateway-Signature = hex HMAC-SHA256(secret, rawBody), X-Gateway-Delivery-Id (stable across retries: deduplicate),\nX-Gateway-Event, X-Gateway-Timestamp. Answer any 2xx; failures retry for one hour, then ABANDONED.\n"
 },
 "tags": [
  {
   "name": "Orders"
  },
  {
   "name": "Refunds"
  },
  {
   "name": "Links"
  },
  {
   "name": "Webhooks"
  },
  {
   "name": "Keys"
  },
  {
   "name": "Customers"
  },
  {
   "name": "Products"
  },
  {
   "name": "Invoices"
  },
  {
   "name": "Subscriptions"
  },
  {
   "name": "Statements"
  },
  {
   "name": "Splits"
  },
  {
   "name": "Disputes"
  },
  {
   "name": "Offers"
  },
  {
   "name": "Settings"
  },
  {
   "name": "Apps",
   "description": "Third-party apps on OAuth"
  },
  {
   "name": "Public"
  }
 ]
}