{
    "openapi": "3.0.3",
    "info": {
        "title": "QRIS Dinamis API",
        "version": "1.0.0",
        "description": "Mengubah QRIS statis menjadi QRIS dinamis (nominal terisi). Satu endpoint utama: POST /qris membentuk payload EMVCo/QRIS dinamis (tag 01=12, tag 54=nominal, tag fee 55/56/57 opsional, CRC16-CCITT tag 63 dihitung ulang). Layanan ini HANYA membentuk payload — tidak ada callback/notifikasi pembayaran; pelunasan dicek lewat mutasi/penyedia QRIS."
    },
    "servers": [
        {
            "url": "https://www.pay.3core.web.id/api/v1"
        }
    ],
    "security": [
        {
            "bearerAuth": []
        },
        {
            "apiKeyHeader": []
        }
    ],
    "paths": {
        "/merchants": {
            "get": {
                "summary": "Daftar merchant aktif",
                "description": "Merchant yang boleh dipakai key ini. Key yang dibatasi ke satu merchant hanya mengembalikan merchant itu.",
                "security": [
                    {
                        "bearerAuth": []
                    },
                    {
                        "apiKeyHeader": []
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Merchant"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/qris": {
            "get": {
                "summary": "Riwayat QRIS dinamis",
                "security": [
                    {
                        "bearerAuth": []
                    },
                    {
                        "apiKeyHeader": []
                    }
                ],
                "parameters": [
                    {
                        "name": "merchant",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        },
                        "description": "Kode merchant. Diabaikan bila key dibatasi ke satu merchant."
                    },
                    {
                        "name": "reference",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        },
                        "description": "Pencarian substring reference."
                    },
                    {
                        "name": "from",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "format": "date"
                        },
                        "description": "YYYY-MM-DD."
                    },
                    {
                        "name": "to",
                        "in": "query",
                        "schema": {
                            "type": "string",
                            "format": "date"
                        },
                        "description": "YYYY-MM-DD."
                    },
                    {
                        "name": "page",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "default": 1
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK (50/halaman, TANPA payload — ambil per id bila butuh payload)",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/GenerationListItem"
                                            }
                                        },
                                        "meta": {
                                            "$ref": "#/components/schemas/PageMeta"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            },
            "post": {
                "summary": "Buat QRIS dinamis",
                "security": [
                    {
                        "bearerAuth": []
                    },
                    {
                        "apiKeyHeader": []
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/CreateQris"
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "Created",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Generation"
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Unauthorized"
                    },
                    "404": {
                        "$ref": "#/components/responses/NotFound"
                    },
                    "422": {
                        "$ref": "#/components/responses/Unprocessable"
                    }
                }
            }
        },
        "/qris/{id}": {
            "get": {
                "summary": "Satu QRIS beserta payload",
                "security": [
                    {
                        "bearerAuth": []
                    },
                    {
                        "apiKeyHeader": []
                    }
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Generation"
                                }
                            }
                        }
                    },
                    "404": {
                        "$ref": "#/components/responses/NotFound"
                    }
                }
            }
        },
        "/qris/{id}/qr.png": {
            "get": {
                "summary": "Gambar QR (PNG)",
                "description": "Tambahkan ?download=1 untuk memaksa unduh. Butuh header API key.",
                "security": [
                    {
                        "bearerAuth": []
                    },
                    {
                        "apiKeyHeader": []
                    }
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "PNG"
                    }
                }
            }
        },
        "/qris/{id}/qr.svg": {
            "get": {
                "summary": "Gambar QR (SVG)",
                "description": "Tambahkan ?download=1 untuk memaksa unduh. Butuh header API key.",
                "security": [
                    {
                        "bearerAuth": []
                    },
                    {
                        "apiKeyHeader": []
                    }
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "SVG"
                    }
                }
            }
        }
    },
    "components": {
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "description": "Authorization: Bearer qk_..."
            },
            "apiKeyHeader": {
                "type": "apiKey",
                "in": "header",
                "name": "X-API-Key",
                "description": "X-API-Key: qk_..."
            }
        },
        "responses": {
            "Unauthorized": {
                "description": "API key tidak ada / tidak valid / dicabut (status 401, error.code=unauthorized)"
            },
            "NotFound": {
                "description": "Tidak ditemukan atau di luar cakupan key (status 404)"
            },
            "Unprocessable": {
                "description": "Validasi gagal: invalid_merchant / invalid_amount / invalid_request (status 422)"
            }
        },
        "schemas": {
            "Merchant": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "integer"
                    },
                    "code": {
                        "type": "string"
                    },
                    "name": {
                        "type": "string"
                    },
                    "city": {
                        "type": "string",
                        "nullable": true
                    },
                    "nmid": {
                        "type": "string",
                        "nullable": true
                    },
                    "active": {
                        "type": "boolean"
                    }
                }
            },
            "CreateQris": {
                "type": "object",
                "required": [
                    "amount"
                ],
                "properties": {
                    "merchant": {
                        "type": "string",
                        "description": "Kode merchant. Wajib kecuali key dibatasi ke satu merchant."
                    },
                    "amount": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 999999999999,
                        "description": "Nominal rupiah, bilangan bulat."
                    },
                    "fee_type": {
                        "type": "string",
                        "enum": [
                            "none",
                            "fixed",
                            "percent"
                        ],
                        "default": "none"
                    },
                    "fee_value": {
                        "description": "Rupiah bulat 1–999999999 (fixed) atau 0–100 maks 2 desimal (percent)."
                    },
                    "reference": {
                        "type": "string",
                        "maxLength": 100,
                        "description": "Nomor invoice/pesanan, bisa dicari via GET /qris?reference=."
                    },
                    "include_qr": {
                        "type": "boolean",
                        "description": "true → respons memuat qr_svg (data URI)."
                    }
                }
            },
            "Generation": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "integer"
                    },
                    "merchant": {
                        "type": "string"
                    },
                    "reference": {
                        "type": "string",
                        "nullable": true
                    },
                    "amount": {
                        "type": "integer"
                    },
                    "fee": {
                        "type": "object",
                        "properties": {
                            "type": {
                                "type": "string",
                                "enum": [
                                    "none",
                                    "fixed",
                                    "percent"
                                ]
                            },
                            "value": {
                                "type": "number",
                                "nullable": true
                            },
                            "amount": {
                                "type": "integer",
                                "description": "Fee dalam rupiah (percent dibulatkan)."
                            }
                        }
                    },
                    "total": {
                        "type": "integer"
                    },
                    "created_at": {
                        "type": "string",
                        "format": "date-time"
                    },
                    "payload": {
                        "type": "string",
                        "description": "String EMVCo/QRIS siap dirender jadi QR."
                    },
                    "image_url": {
                        "type": "string",
                        "description": "Hanya di POST /qris. GET gambar tetap butuh header API key."
                    },
                    "qr_svg": {
                        "type": "string",
                        "description": "Hanya bila include_qr=true. Data URI SVG."
                    }
                }
            },
            "GenerationListItem": {
                "type": "object",
                "description": "Sama seperti Generation tanpa payload.",
                "properties": {
                    "id": {
                        "type": "integer"
                    },
                    "merchant": {
                        "type": "string"
                    },
                    "reference": {
                        "type": "string",
                        "nullable": true
                    },
                    "amount": {
                        "type": "integer"
                    },
                    "fee": {
                        "type": "object"
                    },
                    "total": {
                        "type": "integer"
                    },
                    "created_at": {
                        "type": "string",
                        "format": "date-time"
                    }
                }
            },
            "PageMeta": {
                "type": "object",
                "properties": {
                    "page": {
                        "type": "integer"
                    },
                    "pages": {
                        "type": "integer"
                    },
                    "total": {
                        "type": "integer"
                    },
                    "per_page": {
                        "type": "integer"
                    }
                }
            }
        }
    }
}