{
  "openapi": "3.1.0",
  "info": {
    "title": "FlowPay 开放接口",
    "version": "2026.1",
    "description": "FlowPay 面向商户的公开支付接口。\n\n- **原生接口**（`/v1/...`）：JSON 请求与响应，使用应用凭据 `Authorization: Bearer fp_live_...` 鉴权。\n- **易支付兼容接口**（`/mapi.php`、`/submit.php`、`/api.php`，同时提供 `/v1/epay/` 前缀）：使用 PID/PKey 与 MD5 签名，供主流易支付客户端直接接入。\n- **业务回调**：订单或退款状态变化时，FlowPay 以 JSON + HMAC-SHA256 签名 POST 到应用在控制台配置的 HTTPS 回调地址，见 `webhooks`。\n\n约定：\n- 金额一律为整数，单位为人民币**分**（字段名以 `_fen` 结尾）；易支付协议的 `money` 例外，为两位小数的元。\n- 字段名统一使用 snake_case；时间为 RFC 3339 格式。\n- 每个响应都带 `X-Request-ID` 头；原生接口的错误响应体中也有相同的 `request_id`，排查问题时请提供该值。\n- 原生接口错误响应为 `{\"request_id\", \"error\": {\"code\", \"message\"}}`，请按 `error.code` 判断，`message` 为英文说明，可能调整。\n- 原生下单与退款接口使用严格 JSON 解码：未知字段、多段 JSON 或空请求体都会返回 400。"
  },
  "servers": [
    {
      "url": "https://api.flowpay.cn",
      "description": "生产环境"
    }
  ],
  "tags": [
    {
      "name": "订单",
      "description": "原生 Bearer 接口：创建、查询和关闭支付订单。"
    },
    {
      "name": "退款",
      "description": "原生 Bearer 接口：对已支付订单发起全额或部分退款并查询结果。"
    },
    {
      "name": "系统",
      "description": "服务健康检查。"
    },
    {
      "name": "易支付兼容",
      "description": "兼容主流易支付客户端的 PID/PKey + MD5 协议。"
    },
    {
      "name": "业务回调",
      "description": "FlowPay 发送给商户回调地址的 JSON/HMAC 通知。"
    }
  ],
  "paths": {
    "/v1/orders": {
      "post": {
        "operationId": "createOrder",
        "summary": "创建订单",
        "tags": ["订单"],
        "security": [
          {
            "ApplicationCredential": []
          }
        ],
        "description": "创建支付订单并向渠道预下单，返回调起支付所需参数。\n\n幂等：同一应用内 out_trade_no 唯一。重复提交相同 out_trade_no 时，金额、商品说明、channel 与渠道配置必须一致，否则返回 409 `ORDER_CONFLICT`；订单已预下单则直接返回原结果。并发提交同一 out_trade_no 时，后到的请求返回 409 `ORDER_CREATION_BUSY`，请稍后用同一值重试。\n\n限流：每个应用每分钟（UTC 自然分钟）最多 120 次下单请求。\n\n处理顺序：先校验请求体（400），再校验凭据（401）。",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateOrderRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "订单已创建或已存在且可支付。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateOrderResponse"
                },
                "examples": {
                  "wechat_native": {
                    "summary": "微信 Native",
                    "value": {
                      "order": {
                        "id": 10086,
                        "merchant_id": 12,
                        "merchant_code": "demo_merchant",
                        "application_id": 34,
                        "application_code": "demo_shop",
                        "channel_config_id": 56,
                        "order_no": "20260925120000000001",
                        "out_trade_no": "SHOP-20260925-0001",
                        "provider_out_trade_no": "20260925120000000001",
                        "channel": "wechat_native",
                        "amount_fen": 1990,
                        "refunded_amount_fen": 0,
                        "description": "示例商品",
                        "status": "created",
                        "expires_at": "2026-09-25T04:30:00Z",
                        "created_at": "2026-09-25T04:00:00Z",
                        "updated_at": "2026-09-25T04:00:01Z"
                      },
                      "prepay": {
                        "code_url": "weixin://wxpay/bizpayurl?pr=EXAMPLE00"
                      },
                      "client_params": {
                        "code_url": "weixin://wxpay/bizpayurl?pr=EXAMPLE00"
                      }
                    }
                  },
                  "alipay_h5": {
                    "summary": "支付宝 H5",
                    "value": {
                      "order": {
                        "id": 10086,
                        "merchant_id": 12,
                        "merchant_code": "demo_merchant",
                        "application_id": 34,
                        "application_code": "demo_shop",
                        "channel_config_id": 56,
                        "order_no": "20260925120000000001",
                        "out_trade_no": "SHOP-20260925-0001",
                        "provider_out_trade_no": "20260925120000000001",
                        "channel": "alipay_h5",
                        "amount_fen": 1990,
                        "refunded_amount_fen": 0,
                        "description": "示例商品",
                        "status": "created",
                        "expires_at": "2026-09-25T04:30:00Z",
                        "created_at": "2026-09-25T04:00:00Z",
                        "updated_at": "2026-09-25T04:00:01Z"
                      },
                      "prepay": {
                        "out_trade_no": "20260925120000000001",
                        "subject": "示例商品",
                        "total_amount": "19.90",
                        "product_code": "QUICK_WAP_WAY"
                      },
                      "client_params": {
                        "payment_page_url": "https://pay.flowpay.cn/pay/EXAMPLE_payment_session_token_0000000000",
                        "alipay_qr_payload": "https://render.alipay.com/p/s/i/?scheme=alipays%3A%2F%2Fplatformapi%2Fstartapp%3FappId%3D20000067%26url%3Dhttps%253A%252F%252Fpay.flowpay.cn%252Fpay%252FEXAMPLE_payment_session_token_0000000000"
                      },
                      "payment_page_url": "https://pay.flowpay.cn/pay/EXAMPLE_payment_session_token_0000000000",
                      "alipay_qr_payload": "https://render.alipay.com/p/s/i/?scheme=alipays%3A%2F%2Fplatformapi%2Fstartapp%3FappId%3D20000067%26url%3Dhttps%253A%252F%252Fpay.flowpay.cn%252Fpay%252FEXAMPLE_payment_session_token_0000000000"
                    }
                  },
                  "alipay_page": {
                    "summary": "支付宝电脑网站",
                    "value": {
                      "order": {
                        "id": 10086,
                        "merchant_id": 12,
                        "merchant_code": "demo_merchant",
                        "application_id": 34,
                        "application_code": "demo_shop",
                        "channel_config_id": 56,
                        "order_no": "20260925120000000001",
                        "out_trade_no": "SHOP-20260925-0001",
                        "provider_out_trade_no": "20260925120000000001",
                        "channel": "alipay_page",
                        "amount_fen": 1990,
                        "refunded_amount_fen": 0,
                        "description": "示例商品",
                        "status": "created",
                        "expires_at": "2026-09-25T04:30:00Z",
                        "created_at": "2026-09-25T04:00:00Z",
                        "updated_at": "2026-09-25T04:00:01Z",
                        "prepay": {
                          "subject": "示例商品",
                          "out_trade_no": "20260925120000000001",
                          "total_amount": "19.90",
                          "product_code": "FAST_INSTANT_TRADE_PAY"
                        }
                      },
                      "prepay": {
                        "subject": "示例商品",
                        "out_trade_no": "20260925120000000001",
                        "total_amount": "19.90",
                        "product_code": "FAST_INSTANT_TRADE_PAY"
                      },
                      "client_params": {
                        "payment_url": "https://openapi.alipay.com/gateway.do?EXAMPLE=1",
                        "payment_page_url": "https://pay.flowpay.cn/pay/EXAMPLE_payment_session_token_0000000000"
                      },
                      "payment_page_url": "https://pay.flowpay.cn/pay/EXAMPLE_payment_session_token_0000000000"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "请求参数错误。\n\n可能的 error.code：\n- `INVALID_ORDER_REQUEST`：请求体不是合法 JSON、含未知字段、out_trade_no 格式不符，或 amount_fen ≤ 0、description 为空。\n- `UNSUPPORTED_CHANNEL`：channel 不在支持列表中。\n- `UNSUPPORTED_PROVIDER`：provider_code 不是 official 或 epay。\n- `APP_ID_REQUIRED`：官方渠道配置缺少 app_id。\n- `OPENID_REQUIRED`：官方 wechat_jsapi 未提供 openid。\n- `NOTIFY_URL_REQUIRED`：渠道配置缺少平台通知地址。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "INVALID_ORDER_REQUEST": {
                    "summary": "INVALID_ORDER_REQUEST",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "INVALID_ORDER_REQUEST",
                        "message": "invalid order request"
                      }
                    }
                  },
                  "UNSUPPORTED_CHANNEL": {
                    "summary": "UNSUPPORTED_CHANNEL",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "UNSUPPORTED_CHANNEL",
                        "message": "channel must be wechat_native, wechat_jsapi, alipay_h5 or alipay_page"
                      }
                    }
                  },
                  "UNSUPPORTED_PROVIDER": {
                    "summary": "UNSUPPORTED_PROVIDER",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "UNSUPPORTED_PROVIDER",
                        "message": "provider_code must be official or epay"
                      }
                    }
                  },
                  "APP_ID_REQUIRED": {
                    "summary": "APP_ID_REQUIRED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "APP_ID_REQUIRED",
                        "message": "app_id is required for the selected payment product"
                      }
                    }
                  },
                  "OPENID_REQUIRED": {
                    "summary": "OPENID_REQUIRED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "OPENID_REQUIRED",
                        "message": "openid is required for JSAPI"
                      }
                    }
                  },
                  "NOTIFY_URL_REQUIRED": {
                    "summary": "NOTIFY_URL_REQUIRED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "NOTIFY_URL_REQUIRED",
                        "message": "notify_url is required"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "应用凭据缺失或无效。\n\n可能的 error.code：\n- `INVALID_CREDENTIAL`：Authorization 头缺失、不是 `Bearer ` 开头，或凭据不存在、已吊销，或其所属应用/商户未启用。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "INVALID_CREDENTIAL": {
                    "summary": "INVALID_CREDENTIAL",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "INVALID_CREDENTIAL",
                        "message": "valid application credential is required"
                      }
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "订单冲突。\n\n可能的 error.code：\n- `ORDER_CREATION_BUSY`：同一 out_trade_no 的下单请求正在处理，请用同一值重试。\n- `ORDER_CONFLICT`：out_trade_no 已存在，但金额、商品说明、channel 或渠道配置不同。\n- `ORDER_NOT_PAYABLE`：订单已过期或已进入终态。此时响应额外包含 `order` 快照，请按其 status 处理（可能已支付）；`order.status` 也可能仍是 `created`，表示订单已过期、后台还没完成关单。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/Error"
                    },
                    {
                      "$ref": "#/components/schemas/ErrorWithOrder"
                    }
                  ]
                },
                "examples": {
                  "ORDER_CONFLICT": {
                    "summary": "ORDER_CONFLICT",
                    "value": {
                      "request_id": "req_EXAMPLE",
                      "error": {
                        "code": "ORDER_CONFLICT",
                        "message": "out_trade_no already exists with different order data"
                      }
                    }
                  },
                  "ORDER_NOT_PAYABLE": {
                    "summary": "ORDER_NOT_PAYABLE",
                    "value": {
                      "request_id": "req_EXAMPLE",
                      "error": {
                        "code": "ORDER_NOT_PAYABLE",
                        "message": "order is expired or already finalized"
                      },
                      "order": {
                        "id": 10086,
                        "merchant_id": 12,
                        "merchant_code": "demo_merchant",
                        "application_id": 34,
                        "application_code": "demo_shop",
                        "channel_config_id": 56,
                        "order_no": "20260925120000000001",
                        "out_trade_no": "SHOP-20260925-0001",
                        "provider_out_trade_no": "20260925120000000001",
                        "channel": "wechat_native",
                        "amount_fen": 1990,
                        "refunded_amount_fen": 0,
                        "description": "示例商品",
                        "status": "closed",
                        "expires_at": "2026-09-25T04:30:00Z",
                        "created_at": "2026-09-25T04:00:00Z",
                        "updated_at": "2026-09-25T04:00:01Z",
                        "close_source": "system_expiry",
                        "closed_at": "2026-09-25T04:30:05Z"
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "下单过于频繁。\n\n可能的 error.code：\n- `RATE_LIMITED`：超过每应用每分钟 120 次。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "RATE_LIMITED": {
                    "summary": "RATE_LIMITED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "RATE_LIMITED",
                        "message": "too many order requests"
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "服务内部错误。\n\n可能的 error.code：\n- `ORDER_CREATE_FAILED`：保存本地订单失败。\n- `ORDER_PREPAY_SAVE_FAILED`：保存预支付结果失败。\n- `PAYMENT_PAGE_CREATE_FAILED`：支付宝 H5 订单中心创建失败。\n- `ORDER_RESPONSE_FAILED`：订单响应编码失败。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ORDER_CREATE_FAILED": {
                    "summary": "ORDER_CREATE_FAILED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "ORDER_CREATE_FAILED",
                        "message": "create local order failed"
                      }
                    }
                  },
                  "ORDER_PREPAY_SAVE_FAILED": {
                    "summary": "ORDER_PREPAY_SAVE_FAILED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "ORDER_PREPAY_SAVE_FAILED",
                        "message": "save prepay response failed"
                      }
                    }
                  },
                  "PAYMENT_PAGE_CREATE_FAILED": {
                    "summary": "PAYMENT_PAGE_CREATE_FAILED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "PAYMENT_PAGE_CREATE_FAILED",
                        "message": "create payment page failed"
                      }
                    }
                  },
                  "ORDER_RESPONSE_FAILED": {
                    "summary": "ORDER_RESPONSE_FAILED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "ORDER_RESPONSE_FAILED",
                        "message": "encode order response failed"
                      }
                    }
                  }
                }
              }
            }
          },
          "502": {
            "description": "渠道预下单失败，message 为渠道错误信息。\n\n可能的 error.code：\n- `PROVIDER_CREATE_FAILED`：微信或支付宝预下单返回错误。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "PROVIDER_CREATE_FAILED": {
                    "summary": "PROVIDER_CREATE_FAILED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "PROVIDER_CREATE_FAILED",
                        "message": "create native order: ..."
                      }
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "依赖暂不可用，可稍后重试。\n\n可能的 error.code：\n- `RATE_LIMIT_UNAVAILABLE`：限流计数不可用。\n- `ORDER_CREATION_LOCK_UNAVAILABLE`：下单锁不可用。\n- `PAYMENT_CHANNEL_UNAVAILABLE`：应用未配置所选渠道或渠道凭据不可用，message 为具体原因。\n- `PAYMENT_POLICY_UNAVAILABLE`：读取应用订单策略失败。\n- `ORDER_NUMBER_UNAVAILABLE`：订单号生成失败。\n- `EPAY_NOT_CONFIGURED`：provider_code=epay 但应用的易支付凭据不可用。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "RATE_LIMIT_UNAVAILABLE": {
                    "summary": "RATE_LIMIT_UNAVAILABLE",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "RATE_LIMIT_UNAVAILABLE",
                        "message": "request rate limit is unavailable"
                      }
                    }
                  },
                  "ORDER_CREATION_LOCK_UNAVAILABLE": {
                    "summary": "ORDER_CREATION_LOCK_UNAVAILABLE",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "ORDER_CREATION_LOCK_UNAVAILABLE",
                        "message": "order creation lock is unavailable"
                      }
                    }
                  },
                  "PAYMENT_CHANNEL_UNAVAILABLE": {
                    "summary": "PAYMENT_CHANNEL_UNAVAILABLE",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "PAYMENT_CHANNEL_UNAVAILABLE",
                        "message": "wechat channel is not configured"
                      }
                    }
                  },
                  "PAYMENT_POLICY_UNAVAILABLE": {
                    "summary": "PAYMENT_POLICY_UNAVAILABLE",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "PAYMENT_POLICY_UNAVAILABLE",
                        "message": "payment policy is unavailable"
                      }
                    }
                  },
                  "ORDER_NUMBER_UNAVAILABLE": {
                    "summary": "ORDER_NUMBER_UNAVAILABLE",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "ORDER_NUMBER_UNAVAILABLE",
                        "message": "unable to generate order number"
                      }
                    }
                  },
                  "EPAY_NOT_CONFIGURED": {
                    "summary": "EPAY_NOT_CONFIGURED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "EPAY_NOT_CONFIGURED",
                        "message": "epay application credential is unavailable"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/orders/{out_trade_no}": {
      "get": {
        "operationId": "getOrder",
        "summary": "查询订单",
        "tags": ["订单"],
        "security": [
          {
            "ApplicationCredential": []
          }
        ],
        "description": "按商户订单号查询订单，返回订单对象（无 `order` 包装层）。只返回 FlowPay 本地状态，不会实时向渠道查单。\n\n**超时未支付**：FlowPay 后台任务每 5 秒扫描一次已过 `expires_at` 的 `created` 订单，先向渠道查单，确认未支付才关单并再次确认，然后把订单改为 `closed`（`close_source` 为 `system_expiry`）；确认时发现已付款则改为 `paid`。状态由后台任务推进，查单时不会现算，任务完成前查单仍返回 `created`。正常只有几秒，渠道接口失败时任务会稍后重试。需要马上拿到结果时请调用关单接口。",
        "parameters": [
          {
            "name": "out_trade_no",
            "in": "path",
            "required": true,
            "description": "商户订单号。",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,32}$",
              "maxLength": 32
            }
          }
        ],
        "responses": {
          "200": {
            "description": "订单对象。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                }
              }
            }
          },
          "401": {
            "description": "应用凭据缺失或无效。\n\n可能的 error.code：\n- `INVALID_CREDENTIAL`：Authorization 头缺失、不是 `Bearer ` 开头，或凭据不存在、已吊销，或其所属应用/商户未启用。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "INVALID_CREDENTIAL": {
                    "summary": "INVALID_CREDENTIAL",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "INVALID_CREDENTIAL",
                        "message": "valid application credential is required"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "订单不存在。\n\n可能的 error.code：\n- `ORDER_NOT_FOUND`：当前应用下不存在该 out_trade_no。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ORDER_NOT_FOUND": {
                    "summary": "ORDER_NOT_FOUND",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "ORDER_NOT_FOUND",
                        "message": "order not found"
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "服务内部错误。\n\n可能的 error.code：\n- `ORDER_LOAD_FAILED`：读取订单失败。\n- `ORDER_RESPONSE_FAILED`：订单响应编码失败。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ORDER_LOAD_FAILED": {
                    "summary": "ORDER_LOAD_FAILED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "ORDER_LOAD_FAILED",
                        "message": "load order failed"
                      }
                    }
                  },
                  "ORDER_RESPONSE_FAILED": {
                    "summary": "ORDER_RESPONSE_FAILED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "ORDER_RESPONSE_FAILED",
                        "message": "encode order response failed"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/orders/{out_trade_no}/close": {
      "post": {
        "operationId": "closeOrder",
        "summary": "关闭订单",
        "tags": ["订单"],
        "security": [
          {
            "ApplicationCredential": []
          }
        ],
        "description": "关闭待支付订单。FlowPay 先向渠道查单，必要时关单后再次查单确认。若发现订单实际已支付，仍返回 200，订单 status 为 paid，必须按已支付处理。订单已是终态时直接返回当前订单。无请求体。\n\n**对已过期订单关单的结果：**\n\n- 订单已是 `closed`、`paid`、`refunded`、`failed`：200，返回当前状态，不再请求渠道。\n- 订单仍是 `created`，渠道确认未支付：200，`status` 为 `closed`，`close_source` 为 `merchant_request`。\n- 订单仍是 `created`，渠道查到已付款：200，`status` 为 `paid`。\n- 后台任务正在处理同一笔订单：409 `ORDER_LIFECYCLE_BUSY`，稍后重试。\n- 渠道关单失败：502 `ORDER_CLOSE_FAILED`，稍后重试。\n\n关单接口不会返回 `ORDER_NOT_PAYABLE`。",
        "parameters": [
          {
            "name": "out_trade_no",
            "in": "path",
            "required": true,
            "description": "商户订单号。",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,32}$",
              "maxLength": 32
            }
          }
        ],
        "responses": {
          "200": {
            "description": "关闭后（或当前）的订单对象。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                }
              }
            }
          },
          "401": {
            "description": "应用凭据缺失或无效。\n\n可能的 error.code：\n- `INVALID_CREDENTIAL`：Authorization 头缺失、不是 `Bearer ` 开头，或凭据不存在、已吊销，或其所属应用/商户未启用。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "INVALID_CREDENTIAL": {
                    "summary": "INVALID_CREDENTIAL",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "INVALID_CREDENTIAL",
                        "message": "valid application credential is required"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "订单不存在。\n\n可能的 error.code：\n- `ORDER_NOT_FOUND`：当前应用下不存在该 out_trade_no。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ORDER_NOT_FOUND": {
                    "summary": "ORDER_NOT_FOUND",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "ORDER_NOT_FOUND",
                        "message": "order not found"
                      }
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "订单正在被处理。\n\n可能的 error.code：\n- `ORDER_LIFECYCLE_BUSY`：该订单正在关单或到期处理中，请稍后重试。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ORDER_LIFECYCLE_BUSY": {
                    "summary": "ORDER_LIFECYCLE_BUSY",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "ORDER_LIFECYCLE_BUSY",
                        "message": "order is being processed"
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "服务内部错误。\n\n可能的 error.code：\n- `ORDER_LOAD_FAILED`：读取订单失败。\n- `ORDER_RESPONSE_FAILED`：订单响应编码失败。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ORDER_LOAD_FAILED": {
                    "summary": "ORDER_LOAD_FAILED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "ORDER_LOAD_FAILED",
                        "message": "load order failed"
                      }
                    }
                  },
                  "ORDER_RESPONSE_FAILED": {
                    "summary": "ORDER_RESPONSE_FAILED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "ORDER_RESPONSE_FAILED",
                        "message": "encode order response failed"
                      }
                    }
                  }
                }
              }
            }
          },
          "502": {
            "description": "关单失败。\n\n可能的 error.code：\n- `ORDER_CLOSE_FAILED`：渠道查单、关单或保存结果失败，可稍后重试。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ORDER_CLOSE_FAILED": {
                    "summary": "ORDER_CLOSE_FAILED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "ORDER_CLOSE_FAILED",
                        "message": "close order failed"
                      }
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "依赖暂不可用。\n\n可能的 error.code：\n- `ORDER_LIFECYCLE_UNAVAILABLE`：订单锁不可用。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ORDER_LIFECYCLE_UNAVAILABLE": {
                    "summary": "ORDER_LIFECYCLE_UNAVAILABLE",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "ORDER_LIFECYCLE_UNAVAILABLE",
                        "message": "order lifecycle is unavailable"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/refunds": {
      "post": {
        "operationId": "createRefund",
        "summary": "发起退款",
        "tags": ["退款"],
        "security": [
          {
            "ApplicationCredential": []
          }
        ],
        "description": "对已支付订单发起全额或部分退款。只有 status 为 paid 的订单可以退款（部分退款后仍为 paid，全额退款后变为 refunded）。\n\n幂等：out_refund_no 在应用内唯一。重复提交时 order_no、amount_fen、reason 必须一致，否则返回 409 `REFUND_CONFLICT`；一致时返回已有退款的当前状态。\n\n退款间隔、单订单次数上限、退款期限和是否串行，由应用的退款防护策略决定。处理顺序：先校验请求体（400），再校验凭据（401）。",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateRefundRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "退款已受理或已存在。最终结果以 status 和 refund.updated 回调为准。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RefundResponse"
                }
              }
            }
          },
          "400": {
            "description": "请求参数错误。\n\n可能的 error.code：\n- `INVALID_REFUND_REQUEST`：请求体不合法、含未知字段、order_no 不是 20 位数字、out_refund_no 格式不符或 amount_fen ≤ 0。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "INVALID_REFUND_REQUEST": {
                    "summary": "INVALID_REFUND_REQUEST",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "INVALID_REFUND_REQUEST",
                        "message": "order_no, out_refund_no and positive amount_fen are required"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "应用凭据缺失或无效。\n\n可能的 error.code：\n- `INVALID_CREDENTIAL`：Authorization 头缺失、不是 `Bearer ` 开头，或凭据不存在、已吊销，或其所属应用/商户未启用。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "INVALID_CREDENTIAL": {
                    "summary": "INVALID_CREDENTIAL",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "INVALID_CREDENTIAL",
                        "message": "valid application credential is required"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "订单不存在。\n\n可能的 error.code：\n- `ORDER_NOT_FOUND`：当前应用下不存在该 order_no。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ORDER_NOT_FOUND": {
                    "summary": "ORDER_NOT_FOUND",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "ORDER_NOT_FOUND",
                        "message": "order not found"
                      }
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "当前不能退款。\n\n可能的 error.code：\n- `REFUND_ORDER_NOT_PAID`：订单不是 paid 状态。\n- `REFUND_AMOUNT_EXCEEDED`：超过剩余可退金额（已扣除处理中的退款）。\n- `REFUND_CONFLICT`：out_refund_no 已存在但参数不同。\n- `REFUND_TOO_SOON`：距上次退款间隔不足，按 Retry-After 秒数后重试。\n- `REFUND_ATTEMPTS_EXCEEDED`：超过单订单退款次数上限。\n- `REFUND_WINDOW_EXPIRED`：超过退款期限。\n- `REFUND_IN_PROGRESS`：策略要求串行，且该订单已有处理中的退款。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              },
              "Retry-After": {
                "description": "仅 REFUND_TOO_SOON 时返回，需等待的秒数。",
                "schema": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "REFUND_ORDER_NOT_PAID": {
                    "summary": "REFUND_ORDER_NOT_PAID",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "REFUND_ORDER_NOT_PAID",
                        "message": "only paid orders can be refunded"
                      }
                    }
                  },
                  "REFUND_AMOUNT_EXCEEDED": {
                    "summary": "REFUND_AMOUNT_EXCEEDED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "REFUND_AMOUNT_EXCEEDED",
                        "message": "refund amount exceeds refundable amount"
                      }
                    }
                  },
                  "REFUND_CONFLICT": {
                    "summary": "REFUND_CONFLICT",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "REFUND_CONFLICT",
                        "message": "out_refund_no already exists with different refund data"
                      }
                    }
                  },
                  "REFUND_TOO_SOON": {
                    "summary": "REFUND_TOO_SOON",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "REFUND_TOO_SOON",
                        "message": "another refund was submitted too recently; retry after 30 seconds"
                      }
                    }
                  },
                  "REFUND_ATTEMPTS_EXCEEDED": {
                    "summary": "REFUND_ATTEMPTS_EXCEEDED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "REFUND_ATTEMPTS_EXCEEDED",
                        "message": "refund attempt limit exceeded"
                      }
                    }
                  },
                  "REFUND_WINDOW_EXPIRED": {
                    "summary": "REFUND_WINDOW_EXPIRED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "REFUND_WINDOW_EXPIRED",
                        "message": "refund window has expired"
                      }
                    }
                  },
                  "REFUND_IN_PROGRESS": {
                    "summary": "REFUND_IN_PROGRESS",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "REFUND_IN_PROGRESS",
                        "message": "another refund is already in progress"
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "服务内部错误。\n\n可能的 error.code：\n- `REFUND_CREATE_FAILED`：创建退款失败。\n- `REFUND_READ_FAILED`：读取退款失败。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "REFUND_CREATE_FAILED": {
                    "summary": "REFUND_CREATE_FAILED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "REFUND_CREATE_FAILED",
                        "message": "create refund failed"
                      }
                    }
                  },
                  "REFUND_READ_FAILED": {
                    "summary": "REFUND_READ_FAILED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "REFUND_READ_FAILED",
                        "message": "read refund failed"
                      }
                    }
                  }
                }
              }
            }
          },
          "502": {
            "description": "提交渠道退款失败。\n\n可能的 error.code：\n- `REFUND_PROVIDER_FAILED`：退款已创建但提交渠道失败，仍为 created 并冻结额度，FlowPay 后台会按策略重新提交；也可用相同参数重试。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "REFUND_PROVIDER_FAILED": {
                    "summary": "REFUND_PROVIDER_FAILED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "REFUND_PROVIDER_FAILED",
                        "message": "refund provider request failed"
                      }
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "依赖暂不可用。\n\n可能的 error.code：\n- `REFUND_SUBMIT_UNAVAILABLE`：退款提交状态更新失败。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "REFUND_SUBMIT_UNAVAILABLE": {
                    "summary": "REFUND_SUBMIT_UNAVAILABLE",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "REFUND_SUBMIT_UNAVAILABLE",
                        "message": "refund submit state is unavailable"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "get": {
        "operationId": "listRefunds",
        "summary": "按订单查询退款",
        "tags": ["退款"],
        "security": [
          {
            "ApplicationCredential": []
          }
        ],
        "description": "列出当前应用的退款，按更新时间倒序，最多返回 100 条，不支持分页。\n\n注意：`order_no` 是不区分大小写的模糊匹配，会同时匹配 order_no、out_trade_no、out_refund_no 和 refund_no 中包含该值的退款；传完整的 20 位订单号可得到该订单的退款。省略时返回应用内最近的退款。",
        "parameters": [
          {
            "name": "order_no",
            "in": "query",
            "required": false,
            "description": "FlowPay 订单号（模糊匹配，见上文）。",
            "schema": {
              "type": "string"
            },
            "example": "20260925120000000001"
          }
        ],
        "responses": {
          "200": {
            "description": "退款列表。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RefundListResponse"
                }
              }
            }
          },
          "401": {
            "description": "应用凭据缺失或无效。\n\n可能的 error.code：\n- `INVALID_CREDENTIAL`：Authorization 头缺失、不是 `Bearer ` 开头，或凭据不存在、已吊销，或其所属应用/商户未启用。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "INVALID_CREDENTIAL": {
                    "summary": "INVALID_CREDENTIAL",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "INVALID_CREDENTIAL",
                        "message": "valid application credential is required"
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "服务内部错误。\n\n可能的 error.code：\n- `REFUND_READ_FAILED`：读取退款失败。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "REFUND_READ_FAILED": {
                    "summary": "REFUND_READ_FAILED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "REFUND_READ_FAILED",
                        "message": "read refunds failed"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/refunds/{out_refund_no}": {
      "get": {
        "operationId": "getRefund",
        "summary": "查询退款",
        "tags": ["退款"],
        "security": [
          {
            "ApplicationCredential": []
          }
        ],
        "description": "按商户退款单号查询退款，只返回 FlowPay 本地状态。",
        "parameters": [
          {
            "name": "out_refund_no",
            "in": "path",
            "required": true,
            "description": "商户退款单号。",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,32}$",
              "maxLength": 32
            }
          }
        ],
        "responses": {
          "200": {
            "description": "退款对象。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RefundResponse"
                }
              }
            }
          },
          "401": {
            "description": "应用凭据缺失或无效。\n\n可能的 error.code：\n- `INVALID_CREDENTIAL`：Authorization 头缺失、不是 `Bearer ` 开头，或凭据不存在、已吊销，或其所属应用/商户未启用。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "INVALID_CREDENTIAL": {
                    "summary": "INVALID_CREDENTIAL",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "INVALID_CREDENTIAL",
                        "message": "valid application credential is required"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "退款不存在。\n\n可能的 error.code：\n- `REFUND_NOT_FOUND`：当前应用下不存在该 out_refund_no。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "REFUND_NOT_FOUND": {
                    "summary": "REFUND_NOT_FOUND",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "REFUND_NOT_FOUND",
                        "message": "refund not found"
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "服务内部错误。\n\n可能的 error.code：\n- `REFUND_READ_FAILED`：读取退款失败。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "REFUND_READ_FAILED": {
                    "summary": "REFUND_READ_FAILED",
                    "value": {
                      "request_id": "req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA",
                      "error": {
                        "code": "REFUND_READ_FAILED",
                        "message": "read refund failed"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/health": {
      "get": {
        "operationId": "getHealth",
        "summary": "健康检查",
        "tags": ["系统"],
        "security": [],
        "description": "检查 FlowPay API 及其数据库、Redis 是否可用，无需鉴权。",
        "responses": {
          "200": {
            "description": "服务正常。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                },
                "examples": {
                  "ok": {
                    "summary": "正常",
                    "value": {
                      "status": "ok",
                      "wechat_ready": true,
                      "application_code": "flowpay"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "依赖不可用。",
            "headers": {
              "X-Request-ID": {
                "$ref": "#/components/headers/X-Request-ID"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                },
                "examples": {
                  "degraded": {
                    "summary": "降级",
                    "value": {
                      "status": "degraded",
                      "redis": "unavailable"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/mapi.php": {
      "get": {
        "operationId": "epayCreateGet",
        "summary": "易支付下单（GET）",
        "tags": ["易支付兼容"],
        "security": [],
        "description": "易支付兼容下单，返回 JSON。trade_no 为 FlowPay 订单号，out_trade_no 原样返回。\n\n签名规则（MD5）：取全部请求参数，去掉 `sign`、`sign_type` 和值为空的参数，按参数名 ASCII 升序排列，拼接成 `k1=v1&k2=v2` 形式（值不做 URL 编码），末尾直接拼接 PKey，计算 MD5，取 32 位十六进制（大小写均可）。兼容旧客户端在末尾拼接 `&key=PKey` 的变体。除下表外的其他非空参数也会参与签名。\n\n支付状态变化后，FlowPay 向下单时的 notify_url 以表单 POST 发送 pid、trade_no、out_trade_no、type、name、money、trade_status、param、sign_type、sign（签名规则同上），商户应返回 2xx 且正文为空或 `success`，否则按退避策略重试。\n\n该接口接受任意 HTTP 方法；这里列出 GET（查询参数）和 POST（`application/x-www-form-urlencoded` 表单，不支持 multipart 与 JSON）。POST 时 URL 查询参数同样会被读取并参与签名。",
        "parameters": [
          {
            "name": "pid",
            "in": "query",
            "required": true,
            "description": "易支付商户 ID，在控制台为应用创建，形如 `fp_epay_...`。",
            "schema": {
              "type": "string",
              "examples": ["fp_epay_EXAMPLEexample000000"]
            }
          },
          {
            "name": "type",
            "in": "query",
            "required": true,
            "description": "支付方式，不区分大小写。`wxpay` 等为微信 Native；`alipay` 等为支付宝 H5；`alipay_page` 等为支付宝电脑网站。JSAPI（`wxpay_jsapi`、`wechat_jsapi`、`jsapi`）会被拒绝。",
            "schema": {
              "type": "string",
              "enum": [
                "wxpay",
                "wechat",
                "wechat_native",
                "native",
                "alipay",
                "alipay_h5",
                "alipay_wap",
                "wap",
                "alipay_pc",
                "alipay_page",
                "page"
              ]
            }
          },
          {
            "name": "out_trade_no",
            "in": "query",
            "required": false,
            "description": "商户订单号，1～32 位字母、数字、下划线或连字符；省略时使用 FlowPay 订单号。",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,32}$",
              "maxLength": 32,
              "examples": ["SHOP-20260925-0001"]
            }
          },
          {
            "name": "notify_url",
            "in": "query",
            "required": true,
            "description": "异步通知地址，必须是 HTTPS 且不含用户信息。",
            "schema": {
              "type": "string",
              "format": "uri",
              "examples": ["https://shop.example.com/epay/notify"]
            }
          },
          {
            "name": "return_url",
            "in": "query",
            "required": false,
            "description": "支付成功后浏览器返回地址，提供时必须是 HTTPS。",
            "schema": {
              "type": "string",
              "format": "uri",
              "examples": ["https://shop.example.com/epay/return"]
            }
          },
          {
            "name": "name",
            "in": "query",
            "required": true,
            "description": "商品名称。",
            "schema": {
              "type": "string",
              "minLength": 1,
              "examples": ["示例商品"]
            }
          },
          {
            "name": "money",
            "in": "query",
            "required": true,
            "description": "金额，单位元，最多两位小数，必须大于 0。",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]+(\\.[0-9]{1,2})?$",
              "examples": ["19.90"]
            }
          },
          {
            "name": "param",
            "in": "query",
            "required": false,
            "description": "业务扩展参数，会在异步通知中原样返回。",
            "schema": {
              "type": "string",
              "examples": ["custom-data"]
            }
          },
          {
            "name": "sign_type",
            "in": "query",
            "required": false,
            "description": "签名类型，只支持 MD5（不区分大小写），可省略。",
            "schema": {
              "type": "string",
              "enum": ["MD5"]
            }
          },
          {
            "name": "sign",
            "in": "query",
            "required": true,
            "description": "MD5 签名。",
            "schema": {
              "type": "string",
              "pattern": "^[0-9A-Fa-f]{32}$",
              "examples": ["0123456789abcdef0123456789abcdef"]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "下单成功。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpayCreateResponse"
                }
              }
            }
          },
          "400": {
            "description": "失败，HTTP 400，`code` 为 0。渠道或内部错误时 msg 为具体原因。\n\n常见 msg：\n- pid 是必填参数\n- 易支付凭据不存在或已停用\n- 易支付凭据不可读取\n- 易支付只支持 MD5 签名\n- 易支付请求签名校验失败\n- type 只支持 wxpay、alipay 或 alipay_page\n- 易支付 JSAPI 需要用户 openid，暂不接受公共协议下单\n- out_trade_no 必须是 1-32 位字母、数字、下划线或连字符\n- name 是必填参数\n- money 必须是大于 0 的两位小数金额\n- notify_url 是必填参数\n- notify_url 无效: ...\n- return_url 必须是有效的 HTTPS 地址\n- 易支付应用不存在或已停用\n- 订单创建正在处理中，请使用相同 out_trade_no 重试\n- out_trade_no 已被其他订单占用\n- 订单已过期或已进入终态，不能继续支付",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpayFailure"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "epayCreatePost",
        "summary": "易支付下单（POST）",
        "tags": ["易支付兼容"],
        "security": [],
        "description": "易支付兼容下单，返回 JSON。trade_no 为 FlowPay 订单号，out_trade_no 原样返回。\n\n签名规则（MD5）：取全部请求参数，去掉 `sign`、`sign_type` 和值为空的参数，按参数名 ASCII 升序排列，拼接成 `k1=v1&k2=v2` 形式（值不做 URL 编码），末尾直接拼接 PKey，计算 MD5，取 32 位十六进制（大小写均可）。兼容旧客户端在末尾拼接 `&key=PKey` 的变体。除下表外的其他非空参数也会参与签名。\n\n支付状态变化后，FlowPay 向下单时的 notify_url 以表单 POST 发送 pid、trade_no、out_trade_no、type、name、money、trade_status、param、sign_type、sign（签名规则同上），商户应返回 2xx 且正文为空或 `success`，否则按退避策略重试。\n\n该接口接受任意 HTTP 方法；这里列出 GET（查询参数）和 POST（`application/x-www-form-urlencoded` 表单，不支持 multipart 与 JSON）。POST 时 URL 查询参数同样会被读取并参与签名。",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/EpayCreateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "下单成功。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpayCreateResponse"
                }
              }
            }
          },
          "400": {
            "description": "失败，HTTP 400，`code` 为 0。渠道或内部错误时 msg 为具体原因。\n\n常见 msg：\n- pid 是必填参数\n- 易支付凭据不存在或已停用\n- 易支付凭据不可读取\n- 易支付只支持 MD5 签名\n- 易支付请求签名校验失败\n- type 只支持 wxpay、alipay 或 alipay_page\n- 易支付 JSAPI 需要用户 openid，暂不接受公共协议下单\n- out_trade_no 必须是 1-32 位字母、数字、下划线或连字符\n- name 是必填参数\n- money 必须是大于 0 的两位小数金额\n- notify_url 是必填参数\n- notify_url 无效: ...\n- return_url 必须是有效的 HTTPS 地址\n- 易支付应用不存在或已停用\n- 订单创建正在处理中，请使用相同 out_trade_no 重试\n- out_trade_no 已被其他订单占用\n- 订单已过期或已进入终态，不能继续支付",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpayFailure"
                }
              }
            }
          }
        }
      }
    },
    "/v1/epay/mapi.php": {
      "get": {
        "operationId": "epayCreateV1Get",
        "summary": "易支付下单 /v1/epay 前缀（GET）",
        "tags": ["易支付兼容"],
        "security": [],
        "description": "与 `/mapi.php` 完全相同，供需要 `/v1` 前缀的网关转发使用。\n\n易支付兼容下单，返回 JSON。trade_no 为 FlowPay 订单号，out_trade_no 原样返回。\n\n签名规则（MD5）：取全部请求参数，去掉 `sign`、`sign_type` 和值为空的参数，按参数名 ASCII 升序排列，拼接成 `k1=v1&k2=v2` 形式（值不做 URL 编码），末尾直接拼接 PKey，计算 MD5，取 32 位十六进制（大小写均可）。兼容旧客户端在末尾拼接 `&key=PKey` 的变体。除下表外的其他非空参数也会参与签名。\n\n支付状态变化后，FlowPay 向下单时的 notify_url 以表单 POST 发送 pid、trade_no、out_trade_no、type、name、money、trade_status、param、sign_type、sign（签名规则同上），商户应返回 2xx 且正文为空或 `success`，否则按退避策略重试。\n\n该接口接受任意 HTTP 方法；这里列出 GET（查询参数）和 POST（`application/x-www-form-urlencoded` 表单，不支持 multipart 与 JSON）。POST 时 URL 查询参数同样会被读取并参与签名。",
        "parameters": [
          {
            "name": "pid",
            "in": "query",
            "required": true,
            "description": "易支付商户 ID，在控制台为应用创建，形如 `fp_epay_...`。",
            "schema": {
              "type": "string",
              "examples": ["fp_epay_EXAMPLEexample000000"]
            }
          },
          {
            "name": "type",
            "in": "query",
            "required": true,
            "description": "支付方式，不区分大小写。`wxpay` 等为微信 Native；`alipay` 等为支付宝 H5；`alipay_page` 等为支付宝电脑网站。JSAPI（`wxpay_jsapi`、`wechat_jsapi`、`jsapi`）会被拒绝。",
            "schema": {
              "type": "string",
              "enum": [
                "wxpay",
                "wechat",
                "wechat_native",
                "native",
                "alipay",
                "alipay_h5",
                "alipay_wap",
                "wap",
                "alipay_pc",
                "alipay_page",
                "page"
              ]
            }
          },
          {
            "name": "out_trade_no",
            "in": "query",
            "required": false,
            "description": "商户订单号，1～32 位字母、数字、下划线或连字符；省略时使用 FlowPay 订单号。",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,32}$",
              "maxLength": 32,
              "examples": ["SHOP-20260925-0001"]
            }
          },
          {
            "name": "notify_url",
            "in": "query",
            "required": true,
            "description": "异步通知地址，必须是 HTTPS 且不含用户信息。",
            "schema": {
              "type": "string",
              "format": "uri",
              "examples": ["https://shop.example.com/epay/notify"]
            }
          },
          {
            "name": "return_url",
            "in": "query",
            "required": false,
            "description": "支付成功后浏览器返回地址，提供时必须是 HTTPS。",
            "schema": {
              "type": "string",
              "format": "uri",
              "examples": ["https://shop.example.com/epay/return"]
            }
          },
          {
            "name": "name",
            "in": "query",
            "required": true,
            "description": "商品名称。",
            "schema": {
              "type": "string",
              "minLength": 1,
              "examples": ["示例商品"]
            }
          },
          {
            "name": "money",
            "in": "query",
            "required": true,
            "description": "金额，单位元，最多两位小数，必须大于 0。",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]+(\\.[0-9]{1,2})?$",
              "examples": ["19.90"]
            }
          },
          {
            "name": "param",
            "in": "query",
            "required": false,
            "description": "业务扩展参数，会在异步通知中原样返回。",
            "schema": {
              "type": "string",
              "examples": ["custom-data"]
            }
          },
          {
            "name": "sign_type",
            "in": "query",
            "required": false,
            "description": "签名类型，只支持 MD5（不区分大小写），可省略。",
            "schema": {
              "type": "string",
              "enum": ["MD5"]
            }
          },
          {
            "name": "sign",
            "in": "query",
            "required": true,
            "description": "MD5 签名。",
            "schema": {
              "type": "string",
              "pattern": "^[0-9A-Fa-f]{32}$",
              "examples": ["0123456789abcdef0123456789abcdef"]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "下单成功。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpayCreateResponse"
                }
              }
            }
          },
          "400": {
            "description": "失败，HTTP 400，`code` 为 0。渠道或内部错误时 msg 为具体原因。\n\n常见 msg：\n- pid 是必填参数\n- 易支付凭据不存在或已停用\n- 易支付凭据不可读取\n- 易支付只支持 MD5 签名\n- 易支付请求签名校验失败\n- type 只支持 wxpay、alipay 或 alipay_page\n- 易支付 JSAPI 需要用户 openid，暂不接受公共协议下单\n- out_trade_no 必须是 1-32 位字母、数字、下划线或连字符\n- name 是必填参数\n- money 必须是大于 0 的两位小数金额\n- notify_url 是必填参数\n- notify_url 无效: ...\n- return_url 必须是有效的 HTTPS 地址\n- 易支付应用不存在或已停用\n- 订单创建正在处理中，请使用相同 out_trade_no 重试\n- out_trade_no 已被其他订单占用\n- 订单已过期或已进入终态，不能继续支付",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpayFailure"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "epayCreateV1Post",
        "summary": "易支付下单 /v1/epay 前缀（POST）",
        "tags": ["易支付兼容"],
        "security": [],
        "description": "与 `/mapi.php` 完全相同，供需要 `/v1` 前缀的网关转发使用。\n\n易支付兼容下单，返回 JSON。trade_no 为 FlowPay 订单号，out_trade_no 原样返回。\n\n签名规则（MD5）：取全部请求参数，去掉 `sign`、`sign_type` 和值为空的参数，按参数名 ASCII 升序排列，拼接成 `k1=v1&k2=v2` 形式（值不做 URL 编码），末尾直接拼接 PKey，计算 MD5，取 32 位十六进制（大小写均可）。兼容旧客户端在末尾拼接 `&key=PKey` 的变体。除下表外的其他非空参数也会参与签名。\n\n支付状态变化后，FlowPay 向下单时的 notify_url 以表单 POST 发送 pid、trade_no、out_trade_no、type、name、money、trade_status、param、sign_type、sign（签名规则同上），商户应返回 2xx 且正文为空或 `success`，否则按退避策略重试。\n\n该接口接受任意 HTTP 方法；这里列出 GET（查询参数）和 POST（`application/x-www-form-urlencoded` 表单，不支持 multipart 与 JSON）。POST 时 URL 查询参数同样会被读取并参与签名。",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/EpayCreateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "下单成功。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpayCreateResponse"
                }
              }
            }
          },
          "400": {
            "description": "失败，HTTP 400，`code` 为 0。渠道或内部错误时 msg 为具体原因。\n\n常见 msg：\n- pid 是必填参数\n- 易支付凭据不存在或已停用\n- 易支付凭据不可读取\n- 易支付只支持 MD5 签名\n- 易支付请求签名校验失败\n- type 只支持 wxpay、alipay 或 alipay_page\n- 易支付 JSAPI 需要用户 openid，暂不接受公共协议下单\n- out_trade_no 必须是 1-32 位字母、数字、下划线或连字符\n- name 是必填参数\n- money 必须是大于 0 的两位小数金额\n- notify_url 是必填参数\n- notify_url 无效: ...\n- return_url 必须是有效的 HTTPS 地址\n- 易支付应用不存在或已停用\n- 订单创建正在处理中，请使用相同 out_trade_no 重试\n- out_trade_no 已被其他订单占用\n- 订单已过期或已进入终态，不能继续支付",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpayFailure"
                }
              }
            }
          }
        }
      }
    },
    "/submit.php": {
      "get": {
        "operationId": "epaySubmitGet",
        "summary": "易支付跳转下单（GET）",
        "tags": ["易支付兼容"],
        "security": [],
        "description": "易支付兼容下单，适合浏览器表单直接提交：成功时 302 跳转到支付地址（同 mapi.php 的 payurl）。参数与签名同 mapi.php。\n\n签名规则（MD5）：取全部请求参数，去掉 `sign`、`sign_type` 和值为空的参数，按参数名 ASCII 升序排列，拼接成 `k1=v1&k2=v2` 形式（值不做 URL 编码），末尾直接拼接 PKey，计算 MD5，取 32 位十六进制（大小写均可）。兼容旧客户端在末尾拼接 `&key=PKey` 的变体。除下表外的其他非空参数也会参与签名。\n\n该接口接受任意 HTTP 方法；这里列出 GET（查询参数）和 POST（`application/x-www-form-urlencoded` 表单，不支持 multipart 与 JSON）。POST 时 URL 查询参数同样会被读取并参与签名。",
        "parameters": [
          {
            "name": "pid",
            "in": "query",
            "required": true,
            "description": "易支付商户 ID，在控制台为应用创建，形如 `fp_epay_...`。",
            "schema": {
              "type": "string",
              "examples": ["fp_epay_EXAMPLEexample000000"]
            }
          },
          {
            "name": "type",
            "in": "query",
            "required": true,
            "description": "支付方式，不区分大小写。`wxpay` 等为微信 Native；`alipay` 等为支付宝 H5；`alipay_page` 等为支付宝电脑网站。JSAPI（`wxpay_jsapi`、`wechat_jsapi`、`jsapi`）会被拒绝。",
            "schema": {
              "type": "string",
              "enum": [
                "wxpay",
                "wechat",
                "wechat_native",
                "native",
                "alipay",
                "alipay_h5",
                "alipay_wap",
                "wap",
                "alipay_pc",
                "alipay_page",
                "page"
              ]
            }
          },
          {
            "name": "out_trade_no",
            "in": "query",
            "required": false,
            "description": "商户订单号，1～32 位字母、数字、下划线或连字符；省略时使用 FlowPay 订单号。",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,32}$",
              "maxLength": 32,
              "examples": ["SHOP-20260925-0001"]
            }
          },
          {
            "name": "notify_url",
            "in": "query",
            "required": true,
            "description": "异步通知地址，必须是 HTTPS 且不含用户信息。",
            "schema": {
              "type": "string",
              "format": "uri",
              "examples": ["https://shop.example.com/epay/notify"]
            }
          },
          {
            "name": "return_url",
            "in": "query",
            "required": false,
            "description": "支付成功后浏览器返回地址，提供时必须是 HTTPS。",
            "schema": {
              "type": "string",
              "format": "uri",
              "examples": ["https://shop.example.com/epay/return"]
            }
          },
          {
            "name": "name",
            "in": "query",
            "required": true,
            "description": "商品名称。",
            "schema": {
              "type": "string",
              "minLength": 1,
              "examples": ["示例商品"]
            }
          },
          {
            "name": "money",
            "in": "query",
            "required": true,
            "description": "金额，单位元，最多两位小数，必须大于 0。",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]+(\\.[0-9]{1,2})?$",
              "examples": ["19.90"]
            }
          },
          {
            "name": "param",
            "in": "query",
            "required": false,
            "description": "业务扩展参数，会在异步通知中原样返回。",
            "schema": {
              "type": "string",
              "examples": ["custom-data"]
            }
          },
          {
            "name": "sign_type",
            "in": "query",
            "required": false,
            "description": "签名类型，只支持 MD5（不区分大小写），可省略。",
            "schema": {
              "type": "string",
              "enum": ["MD5"]
            }
          },
          {
            "name": "sign",
            "in": "query",
            "required": true,
            "description": "MD5 签名。",
            "schema": {
              "type": "string",
              "pattern": "^[0-9A-Fa-f]{32}$",
              "examples": ["0123456789abcdef0123456789abcdef"]
            }
          }
        ],
        "responses": {
          "302": {
            "description": "跳转到支付地址。",
            "headers": {
              "Location": {
                "description": "FlowPay 托管收银台或支付宝收银台地址。",
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "200": {
            "description": "没有可跳转的支付地址时返回 JSON。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpaySubmitFallbackResponse"
                }
              }
            }
          },
          "400": {
            "description": "失败，HTTP 400，`code` 为 0。渠道或内部错误时 msg 为具体原因。\n\n常见 msg：\n- pid 是必填参数\n- 易支付凭据不存在或已停用\n- 易支付凭据不可读取\n- 易支付只支持 MD5 签名\n- 易支付请求签名校验失败\n- type 只支持 wxpay、alipay 或 alipay_page\n- 易支付 JSAPI 需要用户 openid，暂不接受公共协议下单\n- out_trade_no 必须是 1-32 位字母、数字、下划线或连字符\n- name 是必填参数\n- money 必须是大于 0 的两位小数金额\n- notify_url 是必填参数\n- notify_url 无效: ...\n- return_url 必须是有效的 HTTPS 地址\n- 易支付应用不存在或已停用\n- 订单创建正在处理中，请使用相同 out_trade_no 重试\n- out_trade_no 已被其他订单占用\n- 订单已过期或已进入终态，不能继续支付",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpayFailure"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "epaySubmitPost",
        "summary": "易支付跳转下单（POST）",
        "tags": ["易支付兼容"],
        "security": [],
        "description": "易支付兼容下单，适合浏览器表单直接提交：成功时 302 跳转到支付地址（同 mapi.php 的 payurl）。参数与签名同 mapi.php。\n\n签名规则（MD5）：取全部请求参数，去掉 `sign`、`sign_type` 和值为空的参数，按参数名 ASCII 升序排列，拼接成 `k1=v1&k2=v2` 形式（值不做 URL 编码），末尾直接拼接 PKey，计算 MD5，取 32 位十六进制（大小写均可）。兼容旧客户端在末尾拼接 `&key=PKey` 的变体。除下表外的其他非空参数也会参与签名。\n\n该接口接受任意 HTTP 方法；这里列出 GET（查询参数）和 POST（`application/x-www-form-urlencoded` 表单，不支持 multipart 与 JSON）。POST 时 URL 查询参数同样会被读取并参与签名。",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/EpayCreateRequest"
              }
            }
          }
        },
        "responses": {
          "302": {
            "description": "跳转到支付地址。",
            "headers": {
              "Location": {
                "description": "FlowPay 托管收银台或支付宝收银台地址。",
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "200": {
            "description": "没有可跳转的支付地址时返回 JSON。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpaySubmitFallbackResponse"
                }
              }
            }
          },
          "400": {
            "description": "失败，HTTP 400，`code` 为 0。渠道或内部错误时 msg 为具体原因。\n\n常见 msg：\n- pid 是必填参数\n- 易支付凭据不存在或已停用\n- 易支付凭据不可读取\n- 易支付只支持 MD5 签名\n- 易支付请求签名校验失败\n- type 只支持 wxpay、alipay 或 alipay_page\n- 易支付 JSAPI 需要用户 openid，暂不接受公共协议下单\n- out_trade_no 必须是 1-32 位字母、数字、下划线或连字符\n- name 是必填参数\n- money 必须是大于 0 的两位小数金额\n- notify_url 是必填参数\n- notify_url 无效: ...\n- return_url 必须是有效的 HTTPS 地址\n- 易支付应用不存在或已停用\n- 订单创建正在处理中，请使用相同 out_trade_no 重试\n- out_trade_no 已被其他订单占用\n- 订单已过期或已进入终态，不能继续支付",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpayFailure"
                }
              }
            }
          }
        }
      }
    },
    "/v1/epay/submit.php": {
      "get": {
        "operationId": "epaySubmitV1Get",
        "summary": "易支付跳转下单 /v1/epay 前缀（GET）",
        "tags": ["易支付兼容"],
        "security": [],
        "description": "与 `/submit.php` 完全相同，供需要 `/v1` 前缀的网关转发使用。\n\n易支付兼容下单，适合浏览器表单直接提交：成功时 302 跳转到支付地址（同 mapi.php 的 payurl）。参数与签名同 mapi.php。\n\n签名规则（MD5）：取全部请求参数，去掉 `sign`、`sign_type` 和值为空的参数，按参数名 ASCII 升序排列，拼接成 `k1=v1&k2=v2` 形式（值不做 URL 编码），末尾直接拼接 PKey，计算 MD5，取 32 位十六进制（大小写均可）。兼容旧客户端在末尾拼接 `&key=PKey` 的变体。除下表外的其他非空参数也会参与签名。\n\n该接口接受任意 HTTP 方法；这里列出 GET（查询参数）和 POST（`application/x-www-form-urlencoded` 表单，不支持 multipart 与 JSON）。POST 时 URL 查询参数同样会被读取并参与签名。",
        "parameters": [
          {
            "name": "pid",
            "in": "query",
            "required": true,
            "description": "易支付商户 ID，在控制台为应用创建，形如 `fp_epay_...`。",
            "schema": {
              "type": "string",
              "examples": ["fp_epay_EXAMPLEexample000000"]
            }
          },
          {
            "name": "type",
            "in": "query",
            "required": true,
            "description": "支付方式，不区分大小写。`wxpay` 等为微信 Native；`alipay` 等为支付宝 H5；`alipay_page` 等为支付宝电脑网站。JSAPI（`wxpay_jsapi`、`wechat_jsapi`、`jsapi`）会被拒绝。",
            "schema": {
              "type": "string",
              "enum": [
                "wxpay",
                "wechat",
                "wechat_native",
                "native",
                "alipay",
                "alipay_h5",
                "alipay_wap",
                "wap",
                "alipay_pc",
                "alipay_page",
                "page"
              ]
            }
          },
          {
            "name": "out_trade_no",
            "in": "query",
            "required": false,
            "description": "商户订单号，1～32 位字母、数字、下划线或连字符；省略时使用 FlowPay 订单号。",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,32}$",
              "maxLength": 32,
              "examples": ["SHOP-20260925-0001"]
            }
          },
          {
            "name": "notify_url",
            "in": "query",
            "required": true,
            "description": "异步通知地址，必须是 HTTPS 且不含用户信息。",
            "schema": {
              "type": "string",
              "format": "uri",
              "examples": ["https://shop.example.com/epay/notify"]
            }
          },
          {
            "name": "return_url",
            "in": "query",
            "required": false,
            "description": "支付成功后浏览器返回地址，提供时必须是 HTTPS。",
            "schema": {
              "type": "string",
              "format": "uri",
              "examples": ["https://shop.example.com/epay/return"]
            }
          },
          {
            "name": "name",
            "in": "query",
            "required": true,
            "description": "商品名称。",
            "schema": {
              "type": "string",
              "minLength": 1,
              "examples": ["示例商品"]
            }
          },
          {
            "name": "money",
            "in": "query",
            "required": true,
            "description": "金额，单位元，最多两位小数，必须大于 0。",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]+(\\.[0-9]{1,2})?$",
              "examples": ["19.90"]
            }
          },
          {
            "name": "param",
            "in": "query",
            "required": false,
            "description": "业务扩展参数，会在异步通知中原样返回。",
            "schema": {
              "type": "string",
              "examples": ["custom-data"]
            }
          },
          {
            "name": "sign_type",
            "in": "query",
            "required": false,
            "description": "签名类型，只支持 MD5（不区分大小写），可省略。",
            "schema": {
              "type": "string",
              "enum": ["MD5"]
            }
          },
          {
            "name": "sign",
            "in": "query",
            "required": true,
            "description": "MD5 签名。",
            "schema": {
              "type": "string",
              "pattern": "^[0-9A-Fa-f]{32}$",
              "examples": ["0123456789abcdef0123456789abcdef"]
            }
          }
        ],
        "responses": {
          "302": {
            "description": "跳转到支付地址。",
            "headers": {
              "Location": {
                "description": "FlowPay 托管收银台或支付宝收银台地址。",
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "200": {
            "description": "没有可跳转的支付地址时返回 JSON。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpaySubmitFallbackResponse"
                }
              }
            }
          },
          "400": {
            "description": "失败，HTTP 400，`code` 为 0。渠道或内部错误时 msg 为具体原因。\n\n常见 msg：\n- pid 是必填参数\n- 易支付凭据不存在或已停用\n- 易支付凭据不可读取\n- 易支付只支持 MD5 签名\n- 易支付请求签名校验失败\n- type 只支持 wxpay、alipay 或 alipay_page\n- 易支付 JSAPI 需要用户 openid，暂不接受公共协议下单\n- out_trade_no 必须是 1-32 位字母、数字、下划线或连字符\n- name 是必填参数\n- money 必须是大于 0 的两位小数金额\n- notify_url 是必填参数\n- notify_url 无效: ...\n- return_url 必须是有效的 HTTPS 地址\n- 易支付应用不存在或已停用\n- 订单创建正在处理中，请使用相同 out_trade_no 重试\n- out_trade_no 已被其他订单占用\n- 订单已过期或已进入终态，不能继续支付",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpayFailure"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "epaySubmitV1Post",
        "summary": "易支付跳转下单 /v1/epay 前缀（POST）",
        "tags": ["易支付兼容"],
        "security": [],
        "description": "与 `/submit.php` 完全相同，供需要 `/v1` 前缀的网关转发使用。\n\n易支付兼容下单，适合浏览器表单直接提交：成功时 302 跳转到支付地址（同 mapi.php 的 payurl）。参数与签名同 mapi.php。\n\n签名规则（MD5）：取全部请求参数，去掉 `sign`、`sign_type` 和值为空的参数，按参数名 ASCII 升序排列，拼接成 `k1=v1&k2=v2` 形式（值不做 URL 编码），末尾直接拼接 PKey，计算 MD5，取 32 位十六进制（大小写均可）。兼容旧客户端在末尾拼接 `&key=PKey` 的变体。除下表外的其他非空参数也会参与签名。\n\n该接口接受任意 HTTP 方法；这里列出 GET（查询参数）和 POST（`application/x-www-form-urlencoded` 表单，不支持 multipart 与 JSON）。POST 时 URL 查询参数同样会被读取并参与签名。",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/EpayCreateRequest"
              }
            }
          }
        },
        "responses": {
          "302": {
            "description": "跳转到支付地址。",
            "headers": {
              "Location": {
                "description": "FlowPay 托管收银台或支付宝收银台地址。",
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "200": {
            "description": "没有可跳转的支付地址时返回 JSON。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpaySubmitFallbackResponse"
                }
              }
            }
          },
          "400": {
            "description": "失败，HTTP 400，`code` 为 0。渠道或内部错误时 msg 为具体原因。\n\n常见 msg：\n- pid 是必填参数\n- 易支付凭据不存在或已停用\n- 易支付凭据不可读取\n- 易支付只支持 MD5 签名\n- 易支付请求签名校验失败\n- type 只支持 wxpay、alipay 或 alipay_page\n- 易支付 JSAPI 需要用户 openid，暂不接受公共协议下单\n- out_trade_no 必须是 1-32 位字母、数字、下划线或连字符\n- name 是必填参数\n- money 必须是大于 0 的两位小数金额\n- notify_url 是必填参数\n- notify_url 无效: ...\n- return_url 必须是有效的 HTTPS 地址\n- 易支付应用不存在或已停用\n- 订单创建正在处理中，请使用相同 out_trade_no 重试\n- out_trade_no 已被其他订单占用\n- 订单已过期或已进入终态，不能继续支付",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpayFailure"
                }
              }
            }
          }
        }
      }
    },
    "/api.php": {
      "get": {
        "operationId": "epayApiGet",
        "summary": "易支付查单与关单（GET）",
        "tags": ["易支付兼容"],
        "security": [],
        "description": "易支付兼容查单（`act=order`，默认）和关单（`act=close`）。只能操作同一 PID 通过易支付接口创建的订单，原生 Bearer 接口创建的订单查不到。\n\n关单时 FlowPay 先向渠道查单，确认未支付后才关闭；若已支付，返回的 status 为 paid。\n\n鉴权：提供 `key`（PKey 明文）时只比对 key；否则按下单规则校验 `sign`。\n\n该接口接受任意 HTTP 方法；这里列出 GET（查询参数）和 POST（`application/x-www-form-urlencoded` 表单，不支持 multipart 与 JSON）。POST 时 URL 查询参数同样会被读取并参与签名。",
        "parameters": [
          {
            "name": "pid",
            "in": "query",
            "required": true,
            "description": "易支付商户 ID。",
            "schema": {
              "type": "string",
              "examples": ["fp_epay_EXAMPLEexample000000"]
            }
          },
          {
            "name": "act",
            "in": "query",
            "required": false,
            "description": "操作，不区分大小写：`order` 查单（默认），`close` 关单。",
            "schema": {
              "type": "string",
              "enum": ["order", "close"],
              "default": "order"
            }
          },
          {
            "name": "out_trade_no",
            "in": "query",
            "required": true,
            "description": "商户订单号。只能查询或关闭由同一 PID 通过易支付接口创建的订单。",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,32}$",
              "maxLength": 32,
              "examples": ["SHOP-20260925-0001"]
            }
          },
          {
            "name": "key",
            "in": "query",
            "required": false,
            "description": "PKey 明文。提供时只校验 key，不再校验 sign。",
            "schema": {
              "type": "string",
              "examples": ["EXAMPLE_pkey_do_not_use"]
            }
          },
          {
            "name": "sign",
            "in": "query",
            "required": false,
            "description": "未提供 key 时必填，规则同下单签名。",
            "schema": {
              "type": "string",
              "pattern": "^[0-9A-Fa-f]{32}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "成功。act=order 返回查单结果（值均为字符串）；act=close 返回关单结果。",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/EpayOrderQueryResponse"
                    },
                    {
                      "$ref": "#/components/schemas/EpayCloseResponse"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "失败，HTTP 400，`code` 为 0。\n\n常见 msg：\n- pid 是必填参数\n- 易支付凭据不存在或已停用\n- 易支付凭据不可读取\n- 易支付查询密钥校验失败\n- 易支付请求签名校验失败\n- api.php 只支持 act=order 或 act=close\n- out_trade_no 是必填参数\n- 订单不存在\n- 读取订单失败\n- 订单不属于当前易支付应用\n- 订单正在处理，请稍后重试\n- 关闭订单失败",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpayFailure"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "epayApiPost",
        "summary": "易支付查单与关单（POST）",
        "tags": ["易支付兼容"],
        "security": [],
        "description": "易支付兼容查单（`act=order`，默认）和关单（`act=close`）。只能操作同一 PID 通过易支付接口创建的订单，原生 Bearer 接口创建的订单查不到。\n\n关单时 FlowPay 先向渠道查单，确认未支付后才关闭；若已支付，返回的 status 为 paid。\n\n鉴权：提供 `key`（PKey 明文）时只比对 key；否则按下单规则校验 `sign`。\n\n该接口接受任意 HTTP 方法；这里列出 GET（查询参数）和 POST（`application/x-www-form-urlencoded` 表单，不支持 multipart 与 JSON）。POST 时 URL 查询参数同样会被读取并参与签名。",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/EpayApiRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "成功。act=order 返回查单结果（值均为字符串）；act=close 返回关单结果。",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/EpayOrderQueryResponse"
                    },
                    {
                      "$ref": "#/components/schemas/EpayCloseResponse"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "失败，HTTP 400，`code` 为 0。\n\n常见 msg：\n- pid 是必填参数\n- 易支付凭据不存在或已停用\n- 易支付凭据不可读取\n- 易支付查询密钥校验失败\n- 易支付请求签名校验失败\n- api.php 只支持 act=order 或 act=close\n- out_trade_no 是必填参数\n- 订单不存在\n- 读取订单失败\n- 订单不属于当前易支付应用\n- 订单正在处理，请稍后重试\n- 关闭订单失败",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpayFailure"
                }
              }
            }
          }
        }
      }
    },
    "/v1/epay/api.php": {
      "get": {
        "operationId": "epayApiV1Get",
        "summary": "易支付查单与关单 /v1/epay 前缀（GET）",
        "tags": ["易支付兼容"],
        "security": [],
        "description": "与 `/api.php` 完全相同，供需要 `/v1` 前缀的网关转发使用。\n\n易支付兼容查单（`act=order`，默认）和关单（`act=close`）。只能操作同一 PID 通过易支付接口创建的订单，原生 Bearer 接口创建的订单查不到。\n\n关单时 FlowPay 先向渠道查单，确认未支付后才关闭；若已支付，返回的 status 为 paid。\n\n鉴权：提供 `key`（PKey 明文）时只比对 key；否则按下单规则校验 `sign`。\n\n该接口接受任意 HTTP 方法；这里列出 GET（查询参数）和 POST（`application/x-www-form-urlencoded` 表单，不支持 multipart 与 JSON）。POST 时 URL 查询参数同样会被读取并参与签名。",
        "parameters": [
          {
            "name": "pid",
            "in": "query",
            "required": true,
            "description": "易支付商户 ID。",
            "schema": {
              "type": "string",
              "examples": ["fp_epay_EXAMPLEexample000000"]
            }
          },
          {
            "name": "act",
            "in": "query",
            "required": false,
            "description": "操作，不区分大小写：`order` 查单（默认），`close` 关单。",
            "schema": {
              "type": "string",
              "enum": ["order", "close"],
              "default": "order"
            }
          },
          {
            "name": "out_trade_no",
            "in": "query",
            "required": true,
            "description": "商户订单号。只能查询或关闭由同一 PID 通过易支付接口创建的订单。",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,32}$",
              "maxLength": 32,
              "examples": ["SHOP-20260925-0001"]
            }
          },
          {
            "name": "key",
            "in": "query",
            "required": false,
            "description": "PKey 明文。提供时只校验 key，不再校验 sign。",
            "schema": {
              "type": "string",
              "examples": ["EXAMPLE_pkey_do_not_use"]
            }
          },
          {
            "name": "sign",
            "in": "query",
            "required": false,
            "description": "未提供 key 时必填，规则同下单签名。",
            "schema": {
              "type": "string",
              "pattern": "^[0-9A-Fa-f]{32}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "成功。act=order 返回查单结果（值均为字符串）；act=close 返回关单结果。",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/EpayOrderQueryResponse"
                    },
                    {
                      "$ref": "#/components/schemas/EpayCloseResponse"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "失败，HTTP 400，`code` 为 0。\n\n常见 msg：\n- pid 是必填参数\n- 易支付凭据不存在或已停用\n- 易支付凭据不可读取\n- 易支付查询密钥校验失败\n- 易支付请求签名校验失败\n- api.php 只支持 act=order 或 act=close\n- out_trade_no 是必填参数\n- 订单不存在\n- 读取订单失败\n- 订单不属于当前易支付应用\n- 订单正在处理，请稍后重试\n- 关闭订单失败",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpayFailure"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "epayApiV1Post",
        "summary": "易支付查单与关单 /v1/epay 前缀（POST）",
        "tags": ["易支付兼容"],
        "security": [],
        "description": "与 `/api.php` 完全相同，供需要 `/v1` 前缀的网关转发使用。\n\n易支付兼容查单（`act=order`，默认）和关单（`act=close`）。只能操作同一 PID 通过易支付接口创建的订单，原生 Bearer 接口创建的订单查不到。\n\n关单时 FlowPay 先向渠道查单，确认未支付后才关闭；若已支付，返回的 status 为 paid。\n\n鉴权：提供 `key`（PKey 明文）时只比对 key；否则按下单规则校验 `sign`。\n\n该接口接受任意 HTTP 方法；这里列出 GET（查询参数）和 POST（`application/x-www-form-urlencoded` 表单，不支持 multipart 与 JSON）。POST 时 URL 查询参数同样会被读取并参与签名。",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/EpayApiRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "成功。act=order 返回查单结果（值均为字符串）；act=close 返回关单结果。",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/EpayOrderQueryResponse"
                    },
                    {
                      "$ref": "#/components/schemas/EpayCloseResponse"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "失败，HTTP 400，`code` 为 0。\n\n常见 msg：\n- pid 是必填参数\n- 易支付凭据不存在或已停用\n- 易支付凭据不可读取\n- 易支付查询密钥校验失败\n- 易支付请求签名校验失败\n- api.php 只支持 act=order 或 act=close\n- out_trade_no 是必填参数\n- 订单不存在\n- 读取订单失败\n- 订单不属于当前易支付应用\n- 订单正在处理，请稍后重试\n- 关闭订单失败",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EpayFailure"
                }
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {
    "payment.updated": {
      "post": {
        "operationId": "onPaymentUpdated",
        "summary": "订单状态变化回调",
        "tags": ["业务回调"],
        "description": "订单因渠道通知、关单或到期处理而改变状态时发送；状态没有变化时不发送。`status` 只会是 `paid`、`closed`、`failed` 之一：超时关闭为 `closed`，关闭后晚到的成功支付会补发 `paid`。全额退款不通过本事件通知，请看 `refund.updated` 或查单。`status` 反映这次渠道通知的结果，最终状态以查单为准；验签通过后无论 `status` 是什么值都请返回 2xx，否则 FlowPay 会持续重投。`event_id` 格式：微信通知为 `evt_{微信通知 ID}`，支付宝通知为 `evt_alipay_{支付宝 notify_id}`，关单与到期处理为 `evt_lifecycle_{订单内部 ID}_{status}`。\n\nFlowPay 向应用在控制台配置的 HTTPS 业务回调地址发送 `POST`，`Content-Type: application/json`。\n\n**签名**：`X-FlowPay-Signature` = `sha256=` + hex(HMAC-SHA256(回调密钥, `X-FlowPay-Timestamp` + `.` + 原始请求体))。请用收到的原始字节验签，不要重新序列化 JSON；建议用常量时间比较，并拒绝时间戳偏差过大的请求。每次投递（含重试）都会重新生成时间戳和签名，请求体保持不变。\n\n**应答与重试**：10 秒内返回 2xx 视为成功，响应体被忽略；其他状态码（包括 3xx，FlowPay 不跟随跳转）或超时视为失败。失败后依次在 1 分钟、5 分钟、30 分钟、2 小时后重试，之后每 24 小时一次，最多 8 次后标记为失败，运营人员可在控制台重新投递。同一 `event_id` 可能送达多次，请幂等处理。\n\n只有通过原生 Bearer 接口创建、且应用已配置回调地址与密钥的订单会收到该回调；易支付订单的通知发到下单时的 notify_url，使用易支付表单协议。",
        "security": [],
        "parameters": [
          {
            "name": "X-FlowPay-Event-ID",
            "in": "header",
            "required": true,
            "description": "事件 ID，与请求体 event_id 相同。",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-FlowPay-Event-Type",
            "in": "header",
            "required": true,
            "description": "事件类型，与请求体 event_type 相同。",
            "schema": {
              "type": "string",
              "const": "payment.updated"
            }
          },
          {
            "name": "X-FlowPay-Timestamp",
            "in": "header",
            "required": true,
            "description": "签名时间，Unix 秒级时间戳（十进制字符串）。",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]+$",
              "examples": ["1790000000"]
            }
          },
          {
            "name": "X-FlowPay-Signature",
            "in": "header",
            "required": true,
            "description": "`sha256=` 加 64 位小写十六进制 HMAC-SHA256 摘要。",
            "schema": {
              "type": "string",
              "pattern": "^sha256=[0-9a-f]{64}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PaymentUpdatedEvent"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "商户已接收。响应体被忽略。"
          },
          "default": {
            "description": "任何非 2xx 响应都视为投递失败，FlowPay 会按退避策略重试。"
          }
        }
      }
    },
    "refund.updated": {
      "post": {
        "operationId": "onRefundUpdated",
        "summary": "退款状态变化回调",
        "tags": ["业务回调"],
        "description": "退款状态发生变化（不含 created）时发送，来源包括提交渠道后的同步结果、渠道退款通知和后台对账。\n\nFlowPay 向应用在控制台配置的 HTTPS 业务回调地址发送 `POST`，`Content-Type: application/json`。\n\n**签名**：`X-FlowPay-Signature` = `sha256=` + hex(HMAC-SHA256(回调密钥, `X-FlowPay-Timestamp` + `.` + 原始请求体))。请用收到的原始字节验签，不要重新序列化 JSON；建议用常量时间比较，并拒绝时间戳偏差过大的请求。每次投递（含重试）都会重新生成时间戳和签名，请求体保持不变。\n\n**应答与重试**：10 秒内返回 2xx 视为成功，响应体被忽略；其他状态码（包括 3xx，FlowPay 不跟随跳转）或超时视为失败。失败后依次在 1 分钟、5 分钟、30 分钟、2 小时后重试，之后每 24 小时一次，最多 8 次后标记为失败，运营人员可在控制台重新投递。同一 `event_id` 可能送达多次，请幂等处理。\n\n只有通过原生 Bearer 接口创建、且应用已配置回调地址与密钥的订单会收到该回调；易支付订单的通知发到下单时的 notify_url，使用易支付表单协议。",
        "security": [],
        "parameters": [
          {
            "name": "X-FlowPay-Event-ID",
            "in": "header",
            "required": true,
            "description": "事件 ID，与请求体 event_id 相同。",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-FlowPay-Event-Type",
            "in": "header",
            "required": true,
            "description": "事件类型，与请求体 event_type 相同。",
            "schema": {
              "type": "string",
              "const": "refund.updated"
            }
          },
          {
            "name": "X-FlowPay-Timestamp",
            "in": "header",
            "required": true,
            "description": "签名时间，Unix 秒级时间戳（十进制字符串）。",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]+$",
              "examples": ["1790000000"]
            }
          },
          {
            "name": "X-FlowPay-Signature",
            "in": "header",
            "required": true,
            "description": "`sha256=` 加 64 位小写十六进制 HMAC-SHA256 摘要。",
            "schema": {
              "type": "string",
              "pattern": "^sha256=[0-9a-f]{64}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RefundUpdatedEvent"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "商户已接收。响应体被忽略。"
          },
          "default": {
            "description": "任何非 2xx 响应都视为投递失败，FlowPay 会按退避策略重试。"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "description": "原生接口统一错误结构。",
        "required": ["request_id", "error"],
        "properties": {
          "request_id": {
            "type": "string",
            "description": "与响应头 X-Request-ID 相同。",
            "examples": ["req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA"]
          },
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": {
                "type": "string",
                "description": "机器可读的错误码，见各接口说明。",
                "examples": ["ORDER_NOT_FOUND"]
              },
              "message": {
                "type": "string",
                "description": "英文错误说明，仅供排查，内容可能调整。",
                "examples": ["order not found"]
              }
            }
          }
        }
      },
      "ErrorWithOrder": {
        "description": "带订单快照的错误结构。仅在下单时订单已存在但不可再支付（`ORDER_NOT_PAYABLE`）时返回，可据 `order.status` 区分已支付和已关闭。",
        "allOf": [
          {
            "$ref": "#/components/schemas/Error"
          },
          {
            "type": "object",
            "required": ["order"],
            "properties": {
              "order": {
                "$ref": "#/components/schemas/Order"
              }
            }
          }
        ]
      },
      "OrderStatus": {
        "type": "string",
        "enum": ["created", "paid", "closed", "refunded", "failed"],
        "description": "订单状态，只会是以下五个值之一，不会返回 `expired`、`partially_refunded` 或其他值：\n\n- `created`：待支付。已过 `expires_at` 但后台还没完成关单时仍是这个值，不是终态。\n- `paid`：已支付。部分退款后仍是 `paid`，已退金额看 `refunded_amount_fen`。\n- `closed`：已关闭，未支付。超时关闭时 `close_source` 为 `system_expiry`。\n- `refunded`：已全额退款，即累计成功退款金额达到订单金额。\n- `failed`：下单阶段渠道明确失败（如微信 PAYERROR）。\n\n状态只按以下方向变化：`created` → `paid` / `closed` / `failed`；`closed` → `paid`（上游晚到一笔成功支付，FlowPay 会补发 `status: paid` 回调）；`failed` → `paid` / `closed`；`paid` → `refunded`；`refunded` 不再变化。"
      },
      "OrderChannel": {
        "type": "string",
        "enum": ["wechat_native", "wechat_jsapi", "alipay_h5", "alipay_page"],
        "description": "支付产品：微信 Native 扫码、微信 JSAPI、支付宝 H5（手机网站）、支付宝电脑网站。"
      },
      "RefundStatus": {
        "type": "string",
        "enum": [
          "created",
          "processing",
          "succeeded",
          "failed",
          "closed",
          "abnormal"
        ],
        "description": "退款状态：`created` 已受理、尚未提交渠道；`processing` 渠道处理中；`succeeded` 成功；`failed` 失败（支付宝 REFUND_FAIL）；`closed` 已关闭（微信 CLOSED，之后仍可能被渠道确认为成功）；`abnormal` 渠道返回异常或未知状态，额度保持冻结，由 FlowPay 后台继续查询收敛。"
      },
      "Order": {
        "type": "object",
        "description": "订单对象。查询订单和关闭订单直接返回该对象；创建订单把它放在 `order` 字段中。标注为可选的字段在为空时不出现。",
        "required": [
          "id",
          "merchant_id",
          "merchant_code",
          "application_id",
          "application_code",
          "channel_config_id",
          "order_no",
          "out_trade_no",
          "provider_out_trade_no",
          "channel",
          "amount_fen",
          "refunded_amount_fen",
          "description",
          "status",
          "expires_at",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "description": "FlowPay 内部订单 ID。"
          },
          "merchant_id": {
            "type": "integer",
            "format": "int64",
            "description": "商户 ID。"
          },
          "merchant_code": {
            "type": "string",
            "description": "商户编码。"
          },
          "application_id": {
            "type": "integer",
            "format": "int64",
            "description": "应用 ID。"
          },
          "application_code": {
            "type": "string",
            "description": "应用编码。"
          },
          "channel_config_id": {
            "type": "integer",
            "format": "int64",
            "description": "下单时使用的渠道配置 ID。"
          },
          "order_no": {
            "type": "string",
            "pattern": "^[0-9]{20}$",
            "description": "FlowPay 全局唯一订单号，20 位数字（14 位北京时间 YYYYMMDDHHMMSS + 6 位秒内序号）。发起退款时使用该值。"
          },
          "out_trade_no": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{1,32}$",
            "maxLength": 32,
            "description": "商户订单号，应用内唯一，也是下单幂等键。"
          },
          "provider_out_trade_no": {
            "type": "string",
            "description": "实际提交给微信或支付宝的请求单号，目前与 order_no 相同。"
          },
          "channel": {
            "$ref": "#/components/schemas/OrderChannel"
          },
          "amount_fen": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "订单金额，单位分。"
          },
          "refunded_amount_fen": {
            "type": "integer",
            "format": "int64",
            "minimum": 0,
            "description": "已成功退款的累计金额，单位分。"
          },
          "description": {
            "type": "string",
            "description": "商户提交的商品说明。"
          },
          "status": {
            "$ref": "#/components/schemas/OrderStatus"
          },
          "provider_transaction_id": {
            "type": "string",
            "description": "可选。渠道交易号（微信 transaction_id / 支付宝 trade_no）。"
          },
          "provider_trade_state": {
            "type": "string",
            "description": "可选。渠道原始交易状态，如微信 SUCCESS、NOTPAY，支付宝 TRADE_SUCCESS、TRADE_CLOSED。"
          },
          "provider_trade_state_desc": {
            "type": "string",
            "description": "可选。渠道交易状态描述。"
          },
          "provider_trade_type": {
            "type": "string",
            "description": "可选。渠道交易类型，如 NATIVE、JSAPI。"
          },
          "provider_bank_type": {
            "type": "string",
            "description": "可选。付款银行类型。"
          },
          "payer_total_fen": {
            "type": "integer",
            "format": "int64",
            "description": "可选。用户实际支付金额，单位分。"
          },
          "paid_at": {
            "type": "string",
            "format": "date-time",
            "description": "可选。支付完成时间。"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time",
            "description": "FlowPay 订单过期时间，由应用订单策略决定（新应用默认 30 分钟）。"
          },
          "close_source": {
            "type": "string",
            "enum": [
              "system_expiry",
              "operator",
              "merchant_request",
              "provider_notification",
              "provider_sync",
              "historical"
            ],
            "description": "可选。订单关闭来源：到期自动关闭、运营操作、商户请求、渠道通知、渠道同步、历史数据。"
          },
          "closed_at": {
            "type": "string",
            "format": "date-time",
            "description": "可选。关闭时间。"
          },
          "prepay": {
            "type": "object",
            "additionalProperties": true,
            "description": "可选。渠道预支付原始响应快照，键名已转为 snake_case，结构随渠道而定，不保证稳定。"
          },
          "provider_detail": {
            "type": "object",
            "additionalProperties": true,
            "description": "可选。最近一次渠道查询或通知的原始数据，键名已转为 snake_case，已移除所有 openid 字段，结构不保证稳定。"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "examples": [
          {
            "id": 10086,
            "merchant_id": 12,
            "merchant_code": "demo_merchant",
            "application_id": 34,
            "application_code": "demo_shop",
            "channel_config_id": 56,
            "order_no": "20260925120000000001",
            "out_trade_no": "SHOP-20260925-0001",
            "provider_out_trade_no": "20260925120000000001",
            "channel": "wechat_native",
            "amount_fen": 1990,
            "refunded_amount_fen": 0,
            "description": "示例商品",
            "status": "paid",
            "provider_transaction_id": "4200000000000000000000000000",
            "provider_trade_state": "SUCCESS",
            "provider_trade_state_desc": "支付成功",
            "provider_trade_type": "NATIVE",
            "provider_bank_type": "OTHERS",
            "payer_total_fen": 1990,
            "paid_at": "2026-09-25T04:01:12Z",
            "expires_at": "2026-09-25T04:30:00Z",
            "created_at": "2026-09-25T04:00:00Z",
            "updated_at": "2026-09-25T04:01:13Z"
          }
        ]
      },
      "CreateOrderRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": ["amount_fen", "description"],
        "properties": {
          "out_trade_no": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{1,32}$",
            "maxLength": 32,
            "description": "商户订单号，1～32 位字母、数字、下划线或连字符。同一次支付重试必须复用同一个值；省略时使用 FlowPay 生成的 order_no。"
          },
          "channel": {
            "type": "string",
            "enum": [
              "wechat_native",
              "wechat_jsapi",
              "alipay_h5",
              "alipay_page"
            ],
            "default": "wechat_native",
            "description": "支付产品，默认 `wechat_native`，不区分大小写。"
          },
          "provider_code": {
            "type": "string",
            "enum": ["official", "epay"],
            "default": "official",
            "description": "渠道提供方，不区分大小写，默认 `official`。`epay` 要求应用已配置易支付凭据，实际支付仍走应用已配置的官方微信/支付宝连接，且不校验 app_id 与 openid。"
          },
          "amount_fen": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "订单金额，单位分，必须大于 0。"
          },
          "description": {
            "type": "string",
            "minLength": 1,
            "description": "商品说明，不能为空。"
          },
          "openid": {
            "type": "string",
            "description": "付款用户在该公众号/小程序下的 openid。`channel=wechat_jsapi` 且 `provider_code=official` 时必填。"
          },
          "param": {
            "type": "string",
            "description": "接受但当前不使用、不保存的保留字段。"
          }
        },
        "examples": [
          {
            "out_trade_no": "SHOP-20260925-0001",
            "amount_fen": 1990,
            "description": "示例商品",
            "channel": "wechat_native"
          }
        ]
      },
      "WechatNativeClientParams": {
        "type": "object",
        "title": "微信 Native",
        "required": ["code_url"],
        "properties": {
          "code_url": {
            "type": "string",
            "description": "微信支付二维码内容，由商户自行生成二维码。",
            "examples": ["weixin://wxpay/bizpayurl?pr=EXAMPLE00"]
          }
        }
      },
      "WechatJsapiClientParams": {
        "type": "object",
        "title": "微信 JSAPI",
        "description": "可直接传给微信 JSAPI 调起支付的参数（字段名已转为 snake_case）。",
        "required": [
          "app_id",
          "time_stamp",
          "nonce_str",
          "package",
          "sign_type",
          "pay_sign"
        ],
        "properties": {
          "app_id": {
            "type": "string",
            "examples": ["wx0000000000example"]
          },
          "time_stamp": {
            "type": "string",
            "examples": ["1790000000"]
          },
          "nonce_str": {
            "type": "string",
            "examples": ["EXAMPLEnonce0000"]
          },
          "package": {
            "type": "string",
            "examples": ["prepay_id=wx000000000000example0000000000000000"]
          },
          "sign_type": {
            "type": "string",
            "examples": ["RSA"]
          },
          "pay_sign": {
            "type": "string",
            "examples": ["EXAMPLEsignature=="]
          }
        }
      },
      "AlipayH5ClientParams": {
        "type": "object",
        "title": "支付宝 H5",
        "required": ["payment_page_url", "alipay_qr_payload"],
        "properties": {
          "payment_page_url": {
            "type": "string",
            "format": "uri",
            "description": "FlowPay 订单中心地址，普通浏览器直接打开。",
            "examples": [
              "https://pay.flowpay.cn/pay/EXAMPLE_payment_session_token_0000000000"
            ]
          },
          "alipay_qr_payload": {
            "type": "string",
            "format": "uri",
            "description": "支付宝官方跳转辅助链接，用于生成给支付宝扫一扫的二维码。",
            "examples": [
              "https://render.alipay.com/p/s/i/?scheme=alipays%3A%2F%2Fplatformapi%2Fstartapp%3FappId%3D20000067%26url%3Dhttps%253A%252F%252Fpay.flowpay.cn%252Fpay%252FEXAMPLE_payment_session_token_0000000000"
            ]
          }
        }
      },
      "AlipayPageClientParams": {
        "type": "object",
        "title": "支付宝电脑网站",
        "required": ["payment_url", "payment_page_url"],
        "properties": {
          "payment_url": {
            "type": "string",
            "format": "uri",
            "description": "已签名的支付宝电脑网站收银台地址，浏览器跳转即可（支付宝页面内可登录或扫码）。",
            "examples": ["https://openapi.alipay.com/gateway.do?EXAMPLE=1"]
          },
          "payment_page_url": {
            "type": "string",
            "format": "uri",
            "description": "FlowPay 托管收银台地址。电脑上打开会显示嵌入的支付宝付款二维码、金额、倒计时和实时状态，手机上打开会引导付款人跳转支付宝收银台。",
            "examples": [
              "https://pay.flowpay.cn/pay/EXAMPLE_payment_session_token_0000000000"
            ]
          }
        }
      },
      "CreateOrderResponse": {
        "type": "object",
        "description": "创建订单响应。`client_params` 按渠道不同：wechat_native 为 WechatNativeClientParams，wechat_jsapi 为 WechatJsapiClientParams，alipay_h5 为 AlipayH5ClientParams，alipay_page 为 AlipayPageClientParams。\n\n使用相同 out_trade_no 重放已创建过预支付的订单时，响应只含 `order` 和 `prepay`；alipay_h5 订单会再次返回 `client_params`、`payment_page_url` 与 `alipay_qr_payload`；alipay_page 订单会再次返回 `client_params` 与 `payment_page_url`。",
        "required": ["order", "prepay"],
        "properties": {
          "order": {
            "$ref": "#/components/schemas/Order"
          },
          "prepay": {
            "type": "object",
            "additionalProperties": true,
            "description": "渠道预支付原始响应快照，与 order.prepay 相同。"
          },
          "client_params": {
            "description": "调起支付所需的参数。",
            "anyOf": [
              {
                "$ref": "#/components/schemas/WechatNativeClientParams"
              },
              {
                "$ref": "#/components/schemas/WechatJsapiClientParams"
              },
              {
                "$ref": "#/components/schemas/AlipayH5ClientParams"
              },
              {
                "$ref": "#/components/schemas/AlipayPageClientParams"
              }
            ]
          },
          "payment_page_url": {
            "type": "string",
            "format": "uri",
            "description": "alipay_h5 与 alipay_page：FlowPay 托管收银台地址。alipay_h5 为订单中心；alipay_page 为嵌入支付宝付款二维码的收银台。",
            "examples": [
              "https://pay.flowpay.cn/pay/EXAMPLE_payment_session_token_0000000000"
            ]
          },
          "alipay_qr_payload": {
            "type": "string",
            "format": "uri",
            "description": "仅 alipay_h5：支付宝扫一扫二维码内容。",
            "examples": [
              "https://render.alipay.com/p/s/i/?scheme=alipays%3A%2F%2Fplatformapi%2Fstartapp%3FappId%3D20000067%26url%3Dhttps%253A%252F%252Fpay.flowpay.cn%252Fpay%252FEXAMPLE_payment_session_token_0000000000"
            ]
          }
        }
      },
      "CreateRefundRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": ["order_no", "out_refund_no", "amount_fen"],
        "properties": {
          "order_no": {
            "type": "string",
            "pattern": "^[0-9]{20}$",
            "description": "原支付订单的 FlowPay 订单号（20 位数字），不是 out_trade_no。"
          },
          "out_refund_no": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{1,32}$",
            "maxLength": 32,
            "description": "商户退款单号，1～32 位字母、数字、下划线或连字符，应用内唯一，也是退款幂等键。"
          },
          "amount_fen": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "退款金额，单位分，不能超过剩余可退金额。"
          },
          "reason": {
            "type": "string",
            "description": "退款原因，首尾空白会被去除。幂等重放时必须与首次请求一致。"
          }
        },
        "examples": [
          {
            "order_no": "20260925120000000001",
            "out_refund_no": "SHOP-RF-0001",
            "amount_fen": 500,
            "reason": "用户申请退款"
          }
        ]
      },
      "Refund": {
        "type": "object",
        "description": "退款对象。标注为可选的字段在为空时不出现。",
        "required": [
          "refund_no",
          "out_refund_no",
          "order_no",
          "out_trade_no",
          "channel",
          "amount_fen",
          "status",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "refund_no": {
            "type": "string",
            "pattern": "^RF[0-9]{20}$",
            "description": "FlowPay 退款单号，`RF` + 20 位数字，也是提交给微信/支付宝的退款请求号。"
          },
          "out_refund_no": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{1,32}$",
            "maxLength": 32,
            "description": "商户退款单号。"
          },
          "order_no": {
            "type": "string",
            "pattern": "^[0-9]{20}$",
            "description": "原订单 FlowPay 订单号。"
          },
          "out_trade_no": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{1,32}$",
            "maxLength": 32,
            "description": "原订单商户订单号。"
          },
          "channel": {
            "$ref": "#/components/schemas/OrderChannel"
          },
          "amount_fen": {
            "type": "integer",
            "format": "int64",
            "description": "退款金额，单位分。"
          },
          "status": {
            "$ref": "#/components/schemas/RefundStatus"
          },
          "provider_refund_no": {
            "type": "string",
            "description": "可选。渠道退款单号。"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "succeeded_at": {
            "type": "string",
            "format": "date-time",
            "description": "可选。退款成功时间。"
          },
          "closed_at": {
            "type": "string",
            "format": "date-time",
            "description": "可选。退款失败或关闭的时间。"
          }
        },
        "examples": [
          {
            "refund_no": "RF20261002103000000001",
            "out_refund_no": "SHOP-RF-0001",
            "order_no": "20260925120000000001",
            "out_trade_no": "SHOP-20260925-0001",
            "channel": "wechat_native",
            "amount_fen": 500,
            "status": "processing",
            "provider_refund_no": "50300000000000000000000000000",
            "created_at": "2026-10-02T02:30:00Z",
            "updated_at": "2026-10-02T02:30:01Z"
          }
        ]
      },
      "RefundResponse": {
        "type": "object",
        "required": ["refund", "refundable_amount_fen"],
        "properties": {
          "refund": {
            "$ref": "#/components/schemas/Refund"
          },
          "refundable_amount_fen": {
            "type": "integer",
            "format": "int64",
            "minimum": 0,
            "description": "订单金额减去已成功退款金额，单位分。未扣除仍在处理中的退款，实际可再发起的金额可能更小。"
          }
        },
        "examples": [
          {
            "refund": {
              "refund_no": "RF20261002103000000001",
              "out_refund_no": "SHOP-RF-0001",
              "order_no": "20260925120000000001",
              "out_trade_no": "SHOP-20260925-0001",
              "channel": "wechat_native",
              "amount_fen": 500,
              "status": "processing",
              "provider_refund_no": "50300000000000000000000000000",
              "created_at": "2026-10-02T02:30:00Z",
              "updated_at": "2026-10-02T02:30:01Z"
            },
            "refundable_amount_fen": 1990
          }
        ]
      },
      "RefundListResponse": {
        "type": "object",
        "required": ["refunds", "total"],
        "properties": {
          "refunds": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/Refund"
            },
            "description": "按更新时间倒序，最多 100 条。"
          },
          "total": {
            "type": "integer",
            "description": "匹配的退款总数，可能大于 refunds 的条数。"
          }
        },
        "examples": [
          {
            "refunds": [
              {
                "refund_no": "RF20261002103000000001",
                "out_refund_no": "SHOP-RF-0001",
                "order_no": "20260925120000000001",
                "out_trade_no": "SHOP-20260925-0001",
                "channel": "wechat_native",
                "amount_fen": 500,
                "status": "processing",
                "provider_refund_no": "50300000000000000000000000000",
                "created_at": "2026-10-02T02:30:00Z",
                "updated_at": "2026-10-02T02:30:01Z"
              }
            ],
            "total": 1
          }
        ]
      },
      "HealthResponse": {
        "type": "object",
        "required": ["status"],
        "properties": {
          "status": {
            "type": "string",
            "enum": ["ok", "degraded"]
          },
          "wechat_ready": {
            "type": "boolean",
            "description": "仅 status=ok 时返回。"
          },
          "application_code": {
            "type": "string",
            "description": "仅 status=ok 时返回，FlowPay 服务自身的内部应用编码。"
          },
          "postgres": {
            "type": "string",
            "enum": ["unavailable"],
            "description": "仅数据库不可用时返回。"
          },
          "redis": {
            "type": "string",
            "enum": ["unavailable"],
            "description": "仅 Redis 不可用时返回。"
          }
        }
      },
      "EpayCreateRequest": {
        "type": "object",
        "required": ["pid", "type", "notify_url", "name", "money", "sign"],
        "properties": {
          "pid": {
            "type": "string",
            "examples": ["fp_epay_EXAMPLEexample000000"],
            "description": "易支付商户 ID，在控制台为应用创建，形如 `fp_epay_...`。"
          },
          "type": {
            "type": "string",
            "enum": [
              "wxpay",
              "wechat",
              "wechat_native",
              "native",
              "alipay",
              "alipay_h5",
              "alipay_wap",
              "wap",
              "alipay_pc",
              "alipay_page",
              "page"
            ],
            "description": "支付方式，不区分大小写。`wxpay` 等为微信 Native；`alipay` 等为支付宝 H5；`alipay_page` 等为支付宝电脑网站。JSAPI（`wxpay_jsapi`、`wechat_jsapi`、`jsapi`）会被拒绝。"
          },
          "out_trade_no": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{1,32}$",
            "maxLength": 32,
            "examples": ["SHOP-20260925-0001"],
            "description": "商户订单号，1～32 位字母、数字、下划线或连字符；省略时使用 FlowPay 订单号。"
          },
          "notify_url": {
            "type": "string",
            "format": "uri",
            "examples": ["https://shop.example.com/epay/notify"],
            "description": "异步通知地址，必须是 HTTPS 且不含用户信息。"
          },
          "return_url": {
            "type": "string",
            "format": "uri",
            "examples": ["https://shop.example.com/epay/return"],
            "description": "支付成功后浏览器返回地址，提供时必须是 HTTPS。"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "examples": ["示例商品"],
            "description": "商品名称。"
          },
          "money": {
            "type": "string",
            "pattern": "^[0-9]+(\\.[0-9]{1,2})?$",
            "examples": ["19.90"],
            "description": "金额，单位元，最多两位小数，必须大于 0。"
          },
          "param": {
            "type": "string",
            "examples": ["custom-data"],
            "description": "业务扩展参数，会在异步通知中原样返回。"
          },
          "sign_type": {
            "type": "string",
            "enum": ["MD5"],
            "description": "签名类型，只支持 MD5（不区分大小写），可省略。"
          },
          "sign": {
            "type": "string",
            "pattern": "^[0-9A-Fa-f]{32}$",
            "examples": ["0123456789abcdef0123456789abcdef"],
            "description": "MD5 签名。"
          }
        },
        "description": "签名规则（MD5）：取全部请求参数，去掉 `sign`、`sign_type` 和值为空的参数，按参数名 ASCII 升序排列，拼接成 `k1=v1&k2=v2` 形式（值不做 URL 编码），末尾直接拼接 PKey，计算 MD5，取 32 位十六进制（大小写均可）。兼容旧客户端在末尾拼接 `&key=PKey` 的变体。除下表外的其他非空参数也会参与签名。"
      },
      "EpayApiRequest": {
        "type": "object",
        "required": ["pid", "out_trade_no"],
        "properties": {
          "pid": {
            "type": "string",
            "examples": ["fp_epay_EXAMPLEexample000000"],
            "description": "易支付商户 ID。"
          },
          "act": {
            "type": "string",
            "enum": ["order", "close"],
            "default": "order",
            "description": "操作，不区分大小写：`order` 查单（默认），`close` 关单。"
          },
          "out_trade_no": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{1,32}$",
            "maxLength": 32,
            "examples": ["SHOP-20260925-0001"],
            "description": "商户订单号。只能查询或关闭由同一 PID 通过易支付接口创建的订单。"
          },
          "key": {
            "type": "string",
            "examples": ["EXAMPLE_pkey_do_not_use"],
            "description": "PKey 明文。提供时只校验 key，不再校验 sign。"
          },
          "sign": {
            "type": "string",
            "pattern": "^[0-9A-Fa-f]{32}$",
            "description": "未提供 key 时必填，规则同下单签名。"
          }
        },
        "description": "查单/关单参数。鉴权方式二选一：提供 `key`（PKey 明文），或按下单规则签名提供 `sign`。"
      },
      "EpayCreateResponse": {
        "type": "object",
        "required": [
          "code",
          "msg",
          "pid",
          "trade_no",
          "out_trade_no",
          "type",
          "name",
          "money",
          "trade_status",
          "qrcode",
          "payurl",
          "return_url"
        ],
        "properties": {
          "code": {
            "type": "integer",
            "const": 1
          },
          "msg": {
            "type": "string",
            "const": "success"
          },
          "pid": {
            "type": "string"
          },
          "trade_no": {
            "type": "string",
            "pattern": "^[0-9]{20}$",
            "description": "FlowPay 订单号。"
          },
          "out_trade_no": {
            "type": "string",
            "description": "商户订单号。"
          },
          "type": {
            "type": "string",
            "description": "原样返回请求中的 type。"
          },
          "name": {
            "type": "string"
          },
          "money": {
            "type": "string",
            "description": "两位小数金额，单位元。"
          },
          "trade_status": {
            "type": "string",
            "const": "WAIT_BUYER_PAY"
          },
          "qrcode": {
            "type": "string",
            "description": "微信 Native 为 code_url；支付宝 H5 为支付宝扫一扫跳转辅助链接；支付宝电脑网站没有原始二维码，为空字符串，请使用 payurl。"
          },
          "payurl": {
            "type": "string",
            "description": "浏览器支付地址，三种方式都是 FlowPay 托管收银台。支付宝电脑网站的收银台在电脑上嵌入支付宝付款二维码，在手机上引导跳转支付宝收银台。"
          },
          "return_url": {
            "type": "string",
            "description": "请求中的 return_url，未提供时为空字符串。"
          }
        },
        "examples": [
          {
            "code": 1,
            "msg": "success",
            "pid": "fp_epay_EXAMPLEexample000000",
            "trade_no": "20260925120000000001",
            "out_trade_no": "SHOP-20260925-0001",
            "type": "wxpay",
            "name": "示例商品",
            "money": "19.90",
            "trade_status": "WAIT_BUYER_PAY",
            "qrcode": "weixin://wxpay/bizpayurl?pr=EXAMPLE00",
            "payurl": "https://pay.flowpay.cn/pay/EXAMPLE_payment_session_token_0000000000",
            "return_url": "https://shop.example.com/epay/return"
          }
        ]
      },
      "EpaySubmitFallbackResponse": {
        "type": "object",
        "description": "没有可跳转的支付地址时返回。",
        "required": ["code", "msg", "qrcode", "trade_no"],
        "properties": {
          "code": {
            "type": "integer",
            "const": 1
          },
          "msg": {
            "type": "string",
            "const": "success"
          },
          "qrcode": {
            "type": "string"
          },
          "trade_no": {
            "type": "string",
            "pattern": "^[0-9]{20}$"
          }
        }
      },
      "EpayOrderQueryResponse": {
        "type": "object",
        "description": "查单结果。注意所有值都是字符串（包括 `code`）。响应带有 `sign`，规则同请求签名（不使用 `&key=` 变体）。\n\n状态映射：paid → `TRADE_SUCCESS` / `1`；closed、failed → `TRADE_CLOSED` / `-1`；其他（created、refunded）→ `WAIT_BUYER_PAY` / `0`。",
        "required": [
          "code",
          "msg",
          "pid",
          "trade_no",
          "out_trade_no",
          "type",
          "name",
          "money",
          "trade_status",
          "status",
          "sign_type",
          "sign"
        ],
        "properties": {
          "code": {
            "type": "string",
            "const": "1"
          },
          "msg": {
            "type": "string",
            "const": "success"
          },
          "pid": {
            "type": "string"
          },
          "trade_no": {
            "type": "string",
            "pattern": "^[0-9]{20}$",
            "description": "FlowPay 订单号。"
          },
          "out_trade_no": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "description": "下单时提交的 type。"
          },
          "name": {
            "type": "string"
          },
          "money": {
            "type": "string",
            "description": "两位小数金额，单位元。"
          },
          "trade_status": {
            "type": "string",
            "enum": ["TRADE_SUCCESS", "TRADE_CLOSED", "WAIT_BUYER_PAY"]
          },
          "status": {
            "type": "string",
            "enum": ["1", "0", "-1"]
          },
          "sign_type": {
            "type": "string",
            "const": "MD5"
          },
          "sign": {
            "type": "string"
          }
        },
        "examples": [
          {
            "code": "1",
            "msg": "success",
            "pid": "fp_epay_EXAMPLEexample000000",
            "trade_no": "20260925120000000001",
            "out_trade_no": "SHOP-20260925-0001",
            "type": "wxpay",
            "name": "示例商品",
            "money": "19.90",
            "trade_status": "TRADE_SUCCESS",
            "status": "1",
            "sign_type": "MD5",
            "sign": "0123456789abcdef0123456789abcdef"
          }
        ]
      },
      "EpayCloseResponse": {
        "type": "object",
        "description": "关单结果。订单已是终态时不报错，直接返回当前状态；若关单前已支付，status 为 paid，必须按已支付处理。",
        "required": ["code", "msg", "out_trade_no", "status", "trade_status"],
        "properties": {
          "code": {
            "type": "integer",
            "const": 1
          },
          "msg": {
            "type": "string",
            "const": "success"
          },
          "out_trade_no": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/OrderStatus"
          },
          "trade_status": {
            "type": "string",
            "enum": ["TRADE_SUCCESS", "TRADE_CLOSED", "WAIT_BUYER_PAY"]
          }
        },
        "examples": [
          {
            "code": 1,
            "msg": "success",
            "out_trade_no": "SHOP-20260925-0001",
            "status": "closed",
            "trade_status": "TRADE_CLOSED"
          }
        ]
      },
      "EpayFailure": {
        "type": "object",
        "description": "易支付接口统一失败结构，HTTP 状态码为 400，`msg` 为中文错误说明。",
        "required": ["code", "msg"],
        "properties": {
          "code": {
            "type": "integer",
            "const": 0
          },
          "msg": {
            "type": "string"
          }
        },
        "examples": [
          {
            "code": 0,
            "msg": "易支付请求签名校验失败"
          }
        ]
      },
      "PaymentUpdatedEvent": {
        "type": "object",
        "description": "订单状态变化事件。",
        "required": [
          "event_id",
          "event_type",
          "provider",
          "order_no",
          "out_trade_no",
          "amount_fen",
          "channel",
          "provider_state",
          "status",
          "occurred_at"
        ],
        "properties": {
          "event_id": {
            "type": "string",
            "description": "事件 ID，同一事件重试时不变，请据此幂等处理。"
          },
          "event_type": {
            "type": "string",
            "const": "payment.updated"
          },
          "provider": {
            "type": "string",
            "enum": ["wechat", "alipay"]
          },
          "order_no": {
            "type": "string",
            "pattern": "^[0-9]{20}$"
          },
          "out_trade_no": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{1,32}$",
            "maxLength": 32
          },
          "amount_fen": {
            "type": "integer",
            "format": "int64",
            "description": "订单金额，单位分。"
          },
          "channel": {
            "$ref": "#/components/schemas/OrderChannel"
          },
          "provider_state": {
            "type": "string",
            "description": "渠道原始交易状态，如 SUCCESS、CLOSED、TRADE_SUCCESS。"
          },
          "status": {
            "type": "string",
            "enum": ["paid", "closed", "failed"],
            "description": "这次变化后的订单状态。只有状态真正变化时才发送本事件，因此不会是 `created`；全额退款请看 `refund.updated`。"
          },
          "provider_transaction_id": {
            "type": "string",
            "description": "可选。渠道交易号，渠道已返回时才出现。"
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time",
            "description": "事件生成时间（UTC）。"
          }
        },
        "examples": [
          {
            "event_id": "evt_EXAMPLE-notify-id-0000",
            "event_type": "payment.updated",
            "provider": "wechat",
            "order_no": "20260925120000000001",
            "out_trade_no": "SHOP-20260925-0001",
            "amount_fen": 1990,
            "channel": "wechat_native",
            "provider_state": "SUCCESS",
            "status": "paid",
            "provider_transaction_id": "4200000000000000000000000000",
            "occurred_at": "2026-09-25T04:01:13.123456Z"
          }
        ]
      },
      "RefundUpdatedEvent": {
        "type": "object",
        "description": "退款状态变化事件。仅在退款状态实际变化且不为 created 时发送。",
        "required": [
          "event_id",
          "event_type",
          "provider",
          "refund_no",
          "out_refund_no",
          "order_no",
          "out_trade_no",
          "amount_fen",
          "channel",
          "provider_refund_no",
          "status"
        ],
        "properties": {
          "event_id": {
            "type": "string",
            "description": "事件 ID，格式 `evt_refund_{refund_no}_{status}`。"
          },
          "event_type": {
            "type": "string",
            "const": "refund.updated"
          },
          "provider": {
            "type": "string",
            "enum": ["wechat", "alipay"]
          },
          "refund_no": {
            "type": "string",
            "pattern": "^RF[0-9]{20}$"
          },
          "out_refund_no": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{1,32}$",
            "maxLength": 32
          },
          "order_no": {
            "type": "string",
            "pattern": "^[0-9]{20}$"
          },
          "out_trade_no": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{1,32}$",
            "maxLength": 32
          },
          "amount_fen": {
            "type": "integer",
            "format": "int64",
            "description": "退款金额，单位分。"
          },
          "channel": {
            "$ref": "#/components/schemas/OrderChannel"
          },
          "provider_refund_no": {
            "type": "string",
            "description": "渠道退款单号，可能为空字符串。"
          },
          "status": {
            "$ref": "#/components/schemas/RefundStatus"
          }
        },
        "examples": [
          {
            "event_id": "evt_refund_RF20261002103000000001_succeeded",
            "event_type": "refund.updated",
            "provider": "wechat",
            "refund_no": "RF20261002103000000001",
            "out_refund_no": "SHOP-RF-0001",
            "order_no": "20260925120000000001",
            "out_trade_no": "SHOP-20260925-0001",
            "amount_fen": 500,
            "channel": "wechat_native",
            "provider_refund_no": "50300000000000000000000000000",
            "status": "succeeded"
          }
        ]
      }
    },
    "securitySchemes": {
      "ApplicationCredential": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "fp_live_{prefix}.{secret}",
        "description": "应用凭据，在控制台为应用创建，完整值形如 `fp_live_<16 位前缀>.<密钥>`，以最后一个 `.` 分隔前缀与密钥。\n\n请求头必须严格为 `Authorization: Bearer <凭据>`（`Bearer` 区分大小写，后接一个空格）。凭据须处于启用状态，且所属应用与商户均为启用状态，否则返回 401 `INVALID_CREDENTIAL`。应用身份完全由凭据确定，请求体中不能再传 `application_code`。"
      }
    },
    "headers": {
      "X-Request-ID": {
        "description": "本次请求的唯一标识，以 `req_` 开头，与错误响应体中的 `request_id` 相同。",
        "schema": {
          "type": "string",
          "pattern": "^req_",
          "examples": ["req_Zm9vYmFyRXhhbXBsZVJlcXVlc3RJZDAwMDAwMDAwMDA"]
        }
      }
    }
  }
}
