{
  "openapi": "3.0.3",
  "info": {
    "title": "SHENTUPAY 商户交易网关 API",
    "version": "1.0.0",
    "description": "统一交易网关：通过一套标准接口接入直连支付、托管收银台、查询与退款。所有商户服务端接口使用 apiKeyId + RSA-SHA256 请求签名，平台响应同样签名，双向验签。新增上游通道不会改变本文件的接口结构，只增字段不删字段。",
    "contact": {
      "name": "SHENTUPAY 技术支持",
      "url": "https://www.shentu-pay.com/"
    }
  },
  "servers": [
    {
      "url": "https://api.shentu-pay.com",
      "description": "生产环境"
    },
    {
      "url": "https://api-test.shentu-pay.com",
      "description": "测试环境"
    }
  ],
  "tags": [
    {
      "name": "Payment",
      "description": "直连支付与交易查询"
    },
    {
      "name": "Refund",
      "description": "退款提交与退款查询"
    },
    {
      "name": "Checkout",
      "description": "托管收银台会话"
    },
    {
      "name": "Webhook",
      "description": "平台发起的异步结果通知（商户实现）"
    }
  ],
  "x-intro": {
    "steps": [
      {
        "title": "获取接入凭据",
        "desc": "平台分配 apiKeyId，商户自行生成 RSA 2048 密钥对并上传公钥。"
      },
      {
        "title": "生成请求签名",
        "desc": "按规范拼接待签串，用商户私钥 SHA256withRSA 签名，放入 X-Signature。"
      },
      {
        "title": "发起交易请求",
        "desc": "调用 payment/submit 直连支付，或 create-session 获取收银台链接。"
      },
      {
        "title": "处理交易结果",
        "desc": "同步返回 PENDING 时，依据 nextAction 引导跳转，最终结果以 webhook 为准。"
      }
    ],
    "signature": {
      "algorithm": "SHA256withRSA (RSA 2048, PKCS#1 v1.5)",
      "headers": [
        {
          "name": "X-Api-Key",
          "required": true,
          "desc": "平台分配的 apiKeyId"
        },
        {
          "name": "X-Timestamp",
          "required": true,
          "desc": "毫秒级 Unix 时间戳，与平台时间偏差不得超过 300 秒"
        },
        {
          "name": "X-Nonce",
          "required": true,
          "desc": "32 位随机字符串，同一 apiKeyId 下 300 秒内不可重复"
        },
        {
          "name": "X-Signature",
          "required": true,
          "desc": "对规范化待签串的签名结果，Base64 编码"
        },
        {
          "name": "Content-Type",
          "required": true,
          "desc": "application/json; charset=utf-8"
        }
      ],
      "canonical": "HTTP_METHOD\nREQUEST_PATH\nX-Timestamp\nX-Nonce\nBODY_SHA256_HEX",
      "notes": [
        "REQUEST_PATH 为不含域名与查询参数的路径，例如 /gateway/trade/payment/submit。",
        "BODY_SHA256_HEX 为原始请求体（字节级，不做 JSON 重排）的 SHA-256 十六进制小写；无请求体时取空串的 SHA-256，即 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855。",
        "GET 请求的查询参数按 key 字典序拼接为 k1=v1&k2=v2 后整体参与 BODY_SHA256_HEX 计算。",
        "平台响应同样返回 X-Timestamp 与 X-Signature，待签串为 HTTP_STATUS\\nX-Timestamp\\nBODY_SHA256_HEX，商户使用平台公钥验签。"
      ]
    },
    "envelope": "所有接口统一返回 { code, message, data, traceId }。code 为 \"0\" 表示成功，非 \"0\" 时 data 为 null，message 为可读描述，traceId 用于排查。",
    "idempotency": "payment/submit 以 merchantOrderNo 幂等，refund/submit 以 merchantRefundNo 幂等。重复提交不会重复扣款，直接返回该单当前结果。",
    "amountRule": "金额为字符串十进制，最多两位小数，最小单位 0.01，不接受负数与科学计数法；币种使用 ISO 4217 三位大写字母。"
  },
  "x-error-codes": [
    {
      "code": "0",
      "name": "SUCCESS",
      "desc": "成功"
    },
    {
      "code": "1001",
      "name": "MERCHANT_AUTH_FAILED",
      "desc": "apiKeyId 不存在、已停用或商户状态异常"
    },
    {
      "code": "1002",
      "name": "SIGN_INVALID",
      "desc": "签名验证不通过"
    },
    {
      "code": "1003",
      "name": "TIMESTAMP_EXPIRED",
      "desc": "X-Timestamp 超出 300 秒容差"
    },
    {
      "code": "1004",
      "name": "NONCE_REPLAY",
      "desc": "X-Nonce 重复使用"
    },
    {
      "code": "1005",
      "name": "IP_NOT_ALLOWED",
      "desc": "来源 IP 不在商户白名单内"
    },
    {
      "code": "2001",
      "name": "PARAM_MISSING",
      "desc": "必填参数缺失"
    },
    {
      "code": "2002",
      "name": "PARAM_INVALID",
      "desc": "参数格式或取值非法"
    },
    {
      "code": "2003",
      "name": "AMOUNT_INVALID",
      "desc": "金额格式非法或超出允许范围"
    },
    {
      "code": "2004",
      "name": "CURRENCY_NOT_SUPPORTED",
      "desc": "该币种当前无可用通道"
    },
    {
      "code": "2005",
      "name": "PAYMENT_METHOD_NOT_SUPPORTED",
      "desc": "该支付方式当前无可用通道"
    },
    {
      "code": "3001",
      "name": "ORDER_EXISTS",
      "desc": "商户订单号重复且原始请求不一致"
    },
    {
      "code": "3002",
      "name": "ORDER_NOT_FOUND",
      "desc": "交易不存在或不属于当前商户"
    },
    {
      "code": "3003",
      "name": "ORDER_STATUS_INVALID",
      "desc": "当前交易状态不允许此操作"
    },
    {
      "code": "3004",
      "name": "REFUND_AMOUNT_EXCEEDED",
      "desc": "退款金额超过可退余额"
    },
    {
      "code": "4001",
      "name": "RISK_REJECTED",
      "desc": "命中风控规则被拒绝"
    },
    {
      "code": "4002",
      "name": "LIMIT_EXCEEDED",
      "desc": "超出限额（单笔/单日/单月/频次）"
    },
    {
      "code": "5001",
      "name": "CHANNEL_UNAVAILABLE",
      "desc": "当前无可用上游通道"
    },
    {
      "code": "5002",
      "name": "CHANNEL_ERROR",
      "desc": "上游通道返回错误"
    },
    {
      "code": "5003",
      "name": "CHANNEL_TIMEOUT",
      "desc": "上游通道响应超时，结果待确认"
    },
    {
      "code": "9001",
      "name": "SYSTEM_ERROR",
      "desc": "系统内部错误"
    },
    {
      "code": "9002",
      "name": "RATE_LIMITED",
      "desc": "请求频率超出商户配额"
    }
  ],
  "x-test-cards": [
    {
      "number": "5137009801943438",
      "scenario": "直接成功",
      "expect": "同步返回 SUCCESS"
    },
    {
      "number": "5168645305790452",
      "scenario": "直接失败",
      "expect": "同步返回 FAILED，resultCode 为上游失败码"
    },
    {
      "number": "4874970686672022",
      "scenario": "触发 3DS",
      "expect": "返回 PENDING 且 nextAction.type=THREE_DS"
    }
  ],
  "x-webhook": {
    "retry": "首次通知失败后按 1min、5min、15min、1h、6h、12h 重试，共 6 次；全部失败后进入人工重推队列。",
    "ack": "商户需返回 HTTP 200 且响应体包含 SUCCESS（不区分大小写）才算送达。",
    "verify": "使用平台公钥对请求头 X-Signature 验签，待签串为 POST\\n{notifyPath}\\nX-Timestamp\\nX-Nonce\\nBODY_SHA256_HEX。",
    "dedupe": "同一 eventId 可能重复投递，商户需按 eventId 或 (eventType + tradeNo + status) 去重。"
  },
  "paths": {
    "/gateway/trade/payment/submit": {
      "post": {
        "tags": [
          "Payment"
        ],
        "summary": "直连支付",
        "description": "商户服务端发起银行卡直连支付。需要 3DS 时返回 PENDING 与 nextAction，前端跳转后由平台接收回跳并完成后续处理。浏览器最终回到 resultUrls 指定的地址，平台会在回跳地址上追加 tradeNo、merchantOrderNo、status 三个查询参数，仅用于展示，交易结果以 webhook 与查询接口为准。",
        "operationId": "paymentSubmit",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PaymentSubmitRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "统一响应",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentResponse"
                }
              }
            }
          }
        }
      }
    },
    "/gateway/trade/payment/query": {
      "post": {
        "tags": [
          "Payment"
        ],
        "summary": "支付结果查询",
        "description": "按平台交易号或商户订单号查询当前状态。收到 PENDING 时应轮询本接口，直到进入终态或超时。",
        "operationId": "paymentQuery",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PaymentQueryRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "统一响应",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentResponse"
                }
              }
            }
          }
        }
      }
    },
    "/gateway/trade/payment/close": {
      "post": {
        "tags": [
          "Payment"
        ],
        "summary": "关闭交易",
        "description": "关闭未支付的交易。已成功的交易不可关闭，请走退款。",
        "operationId": "paymentClose",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PaymentQueryRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "统一响应",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentResponse"
                }
              }
            }
          }
        }
      }
    },
    "/gateway/trade/refund/submit": {
      "post": {
        "tags": [
          "Refund"
        ],
        "summary": "退款提交",
        "description": "对原支付单发起全额或部分退款。支持多次部分退款，累计不得超过原交易金额。",
        "operationId": "refundSubmit",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RefundSubmitRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "统一响应",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RefundResponse"
                }
              }
            }
          }
        }
      }
    },
    "/gateway/trade/refund/query": {
      "post": {
        "tags": [
          "Refund"
        ],
        "summary": "退款查询",
        "description": "按平台退款单号或商户退款单号查询退款结果。",
        "operationId": "refundQuery",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RefundQueryRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "统一响应",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RefundResponse"
                }
              }
            }
          }
        }
      }
    },
    "/gateway/trade/checkout/create-session": {
      "post": {
        "tags": [
          "Checkout"
        ],
        "summary": "创建收银台会话",
        "description": "创建托管收银台会话，返回可直接交付浏览器的 url。适用于不希望接触卡数据的商户，可显著缩小 PCI 范围。",
        "operationId": "checkoutCreateSession",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CheckoutSessionCreateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "统一响应",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckoutSessionResponse"
                }
              }
            }
          }
        }
      }
    },
    "/gateway/trade/checkout/page": {
      "get": {
        "tags": [
          "Checkout"
        ],
        "summary": "打开收银台页面",
        "description": "浏览器直接打开创建会话返回的 url，通过 token 校验会话有效性，不走 apiKeyId 签名。",
        "operationId": "checkoutPage",
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "会话 token"
          }
        ],
        "responses": {
          "200": {
            "description": "HTML 收银台页面",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/webhook/trade-notification": {
      "post": {
        "tags": [
          "Webhook"
        ],
        "summary": "交易结果通知（平台 → 商户）",
        "description": "由平台发起，POST 到商户创建交易时提供的 notifyUrl。请在 3 秒内返回 HTTP 200 且响应体包含 SUCCESS，否则平台将按退避策略重试。",
        "operationId": "tradeNotification",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TradeNotification"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "商户应答成功，响应体返回 SUCCESS"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "PaymentMethod": {
        "type": "object",
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "CARD",
              "WALLET"
            ],
            "description": "支付类型，默认 CARD"
          },
          "walletCode": {
            "type": "string",
            "description": "钱包支付方式，type=WALLET 时必填",
            "enum": [
              "CASHAPP_WAP",
              "CASHAPP_WEB",
              "KLARNA",
              "APPLE_PAY",
              "GOOGLE_PAY",
              "BLIK",
              "IDEAL",
              "BANCONTACT",
              "SWISH",
              "TWINT",
              "WERO"
            ]
          }
        }
      },
      "Card": {
        "type": "object",
        "required": [
          "number",
          "expiryMonth",
          "expiryYear",
          "securityCode",
          "holderName"
        ],
        "properties": {
          "number": {
            "type": "string",
            "description": "卡号，13-19 位数字",
            "example": "4242424242424242"
          },
          "expiryMonth": {
            "type": "string",
            "description": "有效期月份，两位，如 03",
            "example": "03"
          },
          "expiryYear": {
            "type": "string",
            "description": "有效期年份，两位或四位，如 30 或 2030",
            "example": "30"
          },
          "securityCode": {
            "type": "string",
            "description": "安全码 CVV/CVC",
            "example": "123"
          },
          "holderName": {
            "type": "string",
            "description": "持卡人姓名，与卡面一致"
          }
        }
      },
      "Customer": {
        "type": "object",
        "properties": {
          "firstName": {
            "type": "string",
            "description": "名"
          },
          "lastName": {
            "type": "string",
            "description": "姓"
          },
          "email": {
            "type": "string",
            "description": "持卡人邮箱，上限 100"
          },
          "phone": {
            "type": "string",
            "description": "联系电话，上限 50"
          },
          "ip": {
            "type": "string",
            "description": "持卡人公网 IP，上限 45"
          },
          "userAgent": {
            "type": "string",
            "description": "浏览器 User-Agent 原值，上限 1024"
          },
          "acceptHeader": {
            "type": "string",
            "description": "浏览器 Accept 头原值，注意不是 UA"
          },
          "locale": {
            "type": "string",
            "description": "语言，格式 en_US / zh_CN / fr_FR"
          },
          "timezoneOffsetMinutes": {
            "type": "integer",
            "description": "相对 UTC 的时区偏移分钟数，北京 480，洛杉矶夏令时 -420"
          }
        }
      },
      "Device": {
        "type": "object",
        "description": "3DS/SCA 采集字段，缺失会显著提高 3DS 失败率，建议由前端采集后一并上送",
        "properties": {
          "colorDepth": {
            "type": "integer",
            "description": "屏幕颜色深度，如 24"
          },
          "screenWidth": {
            "type": "integer",
            "description": "屏幕宽度像素，如 1920"
          },
          "screenHeight": {
            "type": "integer",
            "description": "屏幕高度像素，如 1080"
          },
          "javaEnabled": {
            "type": "boolean",
            "description": "浏览器是否启用 Java"
          },
          "javaScriptEnabled": {
            "type": "boolean",
            "description": "浏览器是否启用 JS"
          },
          "timezoneOffsetMinutes": {
            "type": "integer",
            "description": "时区偏移分钟数"
          }
        }
      },
      "Address": {
        "type": "object",
        "properties": {
          "firstName": {
            "type": "string"
          },
          "lastName": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          },
          "address1": {
            "type": "string",
            "description": "详细地址"
          },
          "address2": {
            "type": "string",
            "description": "地址补充"
          },
          "city": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "description": "州/省"
          },
          "postalCode": {
            "type": "string",
            "description": "邮编"
          },
          "country": {
            "type": "string",
            "description": "ISO 3166-1 alpha-2，两位大写"
          }
        }
      },
      "Product": {
        "type": "object",
        "required": [
          "name",
          "price",
          "qty"
        ],
        "properties": {
          "sku": {
            "type": "string",
            "description": "商品唯一标识，同一订单内不可重复"
          },
          "name": {
            "type": "string",
            "description": "商品名称"
          },
          "price": {
            "type": "string",
            "description": "单价，字符串十进制",
            "example": "34.99"
          },
          "qty": {
            "type": "integer",
            "description": "数量，必须大于 0"
          },
          "link": {
            "type": "string",
            "description": "商品链接，上限 500"
          },
          "image": {
            "type": "string",
            "description": "商品图片链接，上限 255"
          },
          "attributes": {
            "type": "array",
            "description": "规格，如颜色、尺码",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "value": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "ResultUrls": {
        "type": "object",
        "required": [
          "notifyUrl"
        ],
        "properties": {
          "successUrl": {
            "type": "string",
            "description": "支付完成后浏览器回跳地址（非结果依据）"
          },
          "failureUrl": {
            "type": "string",
            "description": "支付失败后浏览器回跳地址"
          },
          "notifyUrl": {
            "type": "string",
            "description": "服务端异步通知地址，最终结果以此为准"
          }
        }
      },
      "NextAction": {
        "type": "object",
        "description": "下一步动作。NONE 表示无需跳转；REDIRECT 表示需要跳转到钱包或收银台页面；THREE_DS 表示需要跳转到发卡行验证页面。",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "NONE",
              "REDIRECT",
              "THREE_DS"
            ]
          },
          "url": {
            "type": "string",
            "description": "跳转地址，type 非 NONE 时返回"
          },
          "httpMethod": {
            "type": "string",
            "enum": [
              "GET",
              "POST"
            ],
            "description": "跳转方式，默认 GET"
          },
          "expiresAt": {
            "type": "string",
            "description": "跳转地址有效期，ISO 8601"
          }
        }
      },
      "PaymentSubmitRequest": {
        "type": "object",
        "required": [
          "merchantOrderNo",
          "amount",
          "currency",
          "paymentMethod",
          "resultUrls"
        ],
        "example": {
          "merchantOrderNo": "SO202611300001",
          "amount": "34.99",
          "currency": "USD",
          "description": "Order #10086",
          "paymentMethod": {
            "type": "CARD"
          },
          "card": {
            "number": "4242424242424242",
            "expiryMonth": "03",
            "expiryYear": "30",
            "securityCode": "123",
            "holderName": "JOHN DOE"
          },
          "customer": {
            "firstName": "John",
            "lastName": "Doe",
            "email": "john@example.com",
            "phone": "+14155550123",
            "ip": "35.213.204.45",
            "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
            "acceptHeader": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
            "locale": "en_US",
            "timezoneOffsetMinutes": -480
          },
          "device": {
            "colorDepth": 24,
            "screenWidth": 1920,
            "screenHeight": 1080,
            "javaEnabled": false,
            "javaScriptEnabled": true,
            "timezoneOffsetMinutes": -480
          },
          "billingAddress": {
            "firstName": "John",
            "lastName": "Doe",
            "phone": "+14155550123",
            "address1": "1226 Sale Ave",
            "city": "Louisville",
            "state": "KY",
            "postalCode": "40215",
            "country": "US"
          },
          "products": [
            {
              "sku": "p_13322",
              "name": "TEST ONLY",
              "price": "34.99",
              "qty": 1,
              "link": "https://shop.example.com/product/13322",
              "image": "https://shop.example.com/uploads/13322.jpg",
              "attributes": [
                {
                  "name": "Color",
                  "value": "Blue"
                }
              ]
            }
          ],
          "resultUrls": {
            "successUrl": "https://shop.example.com/pay/return",
            "failureUrl": "https://shop.example.com/pay/fail",
            "notifyUrl": "https://shop.example.com/api/pay/notify"
          },
          "metadata": {
            "cartId": "C10086"
          }
        },
        "properties": {
          "merchantOrderNo": {
            "type": "string",
            "description": "商户订单号，1-64 位，商户内唯一",
            "example": "SO20261130001"
          },
          "amount": {
            "type": "string",
            "description": "交易金额，字符串十进制，最多两位小数",
            "example": "34.99"
          },
          "currency": {
            "type": "string",
            "description": "ISO 4217 币种",
            "example": "USD"
          },
          "description": {
            "type": "string",
            "description": "交易描述，用于收银台与对账展示"
          },
          "paymentMethod": {
            "$ref": "#/components/schemas/PaymentMethod"
          },
          "card": {
            "$ref": "#/components/schemas/Card"
          },
          "customer": {
            "$ref": "#/components/schemas/Customer"
          },
          "device": {
            "$ref": "#/components/schemas/Device"
          },
          "billingAddress": {
            "$ref": "#/components/schemas/Address"
          },
          "shippingAddress": {
            "$ref": "#/components/schemas/Address"
          },
          "products": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Product"
            }
          },
          "resultUrls": {
            "$ref": "#/components/schemas/ResultUrls"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "透传字段，原样返回与通知"
          }
        }
      },
      "PaymentQueryRequest": {
        "type": "object",
        "properties": {
          "tradeNo": {
            "type": "string",
            "description": "平台交易号，与 merchantOrderNo 二者至少传一个，同时传以 tradeNo 为准"
          },
          "merchantOrderNo": {
            "type": "string",
            "description": "商户订单号"
          }
        }
      },
      "PaymentData": {
        "type": "object",
        "properties": {
          "tradeNo": {
            "type": "string",
            "description": "平台交易号"
          },
          "merchantOrderNo": {
            "type": "string",
            "description": "商户订单号"
          },
          "status": {
            "$ref": "#/components/schemas/TradeStatus"
          },
          "amount": {
            "type": "string",
            "description": "交易金额"
          },
          "currency": {
            "type": "string",
            "description": "币种"
          },
          "refundedAmount": {
            "type": "string",
            "description": "已退款金额，无退款时为空"
          },
          "channel": {
            "type": "string",
            "description": "实际处理通道标识，用于排查，商户无需依赖"
          },
          "nextAction": {
            "$ref": "#/components/schemas/NextAction"
          },
          "resultCode": {
            "type": "string",
            "description": "失败或待确认时的结果码，成功为空"
          },
          "resultMessage": {
            "type": "string",
            "description": "结果描述"
          },
          "createdAt": {
            "type": "string",
            "description": "创建时间，ISO 8601"
          },
          "paidAt": {
            "type": "string",
            "description": "支付成功时间，ISO 8601，未成功为空"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          }
        }
      },
      "TradeStatus": {
        "type": "string",
        "description": "交易状态。PENDING 表示处理中或等待用户完成跳转验证；SUCCESS/FAILED/CLOSED 为终态；REFUNDED 与 PARTIAL_REFUNDED 表示已发生退款。",
        "enum": [
          "PENDING",
          "SUCCESS",
          "FAILED",
          "CLOSED",
          "REFUNDED",
          "PARTIAL_REFUNDED"
        ]
      },
      "RefundStatus": {
        "type": "string",
        "enum": [
          "PENDING",
          "SUCCESS",
          "FAILED"
        ]
      },
      "RefundSubmitRequest": {
        "type": "object",
        "required": [
          "merchantRefundNo",
          "amount",
          "reason"
        ],
        "example": {
          "merchantRefundNo": "SR202611300001",
          "tradeNo": "T20261130000001",
          "amount": "34.99",
          "currency": "USD",
          "reason": "Customer refund",
          "notifyUrl": "https://shop.example.com/api/pay/notify"
        },
        "properties": {
          "merchantRefundNo": {
            "type": "string",
            "description": "商户退款单号，1-40 位，商户内唯一",
            "example": "SR20261130001"
          },
          "tradeNo": {
            "type": "string",
            "description": "原平台交易号，与 merchantOrderNo 二者至少传一个"
          },
          "merchantOrderNo": {
            "type": "string",
            "description": "原商户订单号"
          },
          "amount": {
            "type": "string",
            "description": "退款金额，不得超过可退余额"
          },
          "currency": {
            "type": "string",
            "description": "币种，默认与原交易一致"
          },
          "reason": {
            "type": "string",
            "description": "退款原因"
          },
          "notifyUrl": {
            "type": "string",
            "description": "退款结果通知地址，默认沿用原交易"
          }
        }
      },
      "RefundQueryRequest": {
        "type": "object",
        "properties": {
          "refundNo": {
            "type": "string",
            "description": "平台退款单号"
          },
          "merchantRefundNo": {
            "type": "string",
            "description": "商户退款单号"
          }
        }
      },
      "RefundData": {
        "type": "object",
        "properties": {
          "refundNo": {
            "type": "string",
            "description": "平台退款单号"
          },
          "merchantRefundNo": {
            "type": "string",
            "description": "商户退款单号"
          },
          "tradeNo": {
            "type": "string",
            "description": "原平台交易号"
          },
          "merchantOrderNo": {
            "type": "string",
            "description": "原商户订单号"
          },
          "amount": {
            "type": "string",
            "description": "退款金额"
          },
          "currency": {
            "type": "string",
            "description": "币种"
          },
          "status": {
            "$ref": "#/components/schemas/RefundStatus"
          },
          "resultCode": {
            "type": "string"
          },
          "resultMessage": {
            "type": "string"
          },
          "createdAt": {
            "type": "string"
          },
          "finishedAt": {
            "type": "string"
          }
        }
      },
      "CheckoutSessionCreateRequest": {
        "type": "object",
        "required": [
          "merchantOrderNo",
          "amount",
          "currency",
          "resultUrls"
        ],
        "example": {
          "merchantOrderNo": "SO202611300002",
          "amount": "59.98",
          "currency": "USD",
          "description": "Order #10087",
          "items": [
            {
              "sku": "p_13322",
              "name": "TEST ONLY",
              "price": "29.99",
              "qty": 2
            }
          ],
          "customer": {
            "email": "john@example.com",
            "locale": "en_US"
          },
          "billingAddress": {
            "firstName": "John",
            "lastName": "Doe",
            "phone": "+14155550123",
            "address1": "1226 Sale Ave",
            "city": "Louisville",
            "state": "KY",
            "postalCode": "40215",
            "country": "US"
          },
          "resultUrls": {
            "successUrl": "https://shop.example.com/pay/return",
            "failureUrl": "https://shop.example.com/pay/fail",
            "notifyUrl": "https://shop.example.com/api/pay/notify"
          },
          "expiresIn": 1800,
          "metadata": {
            "cartId": "C10087"
          }
        },
        "properties": {
          "merchantOrderNo": {
            "type": "string",
            "description": "商户订单号"
          },
          "amount": {
            "type": "string",
            "description": "交易金额"
          },
          "currency": {
            "type": "string",
            "description": "币种"
          },
          "description": {
            "type": "string",
            "description": "订单描述"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Product"
            }
          },
          "customer": {
            "$ref": "#/components/schemas/Customer"
          },
          "billingAddress": {
            "$ref": "#/components/schemas/Address"
          },
          "resultUrls": {
            "$ref": "#/components/schemas/ResultUrls"
          },
          "expiresIn": {
            "type": "integer",
            "description": "会话有效期秒数，默认 1800，最大 86400"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          }
        }
      },
      "CheckoutSessionData": {
        "type": "object",
        "properties": {
          "sessionId": {
            "type": "string",
            "description": "会话标识"
          },
          "url": {
            "type": "string",
            "description": "收银台地址，交付浏览器打开"
          },
          "expiresAt": {
            "type": "string",
            "description": "会话过期时间，ISO 8601"
          }
        }
      },
      "TradeNotification": {
        "type": "object",
        "properties": {
          "eventId": {
            "type": "string",
            "description": "事件唯一标识，用于去重"
          },
          "eventType": {
            "type": "string",
            "enum": [
              "PAYMENT_SUCCESS",
              "PAYMENT_FAILED",
              "PAYMENT_CLOSED",
              "REFUND_SUCCESS",
              "REFUND_FAILED"
            ]
          },
          "tradeNo": {
            "type": "string",
            "description": "平台交易号"
          },
          "merchantOrderNo": {
            "type": "string",
            "description": "商户订单号"
          },
          "status": {
            "type": "string",
            "description": "事件发生后的交易状态"
          },
          "amount": {
            "type": "string",
            "description": "交易金额"
          },
          "currency": {
            "type": "string",
            "description": "币种"
          },
          "refundNo": {
            "type": "string",
            "description": "平台退款单号，退款事件返回"
          },
          "merchantRefundNo": {
            "type": "string",
            "description": "商户退款单号，退款事件返回"
          },
          "refundAmount": {
            "type": "string",
            "description": "退款金额，退款事件返回"
          },
          "resultCode": {
            "type": "string",
            "description": "失败时的结果码"
          },
          "resultMessage": {
            "type": "string",
            "description": "结果描述"
          },
          "paidAt": {
            "type": "string",
            "description": "支付成功时间"
          },
          "occurredAt": {
            "type": "string",
            "description": "事件发生时间"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "下单时透传的字段"
          }
        }
      },
      "CommonResponse": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "description": "\"0\" 表示成功"
          },
          "message": {
            "type": "string",
            "description": "结果描述"
          },
          "data": {
            "type": "object",
            "nullable": true,
            "description": "业务数据，失败时为 null"
          },
          "traceId": {
            "type": "string",
            "description": "链路追踪标识，反馈问题时提供"
          }
        }
      },
      "PaymentResponse": {
        "example": {
          "code": "0",
          "message": "success",
          "data": {
            "tradeNo": "T20261130000001",
            "merchantOrderNo": "SO202611300001",
            "status": "PENDING",
            "amount": "34.99",
            "currency": "USD",
            "refundedAmount": null,
            "channel": "aipowerpay",
            "nextAction": {
              "type": "THREE_DS",
              "url": "https://api.shentupay.com/gateway/trade/challenge?token=8f2c1d5e9a7b4c3d",
              "httpMethod": "GET",
              "expiresAt": "2026-11-30T07:20:00+08:00"
            },
            "resultCode": "",
            "resultMessage": "",
            "createdAt": "2026-11-30T07:15:00+08:00",
            "paidAt": null,
            "metadata": {
              "cartId": "C10086"
            }
          },
          "traceId": "7f3c9d2a5b8e4c1f6a0d3b7e9c2f5a80"
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/CommonResponse"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "$ref": "#/components/schemas/PaymentData"
              }
            }
          }
        ]
      },
      "RefundResponse": {
        "example": {
          "code": "0",
          "message": "success",
          "data": {
            "refundNo": "R20261130000001",
            "merchantRefundNo": "SR202611300001",
            "tradeNo": "T20261130000001",
            "merchantOrderNo": "SO202611300001",
            "amount": "34.99",
            "currency": "USD",
            "status": "SUCCESS",
            "resultCode": "",
            "resultMessage": "",
            "createdAt": "2026-11-30T09:02:00+08:00",
            "finishedAt": "2026-11-30T09:02:06+08:00"
          },
          "traceId": "b3e1c7a90d4f2b65"
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/CommonResponse"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "$ref": "#/components/schemas/RefundData"
              }
            }
          }
        ]
      },
      "CheckoutSessionResponse": {
        "example": {
          "code": "0",
          "message": "success",
          "data": {
            "sessionId": "cs_8f2c1d5e9a7b4c3d",
            "url": "https://pay.shentupay.com/checkout/cs_8f2c1d5e9a7b4c3d",
            "expiresAt": "2026-11-30T07:45:00+08:00"
          },
          "traceId": "c9d4e2f7a1b83c60"
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/CommonResponse"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "$ref": "#/components/schemas/CheckoutSessionData"
              }
            }
          }
        ]
      }
    }
  }
}