交易结算#
验证通过后,提交链上结算。对齐 Coinbase V2 协议 + OKX 扩展字段 syncSettle。
请求地址#
POST /api/v6/pay/x402/settle
请求参数#
| 参数 | 类型 | 必传 | 描述 |
|---|---|---|---|
| x402Version | Integer | 是 | x402 协议版本,如 2 |
| paymentPayload | Object | 是 | 客户端携带的 x402 支付载荷,详见 PaymentPayload |
| paymentRequirements | Object | 是 | Seller 定义的支付要求,详见 PaymentRequirements |
| syncSettle | Boolean | 否 | OKX 扩展。true=同步等待链上确认后返回;false(默认)=异步,广播后立即返回。仅 exact scheme 有效 |
响应参数#
| 参数 | 类型 | 描述 |
|---|---|---|
| success | Boolean | 结算是否成功 |
| errorReason | String | 机器可读的失败原因(失败时返回) |
| errorMessage | String | 人类可读的失败说明(失败时返回) |
| payer | String | 付款方钱包地址 |
| transaction | String | 链上交易哈希(exact 成功时返回;deferred 为空串) |
| network | String | CAIP-2 链标识,如 eip155:196 |
| status | String | OKX 扩展。结算状态,取值见下方状态表 |
status 取值#
| scheme | syncSettle | 结果 | status 值 | transaction |
|---|---|---|---|---|
| exact | false(默认) | 已广播 | pending | txHash |
| exact | true | 链上确认成功 | success | txHash |
| exact | true | 等待超时 | timeout | txHash |
| aggr_deferred | — | 已入库 | success | 空串 |
请求示例#
Bash
curl --location --request POST 'https://web3.okx.com/api/v6/pay/x402/settle' \
--header 'Content-Type: application/json' \
--header 'OK-ACCESS-KEY: 37c541a1-****-****-****-10fe7a038418' \
--header 'OK-ACCESS-SIGN: leaV********3uw=' \
--header 'OK-ACCESS-PASSPHRASE: 1****6' \
--header 'OK-ACCESS-TIMESTAMP: 2023-10-18T12:21:41.274Z' \
--data '{
"x402Version": 2,
"paymentPayload": {
"x402Version": 2,
"resource": {
"url": "https://api.example.com/premium-data",
"description": "Access to premium data",
"mimeType": "application/json"
},
"accepted": {
"scheme": "exact",
"network": "eip155:196",
"amount": "10000",
"asset": "0x4ae46a509f6b1d9056937ba4500cb143933d2dc8",
"payTo": "0xRecipientAddress",
"maxTimeoutSeconds": 60,
"extra": { "name": "USDG", "version": "2" }
},
"payload": {
"signature": "0xf3746613c2d920b5fdabc0856f2aeb2d4f88ee6037b8cc5d04a71a4462f13480...",
"authorization": {
"from": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
"to": "0xRecipientAddress",
"value": "10000",
"validAfter": "0",
"validBefore": "1740672154",
"nonce": "0xf374661..."
}
}
},
"paymentRequirements": {
"scheme": "exact",
"network": "eip155:196",
"amount": "10000",
"asset": "0x4ae46a509f6b1d9056937ba4500cb143933d2dc8",
"payTo": "0xRecipientAddress",
"maxTimeoutSeconds": 60,
"extra": { "name": "USDG", "version": "2" }
},
"syncSettle": true
}'
响应示例 - 同步结算(syncSettle=true)#
Json
{
"code": "0",
"msg": "success",
"data": {
"success": true,
"errorReason": null,
"errorMessage": null,
"payer": "0xcb30ed083ad246b126a3aa1f414b44346e83e67d",
"transaction": "0x4f46ed8eac92ddbccfb56a88ff827db3616c7beb191adabbeeded901340bd7d5",
"network": "eip155:196",
"status": "success"
}
}
响应示例 - 异步结算(syncSettle=false)#
Json
{
"code": "0",
"msg": "success",
"data": {
"success": true,
"errorReason": null,
"errorMessage": null,
"payer": "0xcb30ed083ad246b126a3aa1f414b44346e83e67d",
"transaction": "0x4f46ed8eac92ddbccfb56a88ff827db3616c7beb191adabbeeded901340bd7d5",
"network": "eip155:196",
"status": "pending"
}
}
响应示例 - 结算失败#
Json
{
"code": "0",
"msg": "success",
"data": {
"success": false,
"errorReason": "insufficient_funds",
"errorMessage": "Transaction reverted",
"payer": "0xcb30ed083ad246b126a3aa1f414b44346e83e67d",
"transaction": "",
"network": "eip155:196",
"status": ""
}
}