支付
取消支付
在待处理的支付完成前将其取消,并将其状态更新为已取消。
POST
/
payments
/
{payment_id}
/
transactions
/
{transaction_id}
/
cancel
取消支付
curl --request POST \
--url https://api-sandbox.y.uno/v1/payments/{payment_id}/transactions/{transaction_id}/cancel \
--header 'Content-Type: application/json' \
--header 'X-Idempotency-Key: <api-key>' \
--header 'private-secret-key: <api-key>' \
--header 'public-api-key: <api-key>' \
--data '
{
"description": "Duplicate",
"reason": "REQUESTED_BY_CUSTOMER",
"merchant_reference": "AAB01-432245"
}
'import requests
url = "https://api-sandbox.y.uno/v1/payments/{payment_id}/transactions/{transaction_id}/cancel"
payload = {
"description": "Duplicate",
"reason": "REQUESTED_BY_CUSTOMER",
"merchant_reference": "AAB01-432245"
}
headers = {
"public-api-key": "<api-key>",
"private-secret-key": "<api-key>",
"X-Idempotency-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'public-api-key': '<api-key>',
'private-secret-key': '<api-key>',
'X-Idempotency-Key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
description: 'Duplicate',
reason: 'REQUESTED_BY_CUSTOMER',
merchant_reference: 'AAB01-432245'
})
};
fetch('https://api-sandbox.y.uno/v1/payments/{payment_id}/transactions/{transaction_id}/cancel', 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://api-sandbox.y.uno/v1/payments/{payment_id}/transactions/{transaction_id}/cancel",
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([
'description' => 'Duplicate',
'reason' => 'REQUESTED_BY_CUSTOMER',
'merchant_reference' => 'AAB01-432245'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Idempotency-Key: <api-key>",
"private-secret-key: <api-key>",
"public-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://api-sandbox.y.uno/v1/payments/{payment_id}/transactions/{transaction_id}/cancel"
payload := strings.NewReader("{\n \"description\": \"Duplicate\",\n \"reason\": \"REQUESTED_BY_CUSTOMER\",\n \"merchant_reference\": \"AAB01-432245\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("public-api-key", "<api-key>")
req.Header.Add("private-secret-key", "<api-key>")
req.Header.Add("X-Idempotency-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://api-sandbox.y.uno/v1/payments/{payment_id}/transactions/{transaction_id}/cancel")
.header("public-api-key", "<api-key>")
.header("private-secret-key", "<api-key>")
.header("X-Idempotency-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"description\": \"Duplicate\",\n \"reason\": \"REQUESTED_BY_CUSTOMER\",\n \"merchant_reference\": \"AAB01-432245\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-sandbox.y.uno/v1/payments/{payment_id}/transactions/{transaction_id}/cancel")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["public-api-key"] = '<api-key>'
request["private-secret-key"] = '<api-key>'
request["X-Idempotency-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"description\": \"Duplicate\",\n \"reason\": \"REQUESTED_BY_CUSTOMER\",\n \"merchant_reference\": \"AAB01-432245\"\n}"
response = http.request(request)
puts response.read_body{
"id": "438bea6c-9061-4416-b824-469c3c05868d",
"type": "CANCEL",
"status": "SUCCEEDED",
"category": "CARD",
"amount": {
"captured": 0,
"currency": "USD",
"currency_conversion": null,
"refunded": 0,
"value": 30000
},
"merchant_reference": "",
"created_at": "2024-06-06T14:03:08.384014Z",
"updated_at": "2024-06-06T14:03:08.453617Z",
"provider_data": {
"id": "YUNO_TEST_PAYMENT_GW",
"transaction_id": "",
"account_id": "",
"status": "SUCCEEDED",
"sub_status": "",
"status_detail": "SUCCEEDED",
"response_message": null,
"response_code": "SUCCEEDED",
"raw_response": {
"message": "provider response"
},
"third_party_transaction_id": null,
"third_party_account_id": null,
"iso8583_response_code": "00",
"iso8583_response_message": "Approved or completed successfully"
},
"connection_data": {
"id": "58cc35f4-faef-4107-8e09-d18d60121d38",
"name": "Connection name"
},
"response_code": "SUCCEEDED",
"response_message": "Transaction successful",
"payment": {
"id": "2d6f75c1-c4bc-4d2d-80ec-0af4d12c85da",
"account_id": "",
"description": "Test",
"country": "US",
"status": "CANCELED",
"sub_status": "CANCELED",
"merchant_order_id": "0000023",
"created_at": "2024-06-06T14:01:34.286228Z",
"updated_at": "2024-06-06T14:03:08.484781Z",
"amount": {
"captured": 0,
"authorized": 30000,
"currency": "USD",
"currency_conversion": null,
"refunded": 0,
"value": 30000
},
"split_marketplace": []
},
"customer_payer": null,
"simplified_mode": false,
"receipt": false,
"receipt_url": null,
"receipt_language": null
}{
"code": "INVALID_REQUEST",
"messages": [
"Invalid request"
]
}{
"code": "INVALID_CREDENTIALS",
"messages": [
"Invalid credentials"
]
}{
"code": "AUTHORIZATION_REQUIRED",
"messages": [
"The merchant has no authorization to use this API."
]
}由于 AUTHORIZE 交易状态而处于 PENDING 状态的支付,如果不再需要,可以在完成前取消。发送取消请求会将支付状态更新为 CANCELLED。
如果您需要已取消交易的收据,可以在收据生成后进行检索。为此,请使用按 ID 检索支付 endpoint,并查看
3DS 支付由于 3DS 身份验证而处于 PENDING 状态的支付无法取消。这些支付处于等待用户身份验证的临时状态。支付状态将根据身份验证结果自动更新为 FRAUD VERIFIED 或 CANCELLED。
替代支付方式PIX 等替代支付方式也支持取消处于 PENDING 状态的支付。如需了解更多信息,请联系您的技术客户经理。
payment.transaction 对象中的 receipt_url 字段。有关 receipt、receipt_url 和 receipt_language,请参阅支付对象。
要使用此 endpoint,您必须在请求中提供 X-Idempotency-Key。如需了解更多信息,请查看身份验证页面。授权
请求体
application/json
响应
201
此页面对您有帮助吗?
⌘I
取消支付
curl --request POST \
--url https://api-sandbox.y.uno/v1/payments/{payment_id}/transactions/{transaction_id}/cancel \
--header 'Content-Type: application/json' \
--header 'X-Idempotency-Key: <api-key>' \
--header 'private-secret-key: <api-key>' \
--header 'public-api-key: <api-key>' \
--data '
{
"description": "Duplicate",
"reason": "REQUESTED_BY_CUSTOMER",
"merchant_reference": "AAB01-432245"
}
'import requests
url = "https://api-sandbox.y.uno/v1/payments/{payment_id}/transactions/{transaction_id}/cancel"
payload = {
"description": "Duplicate",
"reason": "REQUESTED_BY_CUSTOMER",
"merchant_reference": "AAB01-432245"
}
headers = {
"public-api-key": "<api-key>",
"private-secret-key": "<api-key>",
"X-Idempotency-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'public-api-key': '<api-key>',
'private-secret-key': '<api-key>',
'X-Idempotency-Key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
description: 'Duplicate',
reason: 'REQUESTED_BY_CUSTOMER',
merchant_reference: 'AAB01-432245'
})
};
fetch('https://api-sandbox.y.uno/v1/payments/{payment_id}/transactions/{transaction_id}/cancel', 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://api-sandbox.y.uno/v1/payments/{payment_id}/transactions/{transaction_id}/cancel",
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([
'description' => 'Duplicate',
'reason' => 'REQUESTED_BY_CUSTOMER',
'merchant_reference' => 'AAB01-432245'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Idempotency-Key: <api-key>",
"private-secret-key: <api-key>",
"public-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://api-sandbox.y.uno/v1/payments/{payment_id}/transactions/{transaction_id}/cancel"
payload := strings.NewReader("{\n \"description\": \"Duplicate\",\n \"reason\": \"REQUESTED_BY_CUSTOMER\",\n \"merchant_reference\": \"AAB01-432245\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("public-api-key", "<api-key>")
req.Header.Add("private-secret-key", "<api-key>")
req.Header.Add("X-Idempotency-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://api-sandbox.y.uno/v1/payments/{payment_id}/transactions/{transaction_id}/cancel")
.header("public-api-key", "<api-key>")
.header("private-secret-key", "<api-key>")
.header("X-Idempotency-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"description\": \"Duplicate\",\n \"reason\": \"REQUESTED_BY_CUSTOMER\",\n \"merchant_reference\": \"AAB01-432245\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-sandbox.y.uno/v1/payments/{payment_id}/transactions/{transaction_id}/cancel")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["public-api-key"] = '<api-key>'
request["private-secret-key"] = '<api-key>'
request["X-Idempotency-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"description\": \"Duplicate\",\n \"reason\": \"REQUESTED_BY_CUSTOMER\",\n \"merchant_reference\": \"AAB01-432245\"\n}"
response = http.request(request)
puts response.read_body{
"id": "438bea6c-9061-4416-b824-469c3c05868d",
"type": "CANCEL",
"status": "SUCCEEDED",
"category": "CARD",
"amount": {
"captured": 0,
"currency": "USD",
"currency_conversion": null,
"refunded": 0,
"value": 30000
},
"merchant_reference": "",
"created_at": "2024-06-06T14:03:08.384014Z",
"updated_at": "2024-06-06T14:03:08.453617Z",
"provider_data": {
"id": "YUNO_TEST_PAYMENT_GW",
"transaction_id": "",
"account_id": "",
"status": "SUCCEEDED",
"sub_status": "",
"status_detail": "SUCCEEDED",
"response_message": null,
"response_code": "SUCCEEDED",
"raw_response": {
"message": "provider response"
},
"third_party_transaction_id": null,
"third_party_account_id": null,
"iso8583_response_code": "00",
"iso8583_response_message": "Approved or completed successfully"
},
"connection_data": {
"id": "58cc35f4-faef-4107-8e09-d18d60121d38",
"name": "Connection name"
},
"response_code": "SUCCEEDED",
"response_message": "Transaction successful",
"payment": {
"id": "2d6f75c1-c4bc-4d2d-80ec-0af4d12c85da",
"account_id": "",
"description": "Test",
"country": "US",
"status": "CANCELED",
"sub_status": "CANCELED",
"merchant_order_id": "0000023",
"created_at": "2024-06-06T14:01:34.286228Z",
"updated_at": "2024-06-06T14:03:08.484781Z",
"amount": {
"captured": 0,
"authorized": 30000,
"currency": "USD",
"currency_conversion": null,
"refunded": 0,
"value": 30000
},
"split_marketplace": []
},
"customer_payer": null,
"simplified_mode": false,
"receipt": false,
"receipt_url": null,
"receipt_language": null
}{
"code": "INVALID_REQUEST",
"messages": [
"Invalid request"
]
}{
"code": "INVALID_CREDENTIALS",
"messages": [
"Invalid credentials"
]
}{
"code": "AUTHORIZATION_REQUIRED",
"messages": [
"The merchant has no authorization to use this API."
]
}