refund

Use the refund API to initiate a synchronous or asynchronous refund for a successful payment. 

Structure

A message consists of a header and body. The following sections are focused on the body structure. For the header structure, see: 


Note: Set the data type of each field (except array) as String. This means that you must use double quotation marks (" ") to enclose the field value. Examples:

  • If the data type of a field is Integer and its value is 20, set it as "20". 
  • If the data type of a field is Boolean and its value is true, set it as "true". 

Request parameters

refundRequestId String  REQUIRED

The unique ID assigned by the merchant to identify a refund request.

More information about this field:

  • This field is an API idempotency field. Merchant uses the refundRequestId field for idempotency control. For payment requests that are initiated with the same value of refundRequestId and reach a final status (S or F), the same result is to be returned for the request.
  • Maximum length: 64 characters

paymentId String  REQUIRED

The unique ID assigned by Alipay for the original payment to be refunded.

More information about this field:

  • Maximum length: 64 characters

referenceRefundId String  

The unique ID to identify a refund, which is assigned by the merchant that directly provides services or goods to the customer.

More information about this field:

  • Maximum length: 64 characters

refundAmount Amount object REQUIRED

The refund amount that is initiated by the merchant.

Child parameters

refundReason String  

The refund reasons

More information about this field:

  • Maximum length: 256 characters

Response parameters

result Result object REQUIRED

The request result contains information such as status and error codes.

Child parameters

refundRequestId String  

The unique ID that is assigned by the merchant to identify a refund request.

More information about this field:

  • Maximum length: 64 characters

refundId String  

The unique ID that is assigned by Alipay to identify a refund. A one-to-one correspondence between refundId and refundRequestId exists. 

More information about this field:

  • Maximum length: 64 characters

paymentId String  

The unique ID assigned by Alipay for the original payment to be refunded.

More information about this field:

  • Maximum length: 64 characters

refundAmount Amount object 

The refund amount collected by the payment executor for this refund.

Child parameters

refundTime Datetime  

The date and time when the refund reaches a final state of success or failure.

More information about this field:

  • The value follows the ISO 8601 standard format. For example, "2019-11-27T12:01:01+08:30".

grossSettlementAmount Amount object 

The total settlement amount, which equals to the transaction amount multiplied by the value of settlementQuote.

Note: This field is empty when the settlement currency is the same as the transaction currency.

Child parameters

settlementQuote Quote object 

The exchange rate between the settlement currency and transaction currency at the time of transaction, which is provided only in the locked-in rate case. 

Note: This field is empty when the settlement currency is the same as the transaction currency.

Child parameters
API Explorer

Request

Method
POST
Endpoint
/v1/payments/refund
Header
Accept: application/json
URL
https://<domain_name>/ams/api/<endpoint>
Domain name
North America: https://open-na.alipay.com
Asia: https://open-sea.alipay.com
Europe: https://open-eu.alipay.com
Request Body

Response

Case
Response Body

More information 

This section gives additional information about the key parameter. See the following list for details:

  • refundRequestId:
    The refund can be full or partial. A transaction can have multiple refunds as long as the total refund amount is less than or equal to the original transaction amount. If being out of the refund window, the refund request will be declined. Use the same refundRequestId to retry a refund in case of timeout or when the returned resultStatus is U.
  • refundId:
    The parameter can be used for the refund inquiry.  

Result process logic

For different request results, different actions are to be performed. See the following list for details:

  • If the value of result.resultStatus is S, for synchronous refund, the refund succeeds. For an asynchronous refund the refund request is processed successfully, and merchant can call inquiryPayment interface to query the refund result.
  • If the value of result.resultStatus is F, the refund fails. Usually, the failure is caused by a refund initiated outside the refund window (result. resultCode= FREFUND_WINDOW_EXCEED). If the refund is still needed to be processed, manual intervention is needed.
  • If the value of result.resultStatus is U, the result is unknown. Processing failure might occur due to system or network issues. Merchant can retry with the same refundRequestId.

Error codes

Error codes are usually classified into the following categories:

  • Common error codes: common for all online and in-store payment APIs.
  • API-specific error codes: listed in the following table.  

Result/Error codes

CodeValueMessageFurther action
SUCCESSSSuccess

The refund is successful, no further action is needed.

REFUND_WINDOW_EXCEEDFThe refund date exceeds the refundable period that is agreed in the contract.

Confirm whether the refund date exceeds the refundable period.

REFUND_AMOUNT_EXCEEDFThe total refund amount exceeds the payment amount.

Confirm whether the total refund amount exceeds the payment amount.

ORDER_NOT_EXISTFThe order does not exist.

Check whether paymentId is correct.

ORDER_STATUS_INVALIDFThe order status is invalid.

Check the order status.

MERCHANT_BALANCE_NOT_ENOUGHFThe merchant balance is not enough.

Call the interface again after the merchant has sufficient balance. The refundRequestId field needs to be changed when you try again.

CURRENCY_NOT_SUPPORT FThe currency is not supported.

Use the currency that is agreed in the contract.

REPEAT_REQ_INCONSISTENTFRepeated requests are inconsistent.

Use a unique refundRequestId to initiate the payment again.

CLIENT_INVALIDFThe client is invalid.

Check whether the clientId is correct.

METHOD_NOT_SUPPORTEDFThe server does not implement the requested HTTP method.

Check whether the HTTP method is correct.

MEDIA_TYPE_NOT_ACCEPTABLEFThe server does not implement the media type that is acceptable to the client.

Check whether the media type is correct.

MULTIPLE_REFUNDS_NOT_SUPPORTEDFMultiple refunds are not supported.

Check whether multiple refunds exist.