GetTxnStatus Class

The GetTxnStatus class allows you to retrieve the status of a previously initiated transaction by using the order ID. It handles validation, prepares the request, and processes the API response.

Class Details

  • Namespace: Mypos\IPC
  • Located at: GetTxnStatus.php
  • Extends: Mypos\IPC\Base
  • Purpose: Calls the IPCGetTxnStatus method to check the status of a transaction.

Method Summary

MethodReturn TypeDescription
__construct(Mypos\IPC\Config $cnf)-Initializes the class with a configuration object.
process()Mypos\IPC\ResponseSends the API request and returns the transaction status.
validate()boolValidates that all required parameters are set.
getOrderID()stringGets the order ID for which status is being queried.
setOrderID(string $orderID)GetTxnStatusSets the original order ID for the transaction you want to check.

Inherited Methods from Base

GetTxnStatus inherits core API methods from the Base class:

  • _addPostParam()
  • _processPost()
  • _processHtmlPost()
  • getCnf()
  • setCnf()
  • getOutputFormat()
  • setOutputFormat()
  • isValidSignature()

Example Usage

<?php
namespace Mypos\IPC;
/**
 * Process IPC method: IPCGetTxnStatus.
 * Collect, validate and send API params
 */
class GetTxnStatus extends Base
{
    private $orderID;
    public function __construct(Config $cnf)
    {
        $this->setCnf($cnf);
    }
    /**
     * Initiate API request
     *
     * @return Response
     */
    public function process()
    {
        $this->validate();
        $this->_addPostParam('IPCmethod', 'IPCGetTxnStatus');
        $this->_addPostParam('IPCVersion', $this->getCnf()->getVersion());
        $this->_addPostParam('IPCLanguage', $this->getCnf()->getLang());
        $this->_addPostParam('SID', $this->getCnf()->getSid());
        $this->_addPostParam('WalletNumber', $this->getCnf()->getWallet());
        $this->_addPostParam('KeyIndex', $this->getCnf()->getKeyIndex());
        $this->_addPostParam('Source', $this->getCnf()->getSource());
        $this->_addPostParam('OrderID', $this->getOrderID());
        $this->_addPostParam('OutputFormat', $this->getOutputFormat());
        return $this->_processPost();
    }
    /**
     * Validate all set details
     *
     * @return boolean
     * @throws IPC_Exception
     */
    public function validate()
    {
        try {
            $this->getCnf()->validate();
        } catch (\Exception $ex) {
            throw new IPC_Exception('Invalid Config details: '.$ex->getMessage());
        }
        if ($this->getOrderID() == null || !Helper::isValidOrderId($this->getOrderID())) {
            throw new IPC_Exception('Invalid OrderId');
        }
        if ($this->getOutputFormat() == null || !Helper::isValidOutputFormat($this->getOutputFormat())) {
            throw new IPC_Exception('Invalid Output format');
        }
        return true;
    }
    /**
     * Original request order id
     *
     * @return string
     */
    public function getOrderID()
    {
        return $this->orderID;
    }
    /**
     * Original request order id
     *
     * @param string $orderID
     *
     * @return GetTxnStatus
     */
    public function setOrderID($orderID)
    {
        $this->orderID = $orderID;
        return $this;
    }
}

Use Cases

Use GetTxnStatus when:

  • You need to confirm if a payment was successful or declined
  • You’re implementing post-payment logic based on real-time status
  • You want to check status programmatically instead of relying on notifications