---
page_source: https://docs.hdfcbank.juspay.in/docs/hypercheckout-mobile-sdk/web/resources/refunds
page_title: Refunds
---


## Refunds



Refunds can be initiated only for transactions that are CHARGED. The refunded amount will be settled to the same payment method that the customer used for making the payment.


### Initiating Refunds



Refund using Integration Kit -

Please follow the steps given below initiate a refund :

1. Please add the code snippet for refund functionality in your refunds api file (code snippet given below) 
   
   
   #### Java Code Snippet:
   
   ```java
   Map<String, Object> params = new LinkedHashMap<>();
               params.put("amount", amount);
               params.put("unique_request_id", uniqueRequestId);
               params.put("order_id", orderId);
   
               RequestOptions requestOptions = RequestOptions.createDefault();
   
               Order refund = Order.refund(orderId, params, requestOptions);
               String jsonResponse = objectMapper.writeValueAsString(refund);
   
   ```
   
   #### PHP Code Snippet:
   
   ```php
   $params = array ();
           $params ['order_id'] = "order_id";
           $params['unique_request_id'] = uniqid('php_sdk_test_');
           $params['amount']= "order amount";
           $requestOption = new RequestOptions();
          
   $requestOption->withCustomerId("testing-customer-one")->withMerchantId(“merchant_id”); 
           $order = Order::refund($params, $requestOption);
           echo "amout refunded: " . $order->amountRefunded . PHP_EOL;
   
   ```
2. Please ensure that SmartGateway environment has been setup
3. Please provide the following inputs 
   
   
   | Parameter | Type  | Description  |
   |---|---|---|
   | order_id | Mandatory  | Order Id of the order for which you want to proceed with refund  Example:- 1418394476 |
   | amount | Mandatory | Amount that has to be refunded. Amount has to be less than or equal to the amount of the order that is not yet refunded. If this parameter is not passed, then the order is refunded entirely |
   | unique_request_id | Mandatory | Request ID that uniquely identifies this request. You cannot reuse the value for two different refund requests. This is to avoid processing duplicate refund requests.The length of the unique_request_id should be less than 21 characters |
4. Run the project


### Refund Status Mapping




| Refund Status | Description |
|---|---|
| Pending | SmartGateway has marked refund and sent a refund request to underlying PG. |
| Success | Refund has been successfully executed by underlying PG. |
| Failure | Refund is failed. |
| Manual Review | Refunds that are pending more than 10 days goes into manual review. |



### Updating Refund Status



1. **Order Status Function** : You need to poll this function and fetch refund details from the refunds block in the function response([Sample Response](/hypercheckout-mobile-sdk/android/resources/order-status--sample-response)). Refer [Handle Payment Response](/hypercheckout-mobile-sdk/android/how-to-integrate-sdks/handle-payment-responses) Section to know in detail.
2. **Webhook** : Consume ORDER_REFUNDED and ORDER_REFUND_FAILED and REFUND_MANUAL_REVIEW_NEEDED webhooks to update the refund status real time. Refer [Transaction Status](/hdfc-resources/docs/common-resources/transaction-status) Section to know in detail.


## **Auto Refund** 



In payment ecosystem when a transaction traverses from your website to payment gateway and to bank page there are possibilities that customer might get charged for a transaction, however the transaction status might not get updated in realtime due delayed response from the payment provider or the bank's digital infrastructure that is supporting the transaction. These transactions will stay in pending state and move to success once the PG gets response from the processing bank or when the PG complete the reconciliation with the processing bank, this causes delayed success of transaction. Your business policy might have a predefined order timeouts (a specified duration post which payments will not be accepted against the order). This may range from few minutes to a few days depending on the type of product/ service offered by your business

Auto refund feature can be used to automatically refund -  1. [Conflicted Transactions](/hdfc-resources/docs/common-resources/refunds#Conflicted-transaction)

2. [Multiple Charged Transaction](/hdfc-resources/docs/common-resources/refunds#Multiple-Charged-transactions)


### Conflicted transaction



For merchants rendering realtime services, they can set a threshold time as per their order fulfilment window on dashboard. If transaction goes into pending state and we receive success response from PG post the threshold time limit set by you, then we consider that transaction as conflicted transaction.

> **Note**
> Here the order fulfilment window means a specified duration in which payments will be accepted against an order.



> **Note**
> The auto refund of conflicted transactions threshold time will be calculated from the time of transaction initiation and not order creation.



**Steps to enable Auto Refunds for Conflicted transactions -** 

1. Go to your Dashboard > Payments > Settings > Conflict > Enable the toggle of Auto refund of Conflicted transactions.
2. Set the Auto Refund of Conflicted Transactions Threshold in Mins (This is the field where you need to put the time limit after that when we will receive SUCCESS then that will be auto_refuded, by default it is 10 mins)
3. **[Optional]**  You can also Enable the toggle of Notify on status conflict  and if this is enabled then the you needs to put email id under Conflict Status Email field.
   
   ![Image](https://dth95m2xtyv8v.cloudfront.net/tesseract/assets/hdfc-resources/Screenshot%202023-11-09%20at%204.17.55%20AM.png)


### Multiple Charged transactions



Multiple charged transactions are those in which two or more transactions got charged against a same order.  When customer attempts multiple transactions against an order ID where for the first transaction the amount is debited from customer’s account however transaction goes into pending state, customer attempts another transaction which gets successful and later the first transaction also gets successful, leading to more than one successful transaction against an Order ID.

> **Note**
> If auto-refund for multiple charged transactions is enabled then expect for the first successful transaction all other transactions would be refunded against an Order.



**Steps to enable Auto Refunds for Multiple Charged transactions -** 

* Go to your Dashboard > Payments > Settings > Conflict > Enable the toggle of Multiple charged Transactions.
  
  ![Image](https://dth95m2xtyv8v.cloudfront.net/tesseract/assets/hdfc-resources/Screenshot%202023-11-09%20at%203.55.13%20AM-6bSlv.png)


### Updating Refund Status for Auto-refunded transaction



1. **Order Status Function** : You need to poll the order status function and fetch refund details from the refunds block in the response, the order status of auto-refunded transaction would be **AUTO_REFUNDED** . Refer [Handle Payment Response](/hypercheckout-mobile-sdk/android/how-to-integrate-sdks/handle-payment-responses) Section to know in detail.
2. **Webhook** : Please consume the below webhooks to update the refund status for auto refunded transaction.**AUTO_REFUND_INITIATED:**  Generated when a transaction an auto refund entry for that transaction is created at SmartGateway**AUTO_REFUND_SUCCEEDED:** Generated when the transaction is auto refunded and refund is success.**AUTO_REFUND_FAILED:**  Generated when the transaction is auto refunded and refund has failed.