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 Python SDK Version <= 0.0.3, the imports should be:
from phonepe.sdk.pg.payments

For Python SDK Version > 0.0.3, the imports should be:
from phonepe.sdk.pg.payments.v1

Example (Check Status)

from phonepe.sdk.pg.payments.v1.payment_client import PhonePePaymentClient
from phonepe.sdk.pg.env import Env

merchant_id = "<YOUR_MERCHANT_ID>"
salt_key = "<YOUR_SALT_KEY>"
salt_index = 1 # insert your salt index
env = Env.UAT
should_publish_events = True
phonepe_client = PhonePePaymentClient(merchant_id, salt_key, salt_index, env, should_publish_events)

merchant_transaction_id = "YOUR_MERCHANT_TRANSACTION_ID"
response = phonepe_client.check_status(merchant_transaction_id)

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

from phonepe.sdk.pg.payments.v1.payment_client import PhonePePaymentClient
from phonepe.sdk.pg.env import Env

merchant_id = "<YOUR_MERCHANT_ID>"
salt_key = "<YOUR_SALT_KEY>"
salt_index = 1 # insert your salt index
env = Env.UAT
should_publish_events = True
phonepe_client = PhonePePaymentClient(merchant_id, salt_key, salt_index, env, should_publish_events)

merchant_transaction_id = "YOUR_MERCHANT_TRANSACTION_ID"
response = phonepe_client.check_status(merchant_transaction_id)

# transaction details
if response.data and response.data.payment_instrument.type.value == "UPI":
    state = response.data.state
    ifsc = response.data.payment_instrument.ifsc
    utr = response.data.payment_instrument.utr

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

from phonepe.sdk.pg.payments.v1.payment_client import PhonePePaymentClient
from phonepe.sdk.pg.env import Env

merchant_id = "<YOUR_MERCHANT_ID>"
salt_key = "<YOUR_SALT_KEY>"
salt_index = 1 # insert your salt index
env = Env.UAT
should_publish_events = True
phonepe_client = PhonePePaymentClient(merchant_id, salt_key, salt_index, env, should_publish_events)

merchant_transaction_id = "YOUR_MERCHANT_TRANSACTION_ID"
response = phonepe_client.check_status(merchant_transaction_id)

# transaction details
if response.data and response.data.payment_instrument.type.value == "CARD":
    state = response.data.state
    pg_transaction_id = response.data.payment_instrument.pg_transaction_id
    pg_authorization_code = response.data.payment_instrument.pg_authorization_code
    bank_id = response.data.payment_instrument.bank_id

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.

from phonepe.sdk.pg.payments.v1.payment_client import PhonePePaymentClient
from phonepe.sdk.pg.env import Env

merchant_id = "<YOUR_MERCHANT_ID>"
salt_key = "<YOUR_SALT_KEY>"
salt_index = 1 # insert your salt index
env = Env.UAT
should_publish_events = True
phonepe_client = PhonePePaymentClient(merchant_id, salt_key, salt_index, env, should_publish_events)

merchant_transaction_id = "YOUR_MERCHANT_TRANSACTION_ID"
response = phonepe_client.check_status(merchant_transaction_id)

# transaction details
if response.data and response.data.payment_instrument.type.value == "NETBANKING":
    state = response.data.state
    bank_id = response.data.payment_instrument.bank_id
    bank_transaction_id = response.data.payment_instrument.bank_transaction_id