NodeJs SDK – Callback Verification

This is used to verify whether the callback received is valid or not

You need to pass 4 parameters to the validateCallback() function

Parameter NameData TypeMandatoryDescription
usernameStringYesUnique username configured for the callback url.
passwordStringYesUnique password configured for the callback url.
authorizationStringYesValue of the Authorization header under the callback response.
responseBodyStringYesCallback response body as string.

Example usage :

import {CustomCheckoutClient, Env, CallbackResponse} 
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 username = "<username>";

const password = "<password>";

const authorization = "<authorization";

const responseBody = "<responseBody>";
 

const callbackResponse = client.
validateCallback(username, password, authorization, responseBody);
 
String orderId = callbackResponse.payload.orderId
String state = callbackResponse.payload.state

Returns :

The function returns a CallbackResponse if the callback is valid, otherwise throws a PhonePeException.

Callback Response:

PropertyData TypeDescription
typeCallbackTypeContains event of callback received at the merchant end.
payloadCallbackDataContains callback details.

Callback Type

Callback TypeContext
PG_ORDER_COMPLETEDOrder completed
PG_ORDER_FAILEDOrder failed
PG_REFUND_ACCEPTEDPhonePe has acknowledged the Refund request is valid
PG_REFUND_COMPLETEDRefund request is successfully completed
PG_REFUND_FAILEDRefund request failed

CallbackData Properties :

PropertyData TypeDescription
merchantIdStringThe merchant from which request was initiated.
orderIdStringOrder id generated by PhonePe. (Only present in case of order callbacks)
merchantOrderIdStringOrder id generated by merchant. (Only present in case of order callbacks)
originalMerchantOrderIdStringInternal transaction id for given payment attempt. (Only present in case of refund callback)
refundIdStringRefund id generated by PhonePe. (Only present in case of refund callback)
merchantRefundIdStringRefund id generated by merchant. (Only present in case of refund callback)
stateStringState of the order/refund.
amountLongAmount of the order/refund processed.
expireAtLongExpiry in epoch.
errorCodeStringError code. (Only present when state is failed)
detailedErrorCodeStringDetailed error code. (Only present when state is failed)
metaInfoMetaInfoMetaInfo passed during the init of order.
paymentDetailsList<PaymentDetail>Payment details.

PaymentDetail Object :

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
amountLongAmount in Paisa of the order/refund processed
errorCodeLongError code present only when the transaction state is Failed
detailedErrorCodeStringDetailed Error Code present only when transaction state is Failed
splitInstrumentsList<InstrumentCombo>Contains split instrument details of all the transactions made

Below data can be used when you need to access the response details :

PaymentRail :

Different types of rail which will be received at the time of getOrderStatus(). It falls under the rail attribute in PaymentDetail Object.

UPI RAIL

PropertyType
typePaymentRailType
utrString
upiTransactionIdString
vpaString

PG RAIL

PropertyType
typePaymentRailType
transctionIdString
authorizationCodeString
serviceTransactionIdString

PPI WALLET RAIL

PropertyType
typePaymentRailType

PPI EGV RAIL

PropertyType
typePaymentRailType

Payment Instrument V2

ACCOUNT

PropertyType
typePaymentInstrumentType
ifscString
acountTypeString
maskedAccountNumberString
accountHolderNameString

CREDIT_CARD

PropertyType
typePaymentInstrumentType
bankTransactionIdString
bankIdString
arnString
brnString

DEBIT_CARD

PropertyType
typePaymentInstrumentType
bankTransactionIdString
bankIdString
arnString
brnString

NET_BANKING

PropertyType
typePaymentInstrumentType
bankTransactionIdString
bankIdString
arnString
brnString

EGV

PropertyType
typePaymentInstrumentType
cardNumberString
programIdString

WALLET

PropertyType
typePaymentInstrumentType
walletIdString

Instrument Constraints

ACCOUNT

PropertyType
typeAccount
accountNumberString
ifscString
Is this article helpful?