Purchase OK
This method is triggered after a successful payment, redirecting the customer back to your website.
Do not use IPCPurchaseOK to authorize a payment because it is not a server-to-server connection and it is not always guaranteed to receive a response.
For secure, server-to-server confirmation, always use PurchaseNotify.
Why Avoid IPCPurchaseOK for Authorization?
- It does not guarantee a reliable response.
- It is client-side only (redirect-based), meaning a connection error could result in no notification.
- Always confirm payments via IPCPurchaseNotify for secure verification.
Step 1: Include SDK Loader
This will autoload necessary library files and classes.
require_once './IPC/Loader.php';
Step 2: API Configuration
Note that 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: Configuration Package (Recommended)
$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 IPCPurchaseOK method documentation.
Step 3: Handle Incoming Response
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) {
// Display a general error or redirect to merchant store home page
}
Step 4: Access and Validate Data
$data is a one-dimensional array containing elements with keys:
IPCmethod, SID, Amount, Currency, OrderID, IPC_Trnref, RequestSTAN, RequestDateTime.
$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. - Show a "Thank you" or confirmation page to the customer.
if ('...order is found in merchant store DB') {
// Display "Your order has been successfully paid" for example.
} else {
// Display a general error or redirect to merchant store home page
}