{
  "openapi": "3.0.3",
  "info": {
    "title": "상주곶감촌 AI 주문 접수 API",
    "version": "1.0.0",
    "description": "상주곶감촌(https://gotgamchon.com)의 무통장입금 주문 접수 API입니다. 가격은 서버가 계산하며, 결제(입금)는 구매자 본인이 해야 합니다. 구매자의 개인정보 수집·이용 및 이용약관 동의를 받은 뒤에만 주문하세요. 문의: 080-535-2646",
    "contact": { "name": "상주곶감촌", "url": "https://gotgamchon.com", "email": "gam7000@naver.com" }
  },
  "servers": [{ "url": "https://gotgamchon.com/plugin/gc_aiorder" }],
  "externalDocs": { "description": "사람이 읽는 AI 주문 안내", "url": "https://gotgamchon.com/bbs/content.php?co_id=ai_order" },
  "paths": {
    "/catalog.php": {
      "get": {
        "operationId": "getCatalog",
        "summary": "주문 가능한 상품·가격·재고·배송 규칙 조회",
        "responses": {
          "200": { "description": "상품 목록과 결제·배송 안내", "content": { "application/json": { "schema": { "type": "object" } } } },
          "429": { "description": "요청이 너무 많음" }
        }
      }
    },
    "/order.php": {
      "post": {
        "operationId": "createOrder",
        "summary": "무통장입금 주문 접수 (dry_run 으로 금액 먼저 확인)",
        "description": "1) dry_run=true 로 보내 합계(배송비 포함)를 구매자에게 확인받습니다. 2) dry_run 을 빼고 같은 요청을 보내면 주문이 접수됩니다. 응답의 주문번호·PIN·입금 계좌·금액을 구매자에게 그대로 전달하세요. PIN 은 이번 응답에서만 알려 줍니다. client_order_key 를 쓰면 재시도해도 중복 주문되지 않습니다.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/OrderRequest" },
              "example": {
                "agree": true,
                "dry_run": true,
                "client_order_key": "my-order-0001",
                "buyer": { "name": "홍길동", "phone": "010-1234-5678", "email": "buyer@example.com" },
                "receiver": { "name": "김철수", "phone": "010-9999-8888", "zip": "37100", "address1": "경상북도 상주시 ○○로 1", "address2": "101동 202호" },
                "deposit_name": "홍길동",
                "items": [{ "item_id": "14", "qty": 1 }]
              }
            }
          }
        },
        "responses": {
          "200": { "description": "dry_run 이면 금액 계산 결과, 아니면 주문 접수 결과(주문번호·PIN·입금 안내)", "content": { "application/json": { "schema": { "type": "object" } } } },
          "422": { "description": "입력 오류(필드 목록 포함), 품절·재고 부족·주문 불가 상품" },
          "429": { "description": "주문 접수 한도 초과(IP·이메일·전화번호별)" }
        }
      }
    },
    "/status.php": {
      "get": {
        "operationId": "getOrderStatus",
        "summary": "주문 상태 조회 (입금 대기·입금 확인·준비·배송·완료)",
        "description": "AI 로 접수한 주문만 조회할 수 있습니다. PIN 은 주소가 아니라 헤더 X-Order-Pin 으로 보냅니다.",
        "parameters": [
          { "name": "order_id", "in": "query", "required": true, "schema": { "type": "string" }, "description": "주문 접수 때 받은 주문번호" },
          { "name": "X-Order-Pin", "in": "header", "required": true, "schema": { "type": "string" }, "description": "주문 접수 때 받은 PIN(숫자 6자리)" }
        ],
        "responses": {
          "200": { "description": "주문 상태·입금·배송 정보", "content": { "application/json": { "schema": { "type": "object" } } } },
          "404": { "description": "주문번호 또는 PIN 이 올바르지 않음" },
          "429": { "description": "확인 시도가 너무 많음" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "OrderRequest": {
        "type": "object",
        "required": ["agree", "buyer", "receiver", "items"],
        "properties": {
          "agree": { "type": "boolean", "description": "구매자의 개인정보 수집·이용 및 이용약관 동의를 받았으면 true (필수)" },
          "dry_run": { "type": "boolean", "description": "true 이면 저장하지 않고 금액만 계산" },
          "agent": { "type": "string", "maxLength": 40, "description": "(선택) 사용 중인 AI 이름" },
          "client_order_key": { "type": "string", "maxLength": 40, "description": "(선택, 권장) 같은 키로 다시 보내면 기존 주문을 돌려줌" },
          "buyer": {
            "type": "object",
            "required": ["name", "phone", "email"],
            "properties": {
              "name": { "type": "string", "minLength": 2, "maxLength": 20 },
              "phone": { "type": "string", "description": "숫자 9~11자리" },
              "email": { "type": "string", "format": "email" }
            }
          },
          "receiver": {
            "type": "object",
            "required": ["zip", "address1"],
            "properties": {
              "name": { "type": "string", "maxLength": 20, "description": "생략하면 구매자 이름" },
              "phone": { "type": "string", "description": "생략하면 구매자 전화" },
              "zip": { "type": "string", "description": "5자리 우편번호" },
              "address1": { "type": "string", "minLength": 5, "maxLength": 100 },
              "address2": { "type": "string", "maxLength": 100 }
            }
          },
          "deposit_name": { "type": "string", "maxLength": 20, "description": "입금자명 (생략하면 구매자 이름)" },
          "memo": { "type": "string", "maxLength": 300, "description": "배송 요청사항" },
          "send_date": { "type": "string", "format": "date", "description": "(선택) 발송 예약일. 허용 범위는 catalog.php 의 send_date 참고" },
          "bank_index": { "type": "integer", "minimum": 0, "description": "(선택) catalog.php 의 payment.accounts 순번, 기본 0" },
          "items": {
            "type": "array",
            "minItems": 1,
            "maxItems": 10,
            "items": {
              "type": "object",
              "required": ["item_id", "qty"],
              "properties": {
                "item_id": { "type": "string", "description": "catalog.php 의 item_id" },
                "qty": { "type": "integer", "minimum": 1, "maximum": 30 }
              }
            }
          }
        }
      }
    }
  }
}
