Payment Status

Check the current status of a previously executed payment using the myPOS Checkout API.

Step 1: Include the SDK Loader

This will autoload necessary library files and classes.

Code Example

PHP
require_once './IPC/Loader.php';

Step 2: Create Config Object and Set API Configuration Params

IpcURL is different for sandbox and production environments.

You can use the automatic configuration package or set manually keyIndex, sid, wallet, and RSA keys (for request signatures by setting key content using setPrivateKey and setAPIPublicKey or by setting file path using setPrivateKeyPath and setAPIPublicKeyPath).

Configuration package:

Code Example

PHP
$cnf = new \Mypos\IPC\Config();
$cnf->setIpcURL('https://mypos.com/vmp/checkout-test/');
$cnf->setLang('en');
$cnf->setVersion('1.4');
$configurationPackage = 'your-generated-package-token';
$cnf->loadConfigurationPackage($configurationPackage);

RSA Key pair:

Code Example

PHP
$cnf = new \Mypos\IPC\Config();
$cnf->setIpcURL('https://mypos.com/vmp/checkout-test/');
$cnf->setLang('en');
$cnf->setVersion('1.4');
$cnf->setPrivateKeyPath(dirname(__FILE__) . '/keys/store_private_key.pem');
$cnf->setAPIPublicKeyPath(dirname(__FILE__) . '/keys/api_public_key.pem');
$cnf->setKeyIndex(1);
$cnf->setSid('000000000000010');
$cnf->setWallet('61938166610');

For more information, see the Get Payment Status method documentation.

Step 3: Create GetPaymentStatus Object and Set Required Params

Code Example

PHP
$ipcStatus = new \Mypos\IPC\GetPaymentStatus($cnf);
$ipcStatus->setOrderID('1440');
$ipcStatus->setOutputFormat(\Mypos\IPC\Defines::COMMUNICATION_FORMAT_JSON);

Step 4: Process Request

Code Example

PHP
$result = $ipcStatus->process();

Step 5: Check Response Status and Use Received Data

You may get response data as an array using getData() or in the original communication format using getDataRaw().

Code Example

PHP
switch($result->getStatus()){
    case \Mypos\IPC\Defines::STATUS_SUCCESS:
        // Display returned data in the site interface.
        print_r(\Mypos\IPC\Helper::getArrayVal($result->getData(CASE_LOWER), 'orderstatus'));
        break;
    case \Mypos\IPC\Defines::STATUS_INVALID_PARAMS:
        // Order not found or set params are invalid.
        // Show error.
        break;
}

Best Practice: Wrap in Try-Catch

Using a try-catch block helps handle exceptions gracefully:

Code Example

PHP
try{
    $ipcStatus = new \Mypos\IPC\GetPaymentStatus($cnf);
    $ipcStatus->setOrderID('1440');
    $ipcStatus->setOutputFormat(\Mypos\IPC\Defines::COMMUNICATION_FORMAT_JSON);
    $result = $ipcStatus->process();

    switch($result->getStatus()){
        case \Mypos\IPC\Defines::STATUS_SUCCESS:
            print_r(\Mypos\IPC\Helper::getArrayVal($result->getData(CASE_LOWER), 'orderstatus'));
            break;
        case \Mypos\IPC\Defines::STATUS_INVALID_PARAMS:
            echo 'Not found!';
            break;
    }
}catch(\Mypos\IPC_Exception $ex){
    // Display exception message
    echo $ex->getMessage();
}

More Information

For a full breakdown of response fields and validation tips, see the Get Payment Status API documentation.