# refund

> Use this API to initiate a refund against a successful payment. 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 the refund request is out of the refund window determined in the contract, the refund request will be declined.

`POST /v1/payments/refund`

Use this API to initiate a refund against a successful payment. 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 the refund request is out of the refund window determined in the contract, the refund request will be declined.

> **Note**: Use the same _refundRequestId_ field to retry a refund in case of timeout or when the returned _resultStatus_ is `U`. The _refundRequestId_ field is designed to be idempotent. 

# Structure

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

-   [Request header](https://docs.antom.com/ac/ams/api_fund.md#ML5ur)
-   [Response header](https://docs.antom.com/ac/ams/api_fund.md#WWH90)

> **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:

- This field is an API idempotency field.The 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 Antom for the original payment to be refunded.

More information:

- 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.

> Note: Specify this field if this value is needed for internal use or reconciliation.

More information:

- Maximum length: 64 characters

#### refundAmount (Amount, REQUIRED)

The refund amount that is initiated by the merchant.

##### currency (String, REQUIRED)

The currency used for the corresponding payment of the refund. The value is a 3-letter currency code that follows the [ISO 4217](https://www.iso.org/iso-4217-currency-codes.html) standard.

More information:

- Maximum length: 3 characters

##### value (Integer, REQUIRED)

The value of the amount as a positive integer in the smallest currency unit. For example, if the currency is USD and the amount is $1.00, set the value of this parameter to `100`; or if the currency is JPY and the amount is ￥1, set the value of this parameter to `1`.  

For details about the smallest currency unit, see [Smallest unit of the currency](https://docs.antom.com/ac/ref/cc.md#ONkIe) .

For details about the minimum payment amount allowed for each payment method, see [Minimum amount rules](https://docs.antom.com/ac/ref/cc.md#q9R5A).

> Note: Due to the currency practices in Indonesia, when the currency is IDR, round the amount with banker's rounding and fix the last two digits of this parameter as `00.`

More information:

- Value range: 1 - unlimited

#### refundReason (String)

The refund reason.

> Note: Specify this field if you want to provide the refund reason to the user and payment method.

More information:

- Maximum length: 256 characters

#### refundNotifyUrl (String)

The URL that is used to receive the refund result notification. The URL must be either specified in the request or set in Antom Dashboard.

> Note: Specify this field if you want to receive an asynchronous notification of the refund result. If the refund notification URL is specified in both the request and Antom Dashboard, the value specified in the request takes precedence.

More information:

- Maximum length: 1024 characters

#### metadata (String)

This parameter is used for submitting metadata, including information for special use cases.

> Specify this parameter when you need to add metadata information.

More information:

- Maximum length: 2048 characters

#### actualRefundAmount (Amount)

The refund amount in processing currency, that is, the amount the user actually paid.

> **Note:** This parameter is required when all of the following conditions are met:
>
> -   The presentation currency differs from the processing currency.;
> -   The merchant is aware of the exchange rate;
> -   The refund amount is calculated in the processing currency.

##### currency (String, REQUIRED)

A 3-letter currency code that follows the [ISO 4217](https://www.iso.org/iso-4217-currency-codes.html) standard.

More information:

- Maximum length: 3 characters

##### value (Integer, REQUIRED)

A positive integer in the smallest currency unit.

> **Note**: For details about the smallest currency unit, see [Smallest unit of the currency](https://docs.antom.com/ac/ref/cc.md#ONkIe).

More information:

- Value range: 1 - unlimited

## Response parameters

#### result (Result, REQUIRED)

Indicates whether this API is called successfully. If this API is successfully called, the refund succeeds.

##### resultCode (String, REQUIRED)

Result code. Possible values are listed in the Result/Error codes table on this page.

More information:

- Maximum length: 64 characters

##### resultStatus (String, REQUIRED)

Result status. Valid values are:

-   `S`: Indicates that the refund succeeded.
-   `F`: Indicates that the refund failed.
-   `U`: Indicates that the refund result is unknown.

##### resultMessage (String, REQUIRED)

Result message that explains the result code.

More information:

- Maximum length: 256 characters

#### refundRequestId (String)

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

Note: This field is returned when the refund succeeds (the value of _result.resultStatus_ is `S`).

More information:

- Maximum length: 64 characters

#### refundId (String)

The unique ID that is assigned by Antom to identify a refund. A one-to-one correspondence between _refundId_ and _refundRequestId_ exists.

> Note: This field is returned when the refund succeeds (the value of _result.resultStatus_ is `S`).

More information:

- Maximum length: 64 characters

#### paymentId (String)

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

> Note: This field is returned when the refund succeeds (the value of _result.resultStatus_ is `S`).

More information:

- Maximum length: 64 characters

#### acquirerReferenceNo (String)

The unique ID assigned by the non-Antom acquirer for the transaction.

More information:

- Maximum length: 64 characters

#### refundAmount (Amount)

The refund amount collected by the payer for this refund.

> Note: This field is returned when the refund succeeds (the value of _result.resultStatus_ is `S`).

##### currency (String, REQUIRED)

The transaction currency that is specified in the contract. The value is a 3-letter currency code that follows the [ISO 4217](https://www.iso.org/iso-4217-currency-codes.html) standard.

More information:

- Maximum length: 3 characters

##### value (Integer, REQUIRED)

The amount to charge as a positive integer in the smallest currency unit. (That is, 100 cents to charge $1.00, or 100 to charge JPY ¥100, a 0-decimal currency).

> Note: For details about the smallest currency unit, see [Smallest unit of the currency](https://docs.antom.com/ac/ref/cc.md#ONkIe).

More information:

- Value range: 1 - unlimited

#### refundTime (Datetime)

The date and time when the refund reaches the state of success, failure, or unknown.

More information:

- The value follows the [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) standard format. For example, "2019-11-27T12:01:01+08:00".

#### grossSettlementAmount (Amount)

The refund settlement amount, which equals the refund amount multiplied by the value of _settlementQuote_. This field is returned when the currency exchange is predetermined and the exchange rate is locked at the time of the transaction.

##### currency (String, REQUIRED)

The 3-letter currency code that follows the [ISO 4217](https://www.iso.org/iso-4217-currency-codes.html) standard.

More information:

- Maximum length: 3 characters

##### value (Integer, REQUIRED)

The amount to charge as a positive integer in the smallest currency unit. (That is, 100 cents to charge $1.00, or 100 to charge JPY 100, a zero-decimal currency).

Note: For details about the smallest currency unit, see [Smallest unit of the currency](https://global.alipay.com/docs/ac/ref/cc#ONkIe).

More information:

- Value range: 1 - unlimited

#### settlementQuote (Quote)

The exchange rate between the settlement currency and transaction currency. This field is returned when _grossSettlementAmount_ is returned.

##### guaranteed  (Boolean)

Guaranteed exchange rate available for payment.

##### quoteCurrencyPair (String, REQUIRED)

The exchange rate between settlement currency and transaction currency. Two currencies are separated with a slash and use the 3-letter [ISO-4217](https://www.iso.org/iso-4217-currency-codes.html) currency code.

More information:

- Maximum length: 16 characters

##### quoteExpiryTime (Datetime)

Expiration time of the exchange rate.

More information:

- The value follows the [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) standard format. For example, "2019-11-27T12:01:01+08:00".

##### quoteId (String)

The unique ID that is assigned by Alipay to identify an exchange rate.

More information:

- Maximum length: 64 characters

##### quotePrice (Decimal, REQUIRED)

The exchange rate used when a currency conversion between settlement currency and transaction currency occurs.

More information:

- Value range: 1 - unlimited

##### quoteStartTime (Datetime)

Effective time of the exchange rate.

More information:

- The value follows the [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) standard format. For example, "2019-11-27T12:01:01+08:00".

## 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`, the refund succeeds.
-   If the value of _result.resultStatus_ is `F`, the refund fails. Usually, the failure reason is that the refund is initiated when the refund window has passed (_result.resultCode_\=`REFUND_WINDOW_EXCEED`). If the refund still needs 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. Retry with the same _refundRequestId_ or use the [**inquiryRefund**](https://global.alipay.com/docs/ac/ams/ir_online) API to check the refund result.

## Result/Error codes

| Code | Value | Message | Further action |
| --- | --- | --- | --- |
| SUCCESS | S | Success | The refund is successful, no further action is needed. |
| ACCESS_DENIED | F | Access is denied. | Contact Antom Technical Support for detailed reasons. |
| INVALID_API | F | The called API is invalid or not active. | Contact Antom Technical Support to resolve the issue. |
| CURRENCY_NOT_SUPPORT | F | The currency is not supported. | Contact Antom Technical Support for detailed reasons. |
| INVALID_MERCHANT_STATUS | F | The merchant status is abnormal because restrictions exist. | Contact Antom Technical Support for detailed reasons. |
| KEY_NOT_FOUND | F | The private key or public key of Antom or the merchant is not found. | Check whether the private key or public key exists. If not, upload the private key in Antom Dashboard. |
| MERCHANT_BALANCE_NOT_ENOUGH | F | The merchant balance is insufficient. | Call the interface again after the merchant has sufficient balance. The refundRequestId field needs to be changed when you try again. |
| MULTIPLE_REFUNDS_NOT_SUPPORTED | F | Multiple refunds are not supported because restrictions exist in the contract. | Check whether multiple refunds exist. Do not call the refund interface anymore. For each refund, only call the interface once. |
| NO_INTERFACE_DEF | F | API is not defined. | Check whether the URL is correct. Please refer to the endpoint in the API documentation. |
| ORDER_IS_CLOSED | F | The request you initiated has the same paymentRequestId as that of the existed transaction, which is closed. | Use a new paymentRequestId to initiate the refund again. |
| ORDER_NOT_EXIST | F | The order does not exist. | Check whether paymentId is correct. If correct, contact Antom Technical Support for specific reasons. |
| ORDER_STATUS_INVALID | F | The order status is invalid. The transaction is under process or the transaction is failed. | Check the order status and take corresponding actions. Wait if the transaction is under process. Do not initiate the refund if the transaction failed. Contact Antom Technical Support for specific reasons. |
| PARAM_ILLEGAL | F | The required parameters are not passed, or illegal parameters exist. For example, a non-numeric input, an invalid date, or the length and type of the parameter are wrong. | Check and verify whether the required request fields (including the header fields and body fields) of the current API are correctly passed and valid. |
| PROCESS_FAIL | F | A general business failure occurred. | Do not retry. Human intervention is usually needed. It is recommended that you contact Antom Technical Support to troubleshoot the issue. |
| REFUND_AMOUNT_EXCEED | F | The total refund amount exceeds the payment amount or the refund amount is less than the minimum refund amount.   | Confirm whether the total refund amount exceeds the payment amount or whether the refund amount is less than the minimum refund amount. Create a new refund using an amount that is less than or equal to the payment amount and greater than or equal to the minimum refund amount, or contact Antom technical support. |
| REFUND_WINDOW_EXCEED | F | The refund date exceeds the refundable period that is agreed in the contract. | Confirm whether the refund date exceeds the refundable period. Check the refundable period in the contract or contact Antom Technical Support for the specific refundable period. |
| REPEAT_REQ_INCONSISTENT | F | The amount or currency is different from the previous request. | Ensure all the fields in the requests are the same or use a new paymentRequestId to initiate the refund again. |
| SYSTEM_ERROR | F | A system error occurred. | Do not retry, and contact Antom Technical Support for more details. |
| REFUND_IN_PROCESS | U | The refund is being processed. | Wait for the asynchronous notification or call the inquiryRefund interface to query the final refund status. Do not retry the refund request. |
| REFUND_NOT_SUPPORT | F | Refunds are not supported for this transaction. | Check the transaction status and the refund policy in the contract. If the transaction is successful and the contract allows refunds, contact Antom Technical Support. |
| REQUEST_TRAFFIC_EXCEED_LIMIT | U | The request traffic exceeds the limit. | Call the interface again to resolve the issue. If not resolved, contact Antom Technical Support. |
| PARTIAL_REFUND_NOT_SUPPORTED | F | A partial refund is not supported for this transaction. | Make a full refund or contact the buyer for an offline refund. |
| PAYMENT_METHOD_NOT_SUPPORTED | F | The payment method does not support canceling or refunding transactions if the payment status is successful.  | Do not retry. Contact Antom Technical Support to get more information. |
| ORDER_IS_CANCELED | F | The transaction is canceled. | You cannot refund the transaction because it is canceled. |
| UNKNOWN_EXCEPTION | U | An API call has failed, which is caused by unknown reasons. | Call the interface again to resolve the issue. If not resolved, contact Antom Technical Support. |

## Request

```json
{
  "paymentId": "20241212194010800100188670211082739",
  "captureId": "20241212194010807000188670209694546",
  "refundReason": "amsdemorefund",
  "refundRequestId": "yuqian_refund_654ac17e-bc5e-4648-b9de-a18f0a74aa2a",
  "refundAmount": {
    "currency": "USD",
    "value": "1000"
  },
  "actualRefundAmount": {
    "currency": "MYR",
    "value": "4166"
  }
}
```

## Response

### SUCCESS

```json
{
  "result": {
    "resultCode": "SUCCESS",
    "resultStatus": "S",
    "resultMessage": "Success"
  },
  "refundAmount": {
    "value": "100",
    "currency": "USD"
  },
  "refundTime": "2020-10-10T12:01:01+08:30",
  "paymentId": "20181129190741010007000000XXXX",
  "refundRequestId": "20181129190741020007000000XXXX",
  "refundId": "40181129190741020007000000XXXX"
}
```

### CURRENCY_INCONSISTENT

```json
{
  "result": {
    "resultCode": "CURRENCY_NOT_SUPPORT",
    "resultMessage": "The currency is not supported.",
    "resultStatus": "F"
  }
}
```

### REFUND_LIMIT_EXCEEDED

```json
{
  "result": {
    "resultCode": "REFUND_AMOUNT_EXCEED",
    "resultMessage": "The total refund amount exceeds the payment amount.",
    "resultStatus": "F"
  }
}
```

### REFUNDREQUESTID_REPEAT

```json
{
  "result": {
    "resultCode": "REPEAT_REQ_INCONSISTENT",
    "resultMessage": "The amount or currency is different from the previous request.",
    "resultStatus": "F"
  }
}
```

### TRANSACTION_INVALID

```json
{
  "result": {
    "resultCode": "PROCESS_FAIL",
    "resultMessage": "A general business failure occurred.",
    "resultStatus": "F"
  }
}
```