Create a refund
curl --request POST \
--url https://merchant-api-prod.anyway.sh/v1/refunds \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--header 'X-API-Key: <api-key>' \
--data '
{
"orderId": "<string>",
"amountCents": 123
}
'import requests
url = "https://merchant-api-prod.anyway.sh/v1/refunds"
payload = {
"orderId": "<string>",
"amountCents": 123
}
headers = {
"Idempotency-Key": "<idempotency-key>",
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
'X-API-Key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({orderId: '<string>', amountCents: 123})
};
fetch('https://merchant-api-prod.anyway.sh/v1/refunds', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://merchant-api-prod.anyway.sh/v1/refunds",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'orderId' => '<string>',
'amountCents' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://merchant-api-prod.anyway.sh/v1/refunds"
payload := strings.NewReader("{\n \"orderId\": \"<string>\",\n \"amountCents\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://merchant-api-prod.anyway.sh/v1/refunds")
.header("Idempotency-Key", "<idempotency-key>")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"orderId\": \"<string>\",\n \"amountCents\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://merchant-api-prod.anyway.sh/v1/refunds")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"orderId\": \"<string>\",\n \"amountCents\": 123\n}"
response = http.request(request)
puts response.read_body{
"data": {
"amountCents": 123,
"createdAt": "<string>",
"currency": "<string>",
"failedAt": "<string>",
"failureReason": "<string>",
"fullyRefunded": true,
"orderId": "<string>",
"orgId": "<string>",
"reason": "<string>",
"refundId": "<string>",
"refundedAt": "<string>",
"status": "<string>",
"totalRefundedCents": 123
},
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": {
"amountCents": 123,
"createdAt": "<string>",
"currency": "<string>",
"failedAt": "<string>",
"failureReason": "<string>",
"fullyRefunded": true,
"orderId": "<string>",
"orgId": "<string>",
"reason": "<string>",
"refundId": "<string>",
"refundedAt": "<string>",
"status": "<string>",
"totalRefundedCents": 123
},
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}Merchant API 端点
创建退款
对银行卡订单全额或部分退款。
POST
/
v1
/
refunds
Create a refund
curl --request POST \
--url https://merchant-api-prod.anyway.sh/v1/refunds \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--header 'X-API-Key: <api-key>' \
--data '
{
"orderId": "<string>",
"amountCents": 123
}
'import requests
url = "https://merchant-api-prod.anyway.sh/v1/refunds"
payload = {
"orderId": "<string>",
"amountCents": 123
}
headers = {
"Idempotency-Key": "<idempotency-key>",
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
'X-API-Key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({orderId: '<string>', amountCents: 123})
};
fetch('https://merchant-api-prod.anyway.sh/v1/refunds', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://merchant-api-prod.anyway.sh/v1/refunds",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'orderId' => '<string>',
'amountCents' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://merchant-api-prod.anyway.sh/v1/refunds"
payload := strings.NewReader("{\n \"orderId\": \"<string>\",\n \"amountCents\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://merchant-api-prod.anyway.sh/v1/refunds")
.header("Idempotency-Key", "<idempotency-key>")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"orderId\": \"<string>\",\n \"amountCents\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://merchant-api-prod.anyway.sh/v1/refunds")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"orderId\": \"<string>\",\n \"amountCents\": 123\n}"
response = http.request(request)
puts response.read_body{
"data": {
"amountCents": 123,
"createdAt": "<string>",
"currency": "<string>",
"failedAt": "<string>",
"failureReason": "<string>",
"fullyRefunded": true,
"orderId": "<string>",
"orgId": "<string>",
"reason": "<string>",
"refundId": "<string>",
"refundedAt": "<string>",
"status": "<string>",
"totalRefundedCents": 123
},
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": {
"amountCents": 123,
"createdAt": "<string>",
"currency": "<string>",
"failedAt": "<string>",
"failureReason": "<string>",
"fullyRefunded": true,
"orderId": "<string>",
"orgId": "<string>",
"reason": "<string>",
"refundId": "<string>",
"refundedAt": "<string>",
"status": "<string>",
"totalRefundedCents": 123
},
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}请使用属于目标组织、且为全部权限或勾选了
sales:refunds:execute 权限的 API 密钥进行认证。只有 Owner、Admin 和 Finance 角色可以授予该权限。
- 仅在 Anyway 为你的组织开通 API 退款后可用,请联系 Anyway 支持开通。开通前,无论使用哪种密钥,对你的订单发起的退款都返回
403REFUND_API_NOT_ENABLED。订单本身的错误(如订单不存在时的404)会先返回。 - 输入与控制台订单上的退款按钮相同。省略
amountCents即退还订单剩余可退的全部金额。reason可选:duplicate、fraudulent或requested_by_customer。币种始终为订单币种。 - 请发送唯一的
Idempotency-Key请求头(必填;1–200 个 ASCII 字符,范围0x21到0x7E,不含空格)。相同密钥和相同请求体返回同一笔退款,不会重复退款。相同密钥搭配不同的订单、金额或原因返回409。 - 仅支持 90 天内的银行卡订单。更早的订单请联系 Anyway 支持。
200且status为succeeded表示退款已完成。202且status为pending表示退款在等待 Anyway 审核或卡组织处理。当这笔退款使订单累计退款金额达到审核阈值或以上,或使你的组织超出每日退款限额(与控制台退款共用)时,需要审核;同一订单同一时间只能有一笔退款在等待审核。请使用相同的Idempotency-Key重试以获取最新状态,或等待refund.succeeded或refund.failedWebhook。- 响应与查看退款返回的退款对象相同。通过 API 发起的退款也会显示在控制台的订单上。
| 状态码 | 错误码 | 含义 |
|---|---|---|
400 | BAD_REQUEST | 缺少或无效的 Idempotency-Key、未知字段、金额小于等于 0,或 reason 无效。 |
400 | REFUND_AMOUNT_TOO_LARGE | amountCents 超过订单剩余可退金额。 |
400 | REFUND_NOT_REFUNDABLE | 省略了 amountCents,且订单已没有可退金额。 |
400 | REFUND_UNSUPPORTED_METHOD | 订单不是银行卡支付。 |
400 | REFUND_WINDOW_EXPIRED | 订单已超过 90 天。 |
400 | amount_too_large、charge_already_refunded 或 charge_disputed | 发卡网络拒绝:金额超过剩余可退金额、已全额退款或存在争议。 |
401 | API 密钥缺失或无效。 | |
403 | INSUFFICIENT_SCOPE | 密钥缺少 sales:refunds:execute。 |
403 | REFUND_API_NOT_ENABLED | 你的组织未开通 API 退款。请联系 Anyway 支持。 |
404 | 订单 ID 不存在,或属于其他组织。 | |
409 | REFUND_PENDING_EXISTS | 该订单上另一笔退款正在等待审核。 |
409 | REFUND_IDEMPOTENCY_MISMATCH | 该 Idempotency-Key 已用于不同的订单、金额或原因。 |
409 | REFUND_FAILED 或 REFUND_REJECTED | 该 Idempotency-Key 对应的退款已失败或被拒绝。请使用新的密钥重试。 |
503 | REFUND_UNAVAILABLE | 支付服务商繁忙或不可用,或这笔退款仍在处理中。请使用相同的 Idempotency-Key 重试。 |
请求头
请求体
application/json
Order and amount