{
 "openapi": "3.1.0",
 "info": {
  "title": "QRIS Connect API",
  "version": "1.0.0",
  "description": "API merchant untuk membuat dan membaca invoice QRIS. Callback ditandatangani HMAC-SHA256 (header Qris-Signature). Panduan: https://qris.qumatic.com/docs/api.md"
 },
 "servers": [
  {
   "url": "https://qris.qumatic.com"
  }
 ],
 "security": [
  {
   "bearerAuth": []
  }
 ],
 "paths": {
  "/v1/invoices": {
   "post": {
    "operationId": "createInvoice",
    "summary": "Buat invoice",
    "description": "Idempoten per ref: ref dan amount sama mengembalikan invoice yang ada dengan 200. Body maksimal 16 KB.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/InvoiceInput"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Invoice baru dibuat.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Invoice"
        }
       }
      }
     },
     "200": {
      "description": "Invoice dengan ref yang sama sudah ada.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Invoice"
        }
       }
      }
     },
     "400": {
      "description": "validation: input salah.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "402": {
      "description": "subscription_required: kuota gratis habis atau batas paket tercapai.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "ref_conflict (ref sama, amount berbeda), no_slot (nominal unik habis), atau no_merchant (klien belum punya QRIS aktif).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "413": {
      "description": "validation: body lebih dari 16 KB.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "API key salah atau sudah dicabut (unauthorized).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Terlalu banyak request, maksimal 60 per 10 detik per API key (rate_limited).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      },
      "headers": {
       "Retry-After": {
        "schema": {
         "type": "integer"
        },
        "description": "Detik tunggu."
       }
      }
     },
     "500": {
      "description": "internal",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "get": {
    "operationId": "listInvoices",
    "summary": "Daftar invoice klien",
    "parameters": [
     {
      "name": "status",
      "in": "query",
      "schema": {
       "$ref": "#/components/schemas/Status"
      }
     },
     {
      "name": "ref",
      "in": "query",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 50
      }
     },
     {
      "name": "cursor",
      "in": "query",
      "description": "Isi dengan next_cursor dari respons sebelumnya.",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Daftar invoice.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "next_cursor"
         ],
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Invoice"
           }
          },
          "next_cursor": {
           "type": [
            "string",
            "null"
           ]
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "validation: status, limit, atau cursor salah.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "API key salah atau sudah dicabut (unauthorized).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Terlalu banyak request, maksimal 60 per 10 detik per API key (rate_limited).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      },
      "headers": {
       "Retry-After": {
        "schema": {
         "type": "integer"
        },
        "description": "Detik tunggu."
       }
      }
     }
    }
   }
  },
  "/v1/invoices/{id}": {
   "get": {
    "operationId": "getInvoice",
    "summary": "Baca satu invoice",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[A-Za-z0-9_]+$"
      },
      "example": "inv_XXXX"
     }
    ],
    "responses": {
     "200": {
      "description": "Invoice.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Invoice"
        }
       }
      }
     },
     "404": {
      "description": "not_found: invoice tidak ada, atau milik klien lain.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "API key salah atau sudah dicabut (unauthorized).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Terlalu banyak request, maksimal 60 per 10 detik per API key (rate_limited).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      },
      "headers": {
       "Retry-After": {
        "schema": {
         "type": "integer"
        },
        "description": "Detik tunggu."
       }
      }
     }
    }
   }
  },
  "/v1/invoices/{id}/cancel": {
   "post": {
    "operationId": "cancelInvoice",
    "summary": "Batalkan invoice",
    "description": "Invoice pending menjadi cancelled. Status final lain dikembalikan apa adanya dengan 200.",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[A-Za-z0-9_]+$"
      },
      "example": "inv_XXXX"
     }
    ],
    "responses": {
     "200": {
      "description": "Invoice setelah pembatalan.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Invoice"
        }
       }
      }
     },
     "404": {
      "description": "not_found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "already_paid: invoice sudah lunas.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "API key salah atau sudah dicabut (unauthorized).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Terlalu banyak request, maksimal 60 per 10 detik per API key (rate_limited).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      },
      "headers": {
       "Retry-After": {
        "schema": {
         "type": "integer"
        },
        "description": "Detik tunggu."
       }
      }
     }
    }
   }
  },
  "/v1/invoices/{id}/qr.svg": {
   "get": {
    "operationId": "getInvoiceQr",
    "summary": "Gambar QR invoice (SVG)",
    "description": "Publik, tanpa API key; dibatasi per IP. Hanya untuk invoice pending.",
    "security": [],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[A-Za-z0-9_]+$"
      },
      "example": "inv_XXXX"
     }
    ],
    "responses": {
     "200": {
      "description": "QR dalam SVG.",
      "content": {
       "image/svg+xml": {
        "schema": {
         "type": "string"
        }
       }
      }
     },
     "404": {
      "description": "not_found",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "410": {
      "description": "gone: status invoice bukan pending.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "rate_limited",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  }
 },
 "webhooks": {
  "invoice.paid": {
   "post": {
    "summary": "Invoice lunas",
    "description": "Dikirim ke callback URL klien. Verifikasi Qris-Signature atas body mentah, dedup lewat Qris-Event-Id, lalu konfirmasi dengan GET /v1/invoices/{id}. Balas 2xx hanya bila selesai; selain itu diulang.",
    "parameters": [
     {
      "name": "Qris-Signature",
      "in": "header",
      "required": true,
      "description": "t=<unix>,v1=<hex>; v1 = HMAC-SHA256(signing secret, t + \".\" + body mentah).",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "Qris-Event-Id",
      "in": "header",
      "required": true,
      "description": "Sama dengan id di body.",
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/Event"
       }
      }
     }
    },
    "responses": {
     "2XX": {
      "description": "Event diterima dan selesai diproses."
     }
    }
   }
  },
  "invoice.expired": {
   "post": {
    "summary": "Invoice lewat batas waktu",
    "description": "Dikirim sekali per invoice yang kedaluwarsa. Header dan aturan sama dengan invoice.paid.",
    "parameters": [
     {
      "name": "Qris-Signature",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "Qris-Event-Id",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/Event"
       }
      }
     }
    },
    "responses": {
     "2XX": {
      "description": "Event diterima dan selesai diproses."
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "bearerAuth": {
    "type": "http",
    "scheme": "bearer",
    "description": "API key klien (qk_...) dari dashboard."
   }
  },
  "schemas": {
   "Status": {
    "type": "string",
    "enum": [
     "pending",
     "paid",
     "expired",
     "cancelled"
    ]
   },
   "InvoiceInput": {
    "type": "object",
    "required": [
     "amount",
     "ref"
    ],
    "additionalProperties": true,
    "properties": {
     "amount": {
      "type": "integer",
      "minimum": 1,
      "maximum": 10000000,
      "description": "Rupiah, nominal dasar."
     },
     "ref": {
      "type": "string",
      "pattern": "^[A-Za-z0-9:_\\-.]{1,100}$",
      "description": "Kunci idempotensi per klien."
     },
     "description": {
      "type": "string",
      "maxLength": 500
     },
     "customer_name": {
      "type": "string",
      "maxLength": 100
     },
     "metadata": {
      "type": "object",
      "description": "Maksimal 2 KB. Dikembalikan apa adanya.",
      "additionalProperties": true
     },
     "expires_in": {
      "type": "integer",
      "minimum": 60,
      "maximum": 604800,
      "default": 86400,
      "description": "Detik."
     },
     "return_url": {
      "type": "string",
      "format": "uri",
      "pattern": "^https://",
      "maxLength": 500
     }
    }
   },
   "Invoice": {
    "type": "object",
    "required": [
     "id",
     "ref",
     "status",
     "base_amount",
     "unique_code",
     "amount",
     "description",
     "customer_name",
     "metadata",
     "payload",
     "qr_svg_url",
     "pay_url",
     "return_url",
     "created_at",
     "expires_at",
     "paid_at",
     "cancelled_at"
    ],
    "properties": {
     "id": {
      "type": "string"
     },
     "ref": {
      "type": "string"
     },
     "status": {
      "$ref": "#/components/schemas/Status"
     },
     "base_amount": {
      "type": "integer"
     },
     "unique_code": {
      "type": "integer",
      "description": "1 sampai 999."
     },
     "amount": {
      "type": "integer",
      "description": "Nominal persis yang harus dibayar pelanggan."
     },
     "description": {
      "type": [
       "string",
       "null"
      ]
     },
     "customer_name": {
      "type": [
       "string",
       "null"
      ]
     },
     "metadata": {
      "type": [
       "object",
       "null"
      ],
      "additionalProperties": true
     },
     "payload": {
      "type": [
       "string",
       "null"
      ],
      "description": "String QRIS; hanya terisi saat status pending."
     },
     "qr_svg_url": {
      "type": "string",
      "format": "uri"
     },
     "pay_url": {
      "type": "string",
      "format": "uri"
     },
     "return_url": {
      "type": [
       "string",
       "null"
      ]
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     },
     "paid_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "cancelled_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     }
    }
   },
   "Error": {
    "type": "object",
    "required": [
     "error"
    ],
    "properties": {
     "error": {
      "type": "object",
      "required": [
       "code",
       "message"
      ],
      "properties": {
       "code": {
        "type": "string",
        "enum": [
         "validation",
         "unauthorized",
         "subscription_required",
         "not_found",
         "ref_conflict",
         "no_slot",
         "no_merchant",
         "already_paid",
         "gone",
         "rate_limited",
         "internal"
        ]
       },
       "message": {
        "type": "string"
       }
      }
     }
    }
   },
   "Event": {
    "type": "object",
    "required": [
     "id",
     "type",
     "created_at",
     "data"
    ],
    "properties": {
     "id": {
      "type": "string",
      "description": "evt_..."
     },
     "type": {
      "type": "string",
      "enum": [
       "invoice.paid",
       "invoice.expired"
      ]
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "data": {
      "$ref": "#/components/schemas/Invoice"
     }
    }
   }
  }
 }
}