{
    "openapi": "3.0.3",
    "info": {
        "title": "JOYTEL 合作夥伴 API",
        "version": "1.0.0",
        "description": "下單、出貨、安裝頁、eSIM 狀態與用量。同一個網址，test_ 金鑰是測試、live_ 金鑰是正式。"
    },
    "servers": [
        {
            "url": "https://api.goodcareinternet.com/v1"
        }
    ],
    "security": [
        {
            "bearerAuth": []
        }
    ],
    "tags": [
        {
            "name": "商品"
        },
        {
            "name": "訂單"
        },
        {
            "name": "eSIM"
        },
        {
            "name": "帳戶"
        },
        {
            "name": "測試環境"
        }
    ],
    "paths": {
        "/products": {
            "get": {
                "operationId": "products-list",
                "tags": [
                    "商品"
                ],
                "summary": "商品目錄",
                "description": "回傳貴公司價格表上可下單的 eSIM 商品。目的地、天數、流量型態都是結構化欄位，可以直接拿來建商品頁。價格是這把金鑰綁定帳號價格表上的價格（綁主帳號時是貴公司的經銷價）。",
                "parameters": [
                    {
                        "name": "country",
                        "in": "query",
                        "required": false,
                        "description": "國家代碼（ISO 3166-1 alpha-2），例如 JP",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "validity_days",
                        "in": "query",
                        "required": false,
                        "description": "方案天數",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "data_type",
                        "in": "query",
                        "required": false,
                        "description": "daily（日量）、total（總量）、unlimited（不限量）",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "q",
                        "in": "query",
                        "required": false,
                        "description": "關鍵字（商品名稱、代碼、國家名）",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "page",
                        "in": "query",
                        "required": false,
                        "description": "分頁，per_page 預設 20、上限 100",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "per_page",
                        "in": "query",
                        "required": false,
                        "description": "分頁，per_page 預設 20、上限 100",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "content": {
                            "application/json": {
                                "example": {
                                    "data": [
                                        {
                                            "product_code": "JP-K-5D1",
                                            "name": "日本 KDDI 5天 每日1GB",
                                            "type": "esim",
                                            "price": {
                                                "amount": 299,
                                                "currency": "TWD"
                                            },
                                            "validity_days": 5,
                                            "data": {
                                                "type": "daily",
                                                "quota_mb": 1024
                                            },
                                            "countries": [
                                                {
                                                    "code": "JP",
                                                    "name": "日本"
                                                }
                                            ],
                                            "refund": {
                                                "allowed": true,
                                                "fee": 30
                                            },
                                            "capabilities": {
                                                "usage_query": true,
                                                "install_events": true
                                            },
                                            "available": true,
                                            "updated_at": "2026-10-01T10:00:00+08:00"
                                        }
                                    ],
                                    "pagination": {
                                        "page": 1,
                                        "per_page": 20,
                                        "total": 1,
                                        "total_pages": 1
                                    }
                                }
                            }
                        }
                    },
                    "4XX": {
                        "description": "錯誤（）",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "error": {
                                            "type": "object",
                                            "properties": {
                                                "code": {
                                                    "type": "string"
                                                },
                                                "message": {
                                                    "type": "string"
                                                },
                                                "request_id": {
                                                    "type": "string"
                                                },
                                                "details": {
                                                    "type": "object"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/products/{product_code}": {
            "get": {
                "operationId": "products-show",
                "tags": [
                    "商品"
                ],
                "summary": "單一商品",
                "description": "下單前確認商品還能賣、價格沒變。",
                "parameters": [
                    {
                        "name": "product_code",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "content": {
                            "application/json": {
                                "example": {
                                    "data": {
                                        "product_code": "JP-K-5D1",
                                        "name": "日本 KDDI 5天 每日1GB",
                                        "type": "esim",
                                        "price": {
                                            "amount": 299,
                                            "currency": "TWD"
                                        },
                                        "validity_days": 5,
                                        "data": {
                                            "type": "daily",
                                            "quota_mb": 1024
                                        },
                                        "countries": [
                                            {
                                                "code": "JP",
                                                "name": "日本"
                                            }
                                        ],
                                        "refund": {
                                            "allowed": true,
                                            "fee": 30
                                        },
                                        "capabilities": {
                                            "usage_query": true,
                                            "install_events": true
                                        },
                                        "available": true,
                                        "updated_at": "2026-10-01T10:00:00+08:00"
                                    }
                                }
                            }
                        }
                    },
                    "4XX": {
                        "description": "錯誤（PRODUCT_NOT_FOUND）",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "error": {
                                            "type": "object",
                                            "properties": {
                                                "code": {
                                                    "type": "string"
                                                },
                                                "message": {
                                                    "type": "string"
                                                },
                                                "request_id": {
                                                    "type": "string"
                                                },
                                                "details": {
                                                    "type": "object"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/orders": {
            "post": {
                "operationId": "orders-create",
                "tags": [
                    "訂單"
                ],
                "summary": "下單",
                "description": "受理後立即回 HTTP 202 與訂單編號，狀態是 processing；出卡由系統背景處理（通常幾秒到一分鐘），結果用「訂單狀態」查。同一個 partner_order_id 重送不會重複下單，會回原本的訂單並標 idempotent_replay: true。",
                "parameters": [],
                "responses": {
                    "202": {
                        "description": "成功",
                        "content": {
                            "application/json": {
                                "example": {
                                    "data": {
                                        "order_no": "p00101261010001",
                                        "partner_order_id": "SHOP-20261010-001",
                                        "status": "processing",
                                        "test": false,
                                        "product_code": "JP-K-5D1",
                                        "product_name": "日本 KDDI 5天 每日1GB",
                                        "quantity": 1,
                                        "unit_price": 299,
                                        "amount": 299,
                                        "currency": "TWD",
                                        "delivery": "qr",
                                        "email": "traveler@example.com",
                                        "remark": "",
                                        "esims": [
                                            {
                                                "card_no": "p00101261010001-1",
                                                "status": "processing",
                                                "iccid": null,
                                                "install_state": "na",
                                                "install_state_at": null,
                                                "usage_supported": true
                                            }
                                        ],
                                        "created_at": "2026-10-10T09:30:02+08:00",
                                        "completed_at": null
                                    },
                                    "idempotent_replay": false
                                }
                            }
                        }
                    },
                    "4XX": {
                        "description": "錯誤（INVALID_REQUEST、PRODUCT_NOT_FOUND、DUPLICATE_PARTNER_ORDER、ORDER_IN_PROGRESS、INSUFFICIENT_BALANCE、CREDIT_LIMIT_EXCEEDED、COUPON_NOT_ENABLED、PRODUCT_UNAVAILABLE）",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "error": {
                                            "type": "object",
                                            "properties": {
                                                "code": {
                                                    "type": "string"
                                                },
                                                "message": {
                                                    "type": "string"
                                                },
                                                "request_id": {
                                                    "type": "string"
                                                },
                                                "details": {
                                                    "type": "object"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "partner_order_id": {
                                        "type": "string",
                                        "description": "貴端訂單編號，1–64 字元（英數字與 _ . -），不可重複；作為冪等鍵"
                                    },
                                    "product_code": {
                                        "type": "string",
                                        "description": "商品代碼"
                                    },
                                    "quantity": {
                                        "type": "integer",
                                        "description": "張數，預設 1，上限 100；每張 eSIM 各自一個卡號"
                                    },
                                    "email": {
                                        "type": "string",
                                        "description": "旅客 Email。有填就會寄出貨信（可用 send_email: false 關掉）；兌換碼出貨必填"
                                    },
                                    "send_email": {
                                        "type": "boolean",
                                        "description": "要不要由 JOYTEL 寄出貨信，預設 true（有 email 時）"
                                    },
                                    "template_id": {
                                        "type": "integer",
                                        "description": "出貨信範本編號（在合作夥伴系統「信件範本」設定），不填用預設範本"
                                    },
                                    "delivery": {
                                        "type": "string",
                                        "description": "qr（預設，直接出 QR）或 coupon（兌換碼，旅客自己兌換後安裝；需開通）"
                                    },
                                    "remark": {
                                        "type": "string",
                                        "description": "備註，最多 200 字"
                                    }
                                },
                                "required": [
                                    "partner_order_id",
                                    "product_code"
                                ]
                            },
                            "example": {
                                "partner_order_id": "SHOP-20261010-001",
                                "product_code": "JP-K-5D1",
                                "quantity": 1,
                                "email": "traveler@example.com"
                            }
                        }
                    }
                }
            },
            "get": {
                "operationId": "orders-list",
                "tags": [
                    "訂單"
                ],
                "summary": "訂單列表",
                "description": "這把金鑰綁定帳號（主帳號或子帳號）的訂單，新的在前。",
                "parameters": [
                    {
                        "name": "partner_order_id",
                        "in": "query",
                        "required": false,
                        "description": "用貴端訂單編號找",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "since",
                        "in": "query",
                        "required": false,
                        "description": "只回傳這個時間之後建立的訂單（ISO 8601；沒帶時區時視為台灣時間 UTC+8）",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "page",
                        "in": "query",
                        "required": false,
                        "description": "分頁",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "per_page",
                        "in": "query",
                        "required": false,
                        "description": "分頁",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "content": {
                            "application/json": {
                                "example": {
                                    "data": [
                                        {
                                            "order_no": "p00101261010001",
                                            "partner_order_id": "SHOP-20261010-001",
                                            "status": "completed",
                                            "test": false,
                                            "product_code": "JP-K-5D1",
                                            "product_name": "日本 KDDI 5天 每日1GB",
                                            "quantity": 1,
                                            "unit_price": 299,
                                            "amount": 299,
                                            "currency": "TWD",
                                            "delivery": "qr",
                                            "email": "traveler@example.com",
                                            "remark": "",
                                            "esims": [
                                                {
                                                    "card_no": "p00101261010001-1",
                                                    "status": "issued",
                                                    "iccid": "8988228000000012345",
                                                    "install_state": "not_installed",
                                                    "install_state_at": null,
                                                    "usage_supported": true
                                                }
                                            ],
                                            "created_at": "2026-10-10T09:30:02+08:00",
                                            "completed_at": "2026-10-10T09:30:11+08:00"
                                        }
                                    ],
                                    "pagination": {
                                        "page": 1,
                                        "per_page": 20,
                                        "total": 1,
                                        "total_pages": 1
                                    }
                                }
                            }
                        }
                    },
                    "4XX": {
                        "description": "錯誤（）",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "error": {
                                            "type": "object",
                                            "properties": {
                                                "code": {
                                                    "type": "string"
                                                },
                                                "message": {
                                                    "type": "string"
                                                },
                                                "request_id": {
                                                    "type": "string"
                                                },
                                                "details": {
                                                    "type": "object"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/orders/{order_no}": {
            "get": {
                "operationId": "orders-show",
                "tags": [
                    "訂單"
                ],
                "summary": "訂單狀態",
                "description": "回傳訂單與每張卡的狀態。下單後建議前 30 秒每 3 秒查一次，之後每 30 秒一次。",
                "parameters": [
                    {
                        "name": "order_no",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "content": {
                            "application/json": {
                                "example": {
                                    "data": {
                                        "order_no": "p00101261010001",
                                        "partner_order_id": "SHOP-20261010-001",
                                        "status": "completed",
                                        "test": false,
                                        "product_code": "JP-K-5D1",
                                        "product_name": "日本 KDDI 5天 每日1GB",
                                        "quantity": 1,
                                        "unit_price": 299,
                                        "amount": 299,
                                        "currency": "TWD",
                                        "delivery": "qr",
                                        "email": "traveler@example.com",
                                        "remark": "",
                                        "esims": [
                                            {
                                                "card_no": "p00101261010001-1",
                                                "status": "issued",
                                                "iccid": "8988228000000012345",
                                                "install_state": "not_installed",
                                                "install_state_at": null,
                                                "usage_supported": true
                                            }
                                        ],
                                        "created_at": "2026-10-10T09:30:02+08:00",
                                        "completed_at": "2026-10-10T09:30:11+08:00"
                                    }
                                }
                            }
                        }
                    },
                    "4XX": {
                        "description": "錯誤（ORDER_NOT_FOUND）",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "error": {
                                            "type": "object",
                                            "properties": {
                                                "code": {
                                                    "type": "string"
                                                },
                                                "message": {
                                                    "type": "string"
                                                },
                                                "request_id": {
                                                    "type": "string"
                                                },
                                                "details": {
                                                    "type": "object"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/orders/{order_no}/profile": {
            "get": {
                "operationId": "orders-profile",
                "tags": [
                    "訂單"
                ],
                "summary": "取件：安裝資訊",
                "description": "每張卡的 LPA（QR 內容）、SM-DP+ 與啟用碼、iPhone／Android 一鍵安裝連結，以及一條可直接傳給旅客的安裝頁連結（QR、手動輸入、一鍵安裝都在那一頁）。兌換碼出貨的卡在旅客兌換前只有 coupon_code 與 redeem_url。\n\n安裝資訊等同旅客的憑證，請勿寫進一般日誌或公開在群組。",
                "parameters": [
                    {
                        "name": "order_no",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "content": {
                            "application/json": {
                                "example": {
                                    "data": {
                                        "order_no": "p00101261010001",
                                        "esims": [
                                            {
                                                "card_no": "p00101261010001-1",
                                                "status": "issued",
                                                "lpa": "LPA:1$rsp.example.com$ABCD-1234-EFGH",
                                                "smdp_address": "rsp.example.com",
                                                "activation_code": "ABCD-1234-EFGH",
                                                "ios_install_url": "https://esimsetup.apple.com/esim_qrcode_provisioning?carddata=LPA%3A1%24rsp.example.com%24ABCD-1234-EFGH",
                                                "android_install_url": "https://esimsetup.android.com/esim_qrcode_provisioning?carddata=LPA%3A1%24rsp.example.com%24ABCD-1234-EFGH",
                                                "install_page_url": "https://esim.tiptoewithdata.com/install/3f9c2a7d1e5b4c8a9d0e1f2a3b4c5d6e7f8a9b0c",
                                                "coupon_code": null,
                                                "redeem_url": null
                                            }
                                        ]
                                    }
                                }
                            }
                        }
                    },
                    "4XX": {
                        "description": "錯誤（ORDER_NOT_FOUND、ORDER_NOT_READY、ORDER_CANCELLED）",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "error": {
                                            "type": "object",
                                            "properties": {
                                                "code": {
                                                    "type": "string"
                                                },
                                                "message": {
                                                    "type": "string"
                                                },
                                                "request_id": {
                                                    "type": "string"
                                                },
                                                "details": {
                                                    "type": "object"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/orders/{order_no}/cancel": {
            "post": {
                "operationId": "orders-cancel",
                "tags": [
                    "訂單"
                ],
                "summary": "申請退貨",
                "description": "對還沒安裝的卡申請退貨。正式環境由 JOYTEL 審核：申請後卡的狀態是 cancel_pending，核准後變 cancelled，退款依商品的退貨手續費計算。已安裝的卡不能退；出卡失敗的卡本來就不計費，不用退。重送同一個請求會回目前狀態，不會出錯。",
                "parameters": [
                    {
                        "name": "order_no",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "content": {
                            "application/json": {
                                "example": {
                                    "data": {
                                        "order_no": "p00101261010001",
                                        "partner_order_id": "SHOP-20261010-001",
                                        "status": "completed",
                                        "test": false,
                                        "product_code": "JP-K-5D1",
                                        "product_name": "日本 KDDI 5天 每日1GB",
                                        "quantity": 1,
                                        "unit_price": 299,
                                        "amount": 299,
                                        "currency": "TWD",
                                        "delivery": "qr",
                                        "email": "traveler@example.com",
                                        "remark": "",
                                        "esims": [
                                            {
                                                "card_no": "p00101261010001-1",
                                                "status": "cancel_pending",
                                                "iccid": "8988228000000012345",
                                                "install_state": "not_installed",
                                                "install_state_at": null,
                                                "usage_supported": true
                                            }
                                        ],
                                        "created_at": "2026-10-10T09:30:02+08:00",
                                        "completed_at": "2026-10-10T09:30:11+08:00"
                                    }
                                }
                            }
                        }
                    },
                    "4XX": {
                        "description": "錯誤（ORDER_NOT_FOUND、ORDER_NOT_READY、CANCEL_NOT_ALLOWED）",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "error": {
                                            "type": "object",
                                            "properties": {
                                                "code": {
                                                    "type": "string"
                                                },
                                                "message": {
                                                    "type": "string"
                                                },
                                                "request_id": {
                                                    "type": "string"
                                                },
                                                "details": {
                                                    "type": "object"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "reason": {
                                        "type": "string",
                                        "description": "原因（選填，最多 200 字）"
                                    }
                                }
                            },
                            "example": {
                                "reason": "customer_request"
                            }
                        }
                    }
                }
            }
        },
        "/esims/{card_no}": {
            "get": {
                "operationId": "esims-show",
                "tags": [
                    "eSIM"
                ],
                "summary": "eSIM 狀態與安裝紀錄",
                "description": "用卡號查這張 eSIM 裝到手機了沒：install_state 是裝置端最新狀態（not_installed、downloaded、installed、enabled、disabled、deleted、finished、failed、not_eligible；商品不支援回報時為 na），events 是上游推播的安裝紀錄，新到舊最多 50 筆。",
                "parameters": [
                    {
                        "name": "card_no",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "content": {
                            "application/json": {
                                "example": {
                                    "data": {
                                        "card_no": "p00101261010001-1",
                                        "order_no": "p00101261010001",
                                        "product_code": "JP-K-5D1",
                                        "status": "issued",
                                        "install_state": "enabled",
                                        "install_state_at": "2026-10-12T08:02:11+08:00",
                                        "device": "iPhone 15 Pro",
                                        "location": "日本",
                                        "iccid": "8988228000000012345",
                                        "eid": "89049032004008882600012345678901",
                                        "usage_supported": true,
                                        "events": [
                                            {
                                                "time": "2026-10-12T08:02:11+08:00",
                                                "event": "已啟用",
                                                "ok": true,
                                                "location": "日本",
                                                "device": "iPhone 15 Pro",
                                                "eid": "89049032004008882600012345678901"
                                            },
                                            {
                                                "time": "2026-10-11T21:14:36+08:00",
                                                "event": "已安裝",
                                                "ok": true,
                                                "location": "台灣",
                                                "device": "iPhone 15 Pro",
                                                "eid": "89049032004008882600012345678901"
                                            }
                                        ]
                                    }
                                }
                            }
                        }
                    },
                    "4XX": {
                        "description": "錯誤（ESIM_NOT_FOUND）",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "error": {
                                            "type": "object",
                                            "properties": {
                                                "code": {
                                                    "type": "string"
                                                },
                                                "message": {
                                                    "type": "string"
                                                },
                                                "request_id": {
                                                    "type": "string"
                                                },
                                                "details": {
                                                    "type": "object"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/esims/{card_no}/usage": {
            "get": {
                "operationId": "esims-usage",
                "tags": [
                    "eSIM"
                ],
                "summary": "用量",
                "description": "方案期間累計用量與每日明細（MB）。資料來自電信端，同一張卡 3 分鐘內重複查會拿到同一份；尚未啟用沒有用量。",
                "parameters": [
                    {
                        "name": "card_no",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "content": {
                            "application/json": {
                                "example": {
                                    "data": {
                                        "card_no": "p00101261010001-1",
                                        "activated_at": "2026-10-12T08:02:11+08:00",
                                        "expires_at": "2026-10-17T08:02:11+08:00",
                                        "used_mb": 2310.5,
                                        "daily": [
                                            {
                                                "date": "2026-10-12",
                                                "country": "JP",
                                                "country_name": "日本",
                                                "used_mb": 980.2
                                            },
                                            {
                                                "date": "2026-10-13",
                                                "country": "JP",
                                                "country_name": "日本",
                                                "used_mb": 1330.3
                                            }
                                        ],
                                        "queried_at": "2026-10-13T10:05:00+08:00"
                                    }
                                }
                            }
                        }
                    },
                    "4XX": {
                        "description": "錯誤（ESIM_NOT_FOUND、ESIM_NOT_INSTALLED、USAGE_NOT_SUPPORTED、UPSTREAM_UNAVAILABLE）",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "error": {
                                            "type": "object",
                                            "properties": {
                                                "code": {
                                                    "type": "string"
                                                },
                                                "message": {
                                                    "type": "string"
                                                },
                                                "request_id": {
                                                    "type": "string"
                                                },
                                                "details": {
                                                    "type": "object"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/account": {
            "get": {
                "operationId": "account",
                "tags": [
                    "帳戶"
                ],
                "summary": "帳戶",
                "description": "結帳方式與帳戶餘額（儲值客戶）或可用額度（月結客戶）、這把金鑰綁定的帳號、金鑰設定。bound_to 是 main_account（綁主帳號）或 sub_account（綁子帳號）；綁主帳號時 sub_account 為 null，額度只看 company。適合在下單前檢查餘額，或做低餘額提醒。",
                "parameters": [],
                "responses": {
                    "200": {
                        "description": "成功",
                        "content": {
                            "application/json": {
                                "example": {
                                    "data": {
                                        "mode": "live",
                                        "company": {
                                            "main_account_code": "p001",
                                            "company_name": "示範旅行社",
                                            "billing_mode": "prepaid",
                                            "balance": {
                                                "amount": 12840,
                                                "currency": "TWD"
                                            }
                                        },
                                        "bound_to": "sub_account",
                                        "sub_account": {
                                            "code": "p00101",
                                            "name": "官網",
                                            "credit": {
                                                "limit": 50000,
                                                "used": 8970,
                                                "available": 41030
                                            },
                                            "coupon_delivery": false
                                        },
                                        "coupon_delivery": false,
                                        "key": {
                                            "name": "官網",
                                            "allow_orders": true,
                                            "rate_limit": {
                                                "per_minute": 300,
                                                "orders_per_minute": 60
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "4XX": {
                        "description": "錯誤（）",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "error": {
                                            "type": "object",
                                            "properties": {
                                                "code": {
                                                    "type": "string"
                                                },
                                                "message": {
                                                    "type": "string"
                                                },
                                                "request_id": {
                                                    "type": "string"
                                                },
                                                "details": {
                                                    "type": "object"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/sandbox/esims/{card_no}/simulate": {
            "post": {
                "operationId": "sandbox-simulate",
                "tags": [
                    "測試環境"
                ],
                "summary": "模擬事件（限測試金鑰）",
                "description": "把測試卡推進到指定狀態，不用等真的旅客出國。event 可用：installed（已安裝）、activated（已啟用，開始算效期與用量）、disabled、deleted、expired、install_error、usage_low、expiring；兌換碼出貨的卡先 redeemed。",
                "parameters": [
                    {
                        "name": "card_no",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "content": {
                            "application/json": {
                                "example": {
                                    "data": {
                                        "card_no": "TP00101261010001-1",
                                        "order_no": "TP00101261010001",
                                        "product_code": "TEST-JP-D1G-05",
                                        "status": "issued",
                                        "install_state": "enabled",
                                        "install_state_at": "2026-10-12T08:02:11+08:00",
                                        "device": "iPhone 15 Pro (測試)",
                                        "location": "日本",
                                        "iccid": "8988000000000000201",
                                        "eid": "89049032004008882600012345678901",
                                        "usage_supported": true,
                                        "events": [
                                            {
                                                "time": "2026-10-12T08:02:11+08:00",
                                                "event": "已啟用",
                                                "ok": true,
                                                "location": "日本",
                                                "device": "iPhone 15 Pro",
                                                "eid": "89049032004008882600012345678901"
                                            },
                                            {
                                                "time": "2026-10-11T21:14:36+08:00",
                                                "event": "已安裝",
                                                "ok": true,
                                                "location": "台灣",
                                                "device": "iPhone 15 Pro",
                                                "eid": "89049032004008882600012345678901"
                                            }
                                        ]
                                    }
                                }
                            }
                        }
                    },
                    "4XX": {
                        "description": "錯誤（SANDBOX_ONLY、ESIM_NOT_FOUND、ORDER_NOT_READY、INVALID_STATE）",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "error": {
                                            "type": "object",
                                            "properties": {
                                                "code": {
                                                    "type": "string"
                                                },
                                                "message": {
                                                    "type": "string"
                                                },
                                                "request_id": {
                                                    "type": "string"
                                                },
                                                "details": {
                                                    "type": "object"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "event": {
                                        "type": "string",
                                        "description": "事件名稱"
                                    }
                                },
                                "required": [
                                    "event"
                                ]
                            },
                            "example": {
                                "event": "activated"
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "description": "金鑰在合作夥伴系統「開發者」頁產生"
            }
        },
        "schemas": {
            "Error": {
                "type": "object",
                "properties": {
                    "error": {
                        "type": "object",
                        "properties": {
                            "code": {
                                "type": "string"
                            },
                            "message": {
                                "type": "string"
                            },
                            "request_id": {
                                "type": "string"
                            },
                            "details": {
                                "type": "object"
                            }
                        }
                    }
                }
            }
        }
    }
}