{
  "openapi": "3.1.0",
  "info": {
    "title": "BabyGo Gateway API",
    "version": "1.0.0",
    "description": "Machine-readable overview of the public BabyGo gateway endpoints documented on https://app.babygo.my.id/docs."
  },
  "servers": [
    {
      "url": "https://api.babygo.my.id",
      "description": "Production API"
    }
  ],
  "tags": [
    {
      "name": "gateway",
      "description": "Checkout and payment status operations"
    },
    {
      "name": "public",
      "description": "Publicly accessible invoice assets"
    },
    {
      "name": "webhooks",
      "description": "Webhook payloads BabyGo can send to your system"
    }
  ],
  "paths": {
    "/api/gateway/checkout": {
      "post": {
        "tags": [
          "gateway"
        ],
        "summary": "Create Checkout",
        "description": "Create a dynamic QRIS invoice from a connected merchant.",
        "security": [
          {
            "clientApiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CheckoutRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Checkout created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckoutResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/ErrorResponse"
          }
        }
      }
    },
    "/api/gateway/transactions/{referenceLabel}": {
      "get": {
        "tags": [
          "gateway"
        ],
        "summary": "Get Payment Status",
        "description": "Read the current invoice and payment status using BabyGo reference label.",
        "security": [
          {
            "clientApiKey": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/referenceLabel"
          }
        ],
        "responses": {
          "200": {
            "description": "Payment status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentStatusResponse"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/ErrorResponse"
          }
        }
      }
    },
    "/api/gateway/transactions/{referenceLabel}/check-status": {
      "post": {
        "tags": [
          "gateway"
        ],
        "summary": "Refresh Payment Status",
        "description": "Trigger a fresh status check against upstream journal data, then return the latest status.",
        "security": [
          {
            "clientApiKey": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/referenceLabel"
          }
        ],
        "responses": {
          "200": {
            "description": "Refreshed payment status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentStatusResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/gateway/transactions/{referenceLabel}/cancel": {
      "post": {
        "tags": [
          "gateway"
        ],
        "summary": "Cancel Invoice",
        "description": "Cancel an unpaid invoice so it cannot be used any further.",
        "security": [
          {
            "clientApiKey": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/referenceLabel"
          }
        ],
        "responses": {
          "200": {
            "description": "Invoice cancelled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentStatusResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/public/invoices/{invoiceId}/qr": {
      "get": {
        "tags": [
          "public"
        ],
        "summary": "Public QR URL",
        "description": "Fetch the QR image for a public invoice.",
        "parameters": [
          {
            "name": "invoiceId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "QR image stream"
          },
          "404": {
            "$ref": "#/components/responses/ErrorResponse"
          }
        }
      }
    }
  },
  "webhooks": {
    "invoicePaid": {
      "post": {
        "tags": [
          "webhooks"
        ],
        "summary": "Invoice paid callback",
        "description": "Example webhook payload BabyGo can send to your callback URL when invoice payment status changes.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookPayload"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Receiver accepted webhook"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "clientApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-client-api-key",
        "description": "Preferred auth header. Authorization: Bearer YOUR_CLIENT_API_KEY is also accepted."
      }
    },
    "parameters": {
      "referenceLabel": {
        "name": "referenceLabel",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string"
        },
        "description": "BabyGo invoice reference label, for example INV-ABC123."
      }
    },
    "responses": {
      "ErrorResponse": {
        "description": "API error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      }
    },
    "schemas": {
      "CheckoutRequest": {
        "type": "object",
        "required": [
          "merchantConnectionId",
          "amount"
        ],
        "properties": {
          "merchantConnectionId": {
            "type": "string"
          },
          "amount": {
            "type": "integer",
            "minimum": 1
          },
          "expiresInMinutes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1440
          }
        }
      },
      "CheckoutResponse": {
        "type": "object",
        "properties": {
          "data": {
            "$ref": "#/components/schemas/PaymentStatusEnvelope"
          }
        }
      },
      "PaymentStatusResponse": {
        "type": "object",
        "properties": {
          "data": {
            "$ref": "#/components/schemas/PaymentStatusEnvelope"
          }
        }
      },
      "PaymentStatusEnvelope": {
        "type": "object",
        "properties": {
          "invoice": {
            "$ref": "#/components/schemas/Invoice"
          },
          "qrisString": {
            "type": "string"
          },
          "qrUrl": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "Invoice": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "referenceLabel": {
            "type": "string"
          },
          "externalReference": {
            "type": [
              "string",
              "null"
            ]
          },
          "amount": {
            "type": "integer"
          },
          "currency": {
            "type": "string",
            "default": "IDR"
          },
          "status": {
            "type": "string"
          },
          "paidAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "merchantConnectionId": {
            "type": "string"
          }
        }
      },
      "WebhookPayload": {
        "type": "object",
        "properties": {
          "callbackId": {
            "type": "string"
          },
          "event": {
            "type": "string",
            "example": "invoice.paid"
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time"
          },
          "client": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "code": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "invoice": {
            "$ref": "#/components/schemas/Invoice"
          }
        }
      },
      "ErrorEnvelope": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
