This method is used to check the status of the transaction.
Parameters
Parameter | Type | Mandatory | Description |
---|---|---|---|
merchant_transaction_id | str | Yes | The 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:
Parameter | Type | Description |
---|---|---|
success | boolean | Indicates the success or failure of the request processing. |
code | str | Response code explaining the reason for the status. |
message | str | Message providing more information about the code. |
data | PgTransactionStatusResponse | Information about the transaction status. |
PgTransactionStatusResponse properties
Here is the response property table for the given model:
Property | Type | Description |
---|---|---|
merchant_id | str | The ID of the merchant associated with the transaction. |
merchant_transaction_id | str | The merchant transaction id |
transaction_id | str | The PhonePe unique identifier of the transaction. |
amount | int | The transaction amount |
response_code | str | The response code. |
state | PgTransactionState | The transaction state. Can be PENDING, COMPLETED, or FAILED. |
payment_instrument | CardPaymentInstrumentResponse, UPIPaymentInstrumentResponse, NetBankingPaymentInstrumentResponse | Specific 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();