Skip to content

发起退款

请求方式和路径

POST /payin/v1/createRefund

请求头

字段名类型必传描述
content-typestringapplication/json
x-api-keystringPaydify提供,跟appId相同
x-api-timestampstring时间戳,单位毫秒
x-api-signaturestring签名,具体参看签名算法

请求体

字段名类型必传描述
mchTxnIdstring(60)商户侧订单ID
paymentTxnIdstring(30)支付订单ID
typestring退款责任方:
- MERCHANT: 商户负责退款(链上退款),需要提供 txnHash
- PLATFORM: 平台负责退款(API/托管钱包),需要提供 refundAmount
refundAmountstring(32)条件退款金额(USDT)
- PLATFORM 类型:必填
- MERCHANT 类型:不需要
txnHashstring(120)条件链上退款交易的 Hash
- PLATFORM 类型:不需要
- MERCHANT 类型:必填
mchExtInfostring(512)商户扩展信息,JSON字符串

响应头参数

字段名类型必传描述
x-api-keystringPaydify提供,跟appId相同
x-api-timestampstring时间戳,单位毫秒
x-api-signaturestring签名,具体参看签名算法

返回值

字段名类型描述
codestring响应码,SYS_SUCCESS表示成功
messagestring响应消息
messageDetailstring响应消息详情
successboolean是否成功
data.refundTxnIdstringPaydify侧的退款订单ID
data.paymentTxnIdstring关联的支付订单ID
data.statestring退款状态,枚举值参看退款状态
data.errorMsgstring退款失败原因说明

示例

平台退款示例(Gate.io等托管模式)

json
// 请求体
{
  "mchTxnId": "merchant_refund_123456",
  "paymentTxnId": "P2209141130105863014",
  "type": "PLATFORM",
  "refundAmount": "100.50",
  "mchExtInfo": "{\"reason\": \"customer request\"}"
}
// 请求体
{
  "mchTxnId": "merchant_refund_123456",
  "paymentTxnId": "P2209141130105863014",
  "type": "PLATFORM",
  "refundAmount": "100.50",
  "mchExtInfo": "{\"reason\": \"customer request\"}"
}

商户退款示例(链上退款)

json
// 请求体
{
  "mchTxnId": "merchant_refund_789012",
  "paymentTxnId": "P2209141130105863015",
  "type": "MERCHANT",
  "txnHash": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
  "mchExtInfo": "{\"reason\": \"customer request\"}"
}
// 请求体
{
  "mchTxnId": "merchant_refund_789012",
  "paymentTxnId": "P2209141130105863015",
  "type": "MERCHANT",
  "txnHash": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
  "mchExtInfo": "{\"reason\": \"customer request\"}"
}

成功返回值

json
{
  "code": "SYS_SUCCESS",
  "message": null,
  "messageDetail": null,
  "data": {
    "refundTxnId": "R2209141130105863014",
    "paymentTxnId": "P2209141130105863014",
    "state": "pending",
    "errorMsg": null
  },
  "success": true
}
{
  "code": "SYS_SUCCESS",
  "message": null,
  "messageDetail": null,
  "data": {
    "refundTxnId": "R2209141130105863014",
    "paymentTxnId": "P2209141130105863014",
    "state": "pending",
    "errorMsg": null
  },
  "success": true
}

失败返回值

json
{
  "code": "SYS_ERROR",
  "message": "Refund responsibility 'MERCHANT' does not match payment custody type 'CUSTODIAL'",
  "messageDetail": "Please use responsibility 'PLATFORM' for custodial payments like Gate.io",
  "data": null,
  "success": false
}
{
  "code": "SYS_ERROR",
  "message": "Refund responsibility 'MERCHANT' does not match payment custody type 'CUSTODIAL'",
  "messageDetail": "Please use responsibility 'PLATFORM' for custodial payments like Gate.io",
  "data": null,
  "success": false
}

注意事项

  1. type 参数必须与原支付订单的资金托管类型一致

    • 如果是托管模式支付(如 Gate.io),必须使用 type=PLATFORM(平台负责退款)
    • 如果是非托管模式支付(如 BGW、三方钱包),必须使用 type=MERCHANT(商户负责退款)
  2. 参数依赖关系

    • PLATFORM 类型:必须提供 refundAmount,不需要 txnHash
    • MERCHANT 类型:必须提供 txnHash
  3. 退款处理流程

    • PLATFORM 类型:调用渠道 API 进行退款
    • MERCHANT 类型:验证商户提供的链上退款交易后标记为退款成功
  4. 幂等性

    • 相同的 mchTxnId 只能发起一次退款
    • 建议使用包含时间戳的唯一标识作为 mchTxnId