PG Refund

This method is used to initiate a transaction refund.

Parameters

ParameterTypeMandatoryDescription
merchant_transaction_idstrYesThe merchant transaction ID for which the status is fetched
original_transaction_idstrYesMerchant transaction ID of the forward transaction to be reversed.
amountintYesReversal amount in paise, up to the maximum of the original payment transaction.
callback_urlstrNoURL 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:

ParameterTypeDescription
successbooleanSuccess/failure of the request processing
codestrResponse code explaining the result
messagestrAdditional information about the response
dataPgRefundResponseInformation about the refund

PgRefundResponse properties

Here is the response property table for the given model:

PropertyTypeDescription
merchant_idstrThe ID of the merchant associated with the transaction.
merchant_transaction_idstrThe unique identifier of the merchant transaction
transaction_idstrThe PhonePe unique identifier of the transaction.
amountintThe refunded amount
response_codestrThe response code indicating the status of the refund
statestrThe state of the refund transaction. Can be PENDING, COMPLETED, or FAILED.