Initiate and Verify Refunds with Node.js SDK


It is used to initiate a refund using refund() function. This ensures the amount is returned to the customer’s original payment method.

You can use the RefundRequest.builder() to create the refund request and the following are the attributes that merchant can pass.

Parameter NameData TypeMandatory
(Yes/No)
DescriptionConstraints
merchantRefundIdStringYesUnique refund ID assigned by you.Max Length = 63 characters.
originalMerchantOrderIdStringYesThe original order ID against which the refund is requested.
amountIntegerYesRefund amount in paisa. Must be at least 1 paisa and not exceed the order amount.Min value = 100 (in Paise), Max value = order amount.

⚠️ Invalid Refund Amount!


The refund amount cannot exceed the initiated amount. It must always be less than or equal to the amount originally initiated.

Sample Request
import { StandardCheckoutClient, Env, RefundRequest } from 'pg-sdk-node';
import { randomUUID } from 'crypto';
 
const clientId = "<clientId>";
const clientSecret = "<clientSecret>";
const clientVersion = <clientVersion>;  //insert your client version here
const env = Env.SANDBOX;      //change to Env.PRODUCTION when you go live
 
const client = StandardCheckoutClient.getInstance(clientId, clientSecret, clientVersion, env);
 
const refundId = randomUUID();
const originalMerchantOrderId = '<MERCHANT_ORDER_ID>';    //merchantOrderId for which order has to be initiated
const amount = 100                                      //amount to be refund
 
const request = RefundRequest.builder()
    .amount(amount)
    .merchantRefundId(refundId)
    .originalMerchantOrderId(originalMerchantOrderId)
    .build();
 
client.refund(request).then((response) => {
    const state = response.state
})

The function returns a RefundResponse object with the following properties:

PropertyData TypeDescription
refundIdStringRefund ID generated by PhonePe PG.
stateStringThe status of the refund.
amountLongThe refunded amount (in paisa).

It is used to retrieve the status of a refund using getRefundStatus() function.

Request Parameters
Parameter NameData TypeMandatory
(Yes/No)
Description
refundIdStringYesRefund ID assigned by you at the time of initiation
Sample Request
import {StandardCheckoutClient, Env} from 'pg-sdk-node';
 
const clientId = "<clientId>";
const clientSecret = "<clientSecret>";
const clientVersion = <clientVersion>;  //insert your client version here
const env = Env.SANDBOX;      //change to Env.PRODUCTION when you go live
 
const client = StandardCheckoutClient.getInstance(clientId, clientSecret, clientVersion, env);
 
const refundId = '<REFUND_ID>'; //refundId used to initiate the refund
 
client.getRefundStatus(refundId).then((response) => {
    const state = response.state
})

It returns a RefundStatusResponse Object.

Response Parameters
PropertyData TypeDescription
merchantIdStringOrder ID generated by PhonePe PG.
merchantRefundIdStringThe refund ID created at the time of refund initiation.
stateStringThe status of the refund.
amountIntegerAmount to refund.
paymentDetailsList<PaymentRefundDetail>List of payment attempt details corresponding to the order.

The PaymentRefundDetail property contains a list of payment details for each payment attempt made against an order. The details of each payment are explained in the table below.

PropertyData TypeDescription
transactionIdIntegerThe transaction ID generated by PhonePe PG.
paymentModeStringThe payment method used
UPI_INTENT
UPI_COLLECT
UPI_QR
CARD
TOKEN
NET_BANKING
timestampLongTimestamp of the attempted transaction in epoch.
amountIntegerOrder amount in paisa.
stateStringAttempted transaction state. It can be any one of the following states:
PENDING
COMPLETED
FAILED
errorCodeStringError code (only if the transaction failed)
detailedErrorCodeStringA more detailed error code (only if the transaction failed)
splitInstrumentslist<InstrumentCombo>Contains split instrument details of all the transactions made.

In this section, you’ve learned how to initiate a refund and check its status. In the next section, you’ll understand how payment verification is handled using Webhooks, and how to manually verify the payment in case the webhook callback fails.

Is this article helpful?