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

For more information please refer to IPCPurchase method documentation.

Configuration package

$cnf = new \Mypos\IPC\Config();
$cnf->setIpcURL('https://mypos.com/vmp/checkout-test/'); 
$cnf->setLang('en'); 
$cnf->setVersion('1.4'); 
$configurationPackage = 'eyJzaWQiOiIwMDAwMDAwMDAwMDAwMTAiLCJjbiI6IjYxOTM4MTY2NjEwIiwicGsiOiItLS0tLUJFR0lOIFJTQSBQUklWQVRFIEtFWS0tLS0tXHJcbk1JSUNYQUlCQUFLQmdRQ2YwVGRjVHVwaGI3WCtad2VrdDFYS0VXWkRjelNHZWNmbzZ2UWZxdnJhZjVWUHpjbkpcclxuMk1jNUo3MkhCbTB1OThFSkhhbitubGUyV09aTVZHSXRUYVwvMmsxRlJXd2J0N2lRNWR6RGg1UEVlWkFTZzJVV2VcclxuaG9SOEw4TXBOQnFINmg3WklUd1ZUZlJTNExzQnZsRWZUN1B6aG01WUpLZk0rQ2R6RE0rTDlXVkVHd0lEQVFBQlxyXG5Bb0dBWWZLeHdVdEVicTh1bFZyRDNubldoRitoazFrNktlamRVcTBkTFlOMjl3OFdqYkNNS2I5SWFva21xV2lRXHJcbjVpWkdFcll4aDdHNEJEUDhBV1wvK005SFhNNG9xbTVTRWtheGhiVGxna3MrRTFzOWRUcGRGUXZMNzZUdm9kcVN5XHJcbmwyRTJCZ2hWZ0xMZ2tkaFJuOWJ1YUZ6WXRhOTVKS2ZneUtHb25OeHNRQTM5UHdFQ1FRREtiRzBLcDZLRWtOZ0Jcclxuc3JDcTNDeDJvZDVPZmlQREc4ZzNSWVpLeFwvTzlkTXk1Q00xNjBEd3VzVkpwdXl3YnBSaGNXcjNna3owUWdSTWR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TREdzdDkyYTZ4Y0FlZEVcclxuYWRQMG5GWGhVeitjWVlJZ0ljZ2ZEY1gzWldlTkVGNWtzY3F5NTJrcEQyTzduRk5DVis4NXZTNGR1SkJOQWdNQlxyXG5BQUV3RFFZSktvWklodmNOQVFFTEJRQURnWUVBQ2oweGIrdE5ZRVJKa0wrcCt6RGNCc0JLNFJ2a25QbHBrK1lQXHJcbmVwaHVuRzJkQkdPbWdcL1dLZ29EMVBMV0QyYkVmR2dKeFlCSWc5cjF3TFlwREMxdHhoeFYrMk9CUVM4NktVTGgwXHJcbk5FY3IwcUVZMDVtSTRGbEUrRFwvQnBUXC8rV0Z5S2tadWc5MnJLMEZsejcxWHlcLzltQlhiUWZtK1lLNmw5cm9SWWRcclxuSjRzSGVRYz1cclxuLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLSIsImlkeCI6MX0=';
$cnf->loadConfigurationPackage($configurationPackage);

RSA Key pair

$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');


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();" 
}