PG Check Status

This method is used to check the status of the transaction.

Parameters

ParameterTypeMandatoryDescription
merchant_transaction_idstrYesThe merchant transaction ID for which the status is fetched

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 (Check Status)

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.response.PgTransactionStatusResponse;


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 = "merchantTransactionId";
PhonePeResponse<PgTransactionStatusResponse> statusResponse = phonepeClient.checkStatus(merchantTransactionId);
String state = statusResponse.getData().getState();

Returns

The function returns a PhonePeResponse object with the following properties:

ParameterTypeDescription
successbooleanIndicates the success or failure of the request processing.
codestrResponse code explaining the reason for the status.
messagestrMessage providing more information about the code.
dataPgTransactionStatusResponseInformation about the transaction status.

PgTransactionStatusResponse 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 merchant transaction id
transaction_idstrThe PhonePe unique identifier of the transaction.
amountintThe transaction amount
response_codestrThe response code.
statePgTransactionStateThe transaction state. Can be PENDING, COMPLETED, or FAILED.
payment_instrumentCardPaymentInstrumentResponse, UPIPaymentInstrumentResponse, NetBankingPaymentInstrumentResponseSpecific data for different payment instruments.

Note: The specific properties under payment_instrument will vary based on the type of payment instrument used.

Check status: UPI Instrument

The payment_instrument will be of UPIPaymentInstrumentResponse type. Example for handling response when the transaction was completed using UPI payment instrument

import com.phonepe.sdk.pg.common.http.PhonePeResponse;
import com.phonepe.sdk.pg.payments.v1.models.responseV1.PgPaymentInstrument;
import com.phonepe.sdk.pg.payments.v1.models.responseV1.PgTransactionStatusResponse;
import com.phonepe.sdk.pg.payments.v1.models.responseV1.UPIPaymentInstrumentResponse;

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 = "merchantTransactionId";

PhonePeResponse<PgTransactionStatusResponse> statusResponse = phonepeClient.checkStatus(merchantTransactionId);
PgPaymentInstrument pgPaymentInstrument = statusResponse.getData().getPaymentInstrument();
final UPIPaymentInstrumentResponse upiPaymentInstrumentResponse = (UPIPaymentInstrumentResponse) pgPaymentInstrument;
String utr = upiPaymentInstrumentResponse.getUtr();
String ifsc = upiPaymentInstrumentResponse.getIfsc();

Check status: Card Instrument

The payment_instrument will be of CardPaymentInstrumentResponse type. Example for getting transaction details when it was completed using NetBanking payment instrument

import com.phonepe.sdk.pg.common.http.PhonePeResponse;
import com.phonepe.sdk.pg.payments.v1.models.responseV1.CardPaymentInstrumentResponse;
import com.phonepe.sdk.pg.payments.v1.models.responseV1.PgPaymentInstrument;
import com.phonepe.sdk.pg.payments.v1.models.responseV1.PgTransactionStatusResponse;

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 = "merchantTransactionId";

PhonePeResponse<PgTransactionStatusResponse> statusResponse = phonepeClient.checkStatus(merchantTransactionId);
PgPaymentInstrument pgPaymentInstrument = statusResponse.getData().getPaymentInstrument();
final CardPaymentInstrumentResponse cardPaymentInstrument = (CardPaymentInstrumentResponse) pgPaymentInstrument;
String pgTransactionId = cardPaymentInstrument.getPgTransactionId();
String pgAuthorizationCode = cardPaymentInstrument.getPgAuthorizationCode();
String bankId = cardPaymentInstrument.getBankId();

Check status: NetBanking Instrument

The payment_instrument will be of NetBankingPaymentInstrumentResponse type. Example for getting transaction details when it was completed using NetBanking payment instrument.

import com.phonepe.sdk.pg.common.http.PhonePeResponse;
import com.phonepe.sdk.pg.payments.v1.models.responseV1.NetBankingPaymentInstrumentResponse;
import com.phonepe.sdk.pg.payments.v1.models.responseV1.PgPaymentInstrument;
import com.phonepe.sdk.pg.payments.v1.models.responseV1.PgTransactionStatusResponse;

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 = "merchantTransactionId";

PhonePeResponse<PgTransactionStatusResponse> statusResponse = phonepeClient.checkStatus(merchantTransactionId);
PgPaymentInstrument pgPaymentInstrument = statusResponse.getData().getPaymentInstrument();
final NetBankingPaymentInstrumentResponse netBankingPaymentInstrumentResponse = (NetBankingPaymentInstrumentResponse) pgPaymentInstrument;
String bankId = netBankingPaymentInstrumentResponse.getBankId();
String bankTransactionId = netBankingPaymentInstrumentResponse.getBankTransactionId();