Purchase Cancel

This method notifies your system that the customer has cancelled a payment. You can use it to update order status or display a cancellation message.

Important Notes

  • This is not a payment failure; it simply means the user chose to cancel the process.
  • Use this method to log, update, or notify about the canceled order.

Step 1: Include SDK Loader

This will autoload necessary library files and classes.

require_once './IPC/Loader.php';

Step 2: API Configuration

NOTE: 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).

Option A: Using a Configuration Package

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

Option B: Manual Configuration

$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, please refer to the IPCPurchaseCancel method documentation.

Step 3: Handle the Response

Parse the incoming POST data from myPOS:

try {
    $responce = \Mypos\IPC\Response::getInstance($cnf, $_POST, \Mypos\IPC\Defines::COMMUNICATION_FORMAT_POST);
} catch(\Mypos\IPC\IPC_Exception $e) {
    // Display a general error or redirect to merchant store home page
}

Step 4: Extract and Validate Response Data

$data = $responce->getData(CASE_LOWER);

Returned keys may include:

  • ipcmethod
  • sid
  • amount
  • currency
  • orderid
  • ipc_trnref
  • requeststan
  • requestdatetime

Merchant System Logic

On your end, you should:

  1. Look up the order by orderid.
  2. Verify that amount and currency match.
  3. Show a cancellation page to the customer.
if ('...order is found in merchant store DB...') {
    echo "Your order has been canceled.";
} else {
    echo "Order not found. Redirecting...";
    // Redirect to home or show error
}