Purchase Rollback
This method is used to rollback a previously sent notification, typically when a purchase must be reversed on your system (e.g., after a timeout or business logic reversal).
Rollback of Previous Notification
Step 1: Include SDK Loader
This will autoload necessary library files and classes.
require_once './IPC/Loader.php';
Step 2: Create Config Object and Set API Configuration Params
Note:
IpcURLis 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:
$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);
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 IPCPurchaseRollback method documentation.
Step 3: Handle Incoming Rollback Notification
Create a Response object with the incoming POST data. This will validate the data and the request signature.
try {
$responce = \Mypos\IPC\Response::getInstance($cnf, $_POST, \Mypos\IPC\Defines::COMMUNICATION_FORMAT_POST);
} catch(\Mypos\IPC\IPC_Exception $e) {
echo 'Error';
}
Step 4: Get Posted Data as an Array
$data is a one-dimensional array containing elements with keys:
ipcmethod, sid, amount, currency, orderid
$data = $responce->getData(CASE_LOWER);
Step 5: Merchant Logic
- Search in your database for the order with this
orderid - Verify that
amountandcurrencymatch the original transaction - Change order status to "Cancelled"
- Echo
"OK"if everything is valid
if ('...check and update order...') {
echo 'OK';
} else {
echo 'Error';
}
Reference
For more information, see the PurchaseRollback method in the official documentation.