Purchase with payment card

Include SDK loader.


This will autoload necessary library files and classes

require_once './IPC/Loader.php';


Create Config object and set API configuration params.

Note that IpcURL is different for sandbox and production environment.

You can set RSA keys for request signatures by setting key content using setPrivateKey and setAPIPublicKey or by setting a file path using setPrivateKeyPath and setAPIPublicKeyPath.

For more information please refer to IPCPurchase method documentation.

$cnf = new \Mypos\IPC\Config(); 
$cnf->setIpcURL('https://mypos.eu/vmp/checkout-test/'); 
$cnf->setLang('en'); 
$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->setVersion('1.3'); 
$cnf->setWallet('61938166610');


Create Customer object and set customer data

$customer = new \Mypos\IPC\Customer(); 
$customer->setFirstName('John'); 
$customer->setLastName('Smith'); 
$customer->setEmail('demo@demo.demo'); 
$customer->setPhone('+359111111111'); 
$customer->setCountry('BGR'); 
$customer->setAddress('Business Park Varna'); 
$customer->setCity('Varna'); 
$customer->setZip('9000');

 


Create Cart object and set cart items

$cart = new \Mypos\IPC\Cart; 
$cart->add('Some Book', 1, 9.99); //name, quantity, price 
$cart->add('Some other book', 1, 4.56); 
$cart->add('Discount', 1, -2.05);


Create Purchase object using Config object and set required params

$purchase = new \Mypos\IPC\Purchase($cnf); 
$purchase->setUrlCancel('https://mysite.com/ipc_cancel'); //User comes here after purchase cancelation 
$purchase->setUrlOk('https://mysite.com/ipc_ok'); //User comes here after purchase success 
$purchase->setUrlNotify('https://mysite.com/ipc_notify'); //IPC sends POST reuquest to this address with purchase status
$purchase->setOrderID(uniqid()); //Some unique ID 
$purchase->setCurrency('EUR'); 
$purchase->setNote('Some note'); //Not required 
$purchase->setCustomer($customer); 
$purchase->setCart($cart); 

$purchase->setCardTokenRequest(\Mypos\IPC\Purchase::CARD_TOKEN_REQUEST_PAY_AND_STORE); 
$purchase->setPaymentParametersRequired(\Mypos\IPC\Purchase::PURCHASE_TYPE_FULL);.
$purchase->setPaymentMethod(\Mypos\IPC\Purchase::PAYMENT_METHOD_BOTH);

 


Process payment

try{ 
    $purchase->process(); 
}catch(\Mypos\IPC\IPC_Exception $ex){ 
    echo $ex->getMessage(); 
    //Invalid params. To see details use "echo $ex->getMessage();" 
}