NodeJs SDK – Refund

It is used to initiate a refund using refund() function

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

Parameters:

Parameter nameData TypeMandatoryDescriptionConstraints
merchantRefundIdStringyesUnique merchant refund id generated by merchantMax Length = 63 characters
originalMerchantOrderIdStringyes
Original merchant order id against which refund is required
amountLongyesAmount in paisa to refundMin value = 100 (in paise), Max value = order amount

Example :

import {CustomCheckoutClient, Env, RefundRequest, RefundResponse} 
from 'pg-sdk-node'
import { v4 
as uuid } 
from 'uuid';
 

const clientId:
string = "<clientId>";

const clientSecret:
string = "<clientSecret>";

const clientVersion:number = <clientVersion>;  //insert your client version here

const env = Env.SANDBOX;      //change to Env.PRODUCTION when you go live
 

const client = CustomCheckoutClient.
getInstance(clientId, clientSecret, clientVersion, env);
 

const refundId = 
uuid();

const originalMerchantOrderId = '<MERCHANT_ORDER_ID>';  //merchantOrderId for which order was 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;
});

Returns :

The function returns a RefundResponse Object

PropertyData TypeDescription
refundIdStringPhonePe generated internal refund id
stateStringThe state of the refund initiated. Initially it will be PENDING
amountlongAmount in paisa that will be refunded

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

Parameters

Parameter NameData TypeMandatoryDescription
refundIdStringYesRefund Id created by the merchant at the time of initiating the refund

Example :

import {
CustomCheckoutClient, 
Env} 
from 'pg-sdk-node'

import { 
RefundStatusResponse } 
from 'pg-sdk-node';
 

const clientId:string = "<clientId>";

const clientSecret:string = "<clientSecret>";

const clientVersion:number = 1;  //insert your client version here

const env = 
Env.SANDBOX;      //change to Env.PRODUCTION when you go live
 

const client = 
CustomCheckoutClient.
getInstance(clientId, clientSecret, clientVersion, env);
 

const refundId = '<REFUND_ID>';                   //refundId used to initiate the refund
 
client.
getRefundStatus(refundId).
then((response) => {
  
const state = response.state;
});

Returns:

It returns a RefundStatusResponse Object

RefundStatusResponse

PropertyData TypeDescription
merchantIdStringMerchant Id who initiated the refund
merchantRefundIdStringRefund Id created by the merchant at the time of refund initiation
originalMerchantOrderIdStringOrder Id for which refund has initiated. Created by the merchant at the time of order creation
amountLongAmount to refund
stateStringState of the refund
paymentDetailslist<PaymentRefundDetail>Contains the list of details of each transaction attempt made corresponding to this particular order

PaymentRefundDetail :

PropertyData TypeDescription
transactionIdStringTransaction Id generated by the PhonePe
paymentModeStringMode of Payment. It can be anyone of the following modes:
1. UPI_INTENT
2. UPI_COLLECT
3. UPI_QR
4. CARD
5. TOKEN
6. NET_BANKING
timestampLongTimestamp of the attempted transaction in epoch
stateStringAttempted transaction state. It can be any one of the following states: 1. PENDING
2. COMPLETED
3. FAILED
errorCodeStringError code present only when the transaction state is Failed
detailedErrorCodeStringDetailed Error Code present only when transaction state is Failed
splitInstrumentslist<InstrumentCombo>Type of transaction instrument. It can be any one of the following types:
1. ACCOUNT
2. CREDIT_CARD
3. DEBIT_CARD
4. NET_BANKING
Is this article helpful?