This method is used to initiate a transaction refund.
Parameters
Parameter | Type | Mandatory | Description |
---|---|---|---|
merchant_transaction_id | str | Yes | The merchant transaction ID for which the status is fetched |
original_transaction_id | str | Yes | Merchant transaction ID of the forward transaction to be reversed. |
amount | int | Yes | Reversal amount in paise, up to the maximum of the original payment transaction. |
callback_url | str | No | URL for server-to-server callback. A POST request will be made. |
For Java SDK Version <= 1.0.1, the imports should be:
from phonepe.sdk.pg.payments
For Java SDK Version > 1.0.1, the imports should be:
from phonepe.sdk.pg.payments.v1
Example (Refund)
import com.phonepe.sdk.pg.Env;
import com.phonepe.sdk.pg.common.http.PhonePeResponse;
import com.phonepe.sdk.pg.payments.v1.PhonePePaymentClient;
import com.phonepe.sdk.pg.payments.v1.models.request.PgRefundRequest;
import com.phonepe.sdk.pg.payments.v1.models.response.PgRefundResponse;
String merchantId = "<merchantId>";
String saltKey = "<saltKey>";
Integer saltIndex = "<saltIndex>";
Env env = Env.UAT;
boolean shouldPublishEvents = true;
PhonePePaymentClient phonepeClient = new PhonePePaymentClient(merchantId, saltKey, saltIndex, env, shouldPublishEvents);
String merchantTransactionId = UUID.randomUUID().toString().substring(0,34);
String originalTransactionId = "forwardTranscationId";
long amount = 100;
String callbackUrl = "https://www.merchant.com/notify";
PgRefundRequest pgRefundRequest = PgRefundRequest.builder()
.amount(amount)
.callbackUrl(callbackUrl)
.merchantId(merchantId)
.merchantTransactionId(merchantTransactionId)
.originalTransactionId(originalTransactionId)
.build();
PhonePeResponse<PgRefundResponse> refundResponse = phonepeClient.refund(pgRefundRequest);
String responseCode = refundResponse.getData().getResponseCode();
Returns
The function returns a PhonePeResponse object with the following properties:
Parameter | Type | Description |
---|---|---|
success | boolean | Success/failure of the request processing |
code | str | Response code explaining the result |
message | str | Additional information about the response |
data | PgRefundResponse | Information about the refund |
PgRefundResponse properties
Here is the response property table for the given model:
Property | Type | Description |
---|---|---|
merchant_id | str | The ID of the merchant associated with the transaction. |
merchant_transaction_id | str | The unique identifier of the merchant transaction |
transaction_id | str | The PhonePe unique identifier of the transaction. |
amount | int | The refunded amount |
response_code | str | The response code indicating the status of the refund |
state | str | The state of the refund transaction. Can be PENDING, COMPLETED, or FAILED. |