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 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:
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
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