文档中心 > 当面付-英文版

alipay.trade.cancel

更新时间:2017/01/09 访问次数:4852

Use case:
When the payment does not return a determinative result (such as system error or network exception), the merchant can call this API to cancel the payment.
As the result, if the payment is not complete yet, Alipay will close this transaction; if the payment is complete, Alipay will refund the user.
The cancel API can only be applied to the transactions paid within 24 hours. If it is over 24 hours, please use the refund API. If there is a need for the payment status, the query API call could be used.

Remarks:
Please use the “cancel” API only in the cases of system time-out or unknown payment status. For other scenarios, please use the “refund” API.
For best practice, please call “query” API after the “pay” API. If there is no clear payment result, then we could call “cancel” API.

Common Parameters

Parameter Type Mandatory Length Description Sample
app_id String Y 32 An app id assigned to the developer by Alipay 2014072300007148
method String Y 128 api name Alipay.data.dataservice.bill.downloadurl.query
charset String Y 10 The char set for request use, like utf-8, gbk, gb2312, etc. utf-8
sign_type String Y 10 The type of signature algorithm used by the merchant to generate the signature string. Currently RSA and RSA2 are supported. RSA2
sign String Y 256 Signature string
timestamp String Y 19 The sending time of the request, formatting in “yyyy-MM-dd HH:mm:ss” 2014-07-24 03:07:50
version String Y 3 The version of this API, hard coded as 1.0 for now. 1.0
app_auth_token String N 40 Please refer to the section “application authorization”

Request Parameters

Parameter Type Mandatory Length Description Sample
out_trade_no String Y 64 out_trade_no passed in by the merchant in the request 20150320010101001

Sample:

method=alipay.trade.cancel,
app_id=2014072300007148,
charset=utf-8,
sign_type=RSA2,
sign=MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAL4HgSt9hfOpv9MSwgUvfpgOH7WkC7WrTr84m29b0VfnZtK+9jv/YPXYr+22DrxfWJkdPiXJvSjifxPudlqjX21l6/8k79i/4HRCz8DBcdw5jqROfpoq0l3vYfPVqJGwSqaPhtM1Bb4hAD2yLlN2ukfCbshSntUEFd4ozocLolW/AgMBAAECgYBVHTNj8WMQElYTCnHQtMc1AA5/4yxDgKlSyN4F8NBBWSoa9uF/WhFpzFZwWH0dLm+WlRyC/Gs3ZsuYd9SXIFna9mv49+cEfObSzJhvW5DXOVCi+c4Ap3cTsXZiAj8DMsoCb9OjRHNl/BqzN0kl0Wm1diZvXl9YgSRqbzpXzoj4oQJBAOYLSk87XFYodvwr4aL3KFjZZZhHj1Jpp/q61SNgB03aXqZu9m+hk1X4mTGn4rhA7Cl2ZuL+OoxxnJFDw0cbMRcCQQDTeGgx0VUC+O3zAtzMmocjE7WuesRC3IjhU30of4GGjQzIXvKOQCCuUF2DHvIkrB/k2E75n8+TI9matbLS11mZAkEAtSek7/oF/89Dy9dei2/o9PbVu3J22eZcIuVoHMBtYBCbwqLVLBloJiZrtR/JOWHe19Pmt9COGLULH5XmPKOcJwJAUZnP0xFs1XXLFA/Rtd4XMXDklYxn+UjyRMibrintiEcbXKJOxJd4ROtb+kHRvFbzA7J4XxjM14Fo8asVcwiIWQJAVco+9qQzZ7JZzFzk0KTWhQlfbcRByLX25XIPbIes2lmY2uM895yrY/8kbGx2JgD/VGITWwth+uuutXUQ9K6HIw==,
timestamp=2014-07-24 03:07:50,
biz_content = {
"out_trade_no": "201503022001"
}

Response Parameters in Synchronous Return

The Result of “Success” Return

Parameter Type Mandatory Length Description Sample
out_trade_no String Y 64 out_trade_no passed in by the merchant in the request. 6823789339978248
retry_flag String Y 1 The flag to decide if we need to retry. N
trade_no String N 64 Alipay Transaction ID. 2013112011001004330000121536
action String N 10 The processing result of the request.

close:Trade closed and no refund
refund:Refund
close

Sample:

{
"alipay_trade_cancel_response": {
"code": "10000",
"msg": "处理成功",
"trade_no": "2013112011001004330000121536",
"out_trade_no": "6823789339978248",
"retry_flag": "N",
"action": "close"
},
"sign": "jfAz0Yi0OUvAPqYTzA0DLysx0ri++yf7o/lkHOHaG1Zy2fHBf3j4WM+sJWHZUuyInt6V+wn+6IP9AmwRTKi+GGdWjPrsfBjXqR7H5aBnLhMsAltV7v4cYjhuguAqh4WkaJO6v6CfdybDpzHlxE6Thoucnad+OsjdCXkNd1g3UuU="
}

The Result of “Failed” Return

Parameter Type Mandatory Length Description Sample
retry_flag String N 1 The flag indicating if retry is allowed

Y:the requestor could retry;
N:could not retry,all new retries will not succeed
N

Sample:

{
"alipay_trade_cancel_response": {
"code": "40004",
"msg": "处理失败",
"sub_code": "ACQ.INVALID_PARAMETER",
"sub_msg": "参数无效",
"retry_flag": "N"
},
"sign": "jfAz0Yi0OUvAPqYTzA0DLysx0ri++yf7o/lkHOHaG1Zy2fHBf3j4WM+sJWHZUuyInt6V+wn+6IP9AmwRTKi+GGdWjPrsfBjXqR7H5aBnLhMsAltV7v4cYjhuguAqh4WkaJO6v6CfdybDpzHlxE6Thoucnad+OsjdCXkNd1g3UuU="
}

Error Codes

Name Description Solution
AQC.SYSTEM_ERROR System error, such as system time out Call the inquiry API ASAP, and proceed accordingly with the order’s status.
ACQ.INVALID_PARAMETER At least one of the parameters is not valid. Examine the request parameters and resend the request after fixing the issue.
ACQ.SELLER_BALANCE_NOT_ENOUGH Seller does not have enough balance to complete the refund. The seller could add fund to the account and refund again.
ACQ.REASON_TRADE_BEEN_FREEZEN The payment is restricted and could not be cancelled. Please contact Alipay CS to get the transaction status.

FAQ

关于此文档暂时还没有FAQ
返回
顶部