Recurring Payments with MyPOS
NOTE: In order to process recurring payments you must enable the functionality first.
Please contact us with explanation why you need the functionality at: online@mypos.com
There are 2 different ways to introduce recurring payments.
1. Store a card with IPCPurchase, charge a stored card with IPCIAPurchase
If you call the IPCPurchase method with CardTokenRequest parameter set to “1” or “2”, your customer is first redirected to the myPOS hosted checkout page. You can use it for the following combinations:
- Store and verify a card without charging it (0 value charge)
- Store and verify a card after it is charged (customer pays and upon payment, a card token is returned in the response)
Available options:
0-CARD_TOKEN_REQUEST_NONE– Create regular payment without token request1-CARD_TOKEN_REQUEST_ONLY_STORE– Only token request without making payment2-CARD_TOKEN_REQUEST_PAY_AND_STORE– Make payment and create a token
Once you have a token using IPCPurchase, you can subsequently charge your customer by calling IPCIAPurchase with the CardToken parameter. This means your customer won’t be redirected to a myPOS hosted checkout page the second time.
If the card is 3D Secure, the first time the cardholder enters card data, they will be redirected to the issuing bank’s 3D Secure portal.
Store a card with payment
require_once './IPC/Loader.php';
$cnf = new \Mypos\IPC\Config();
$cnf->setIpcURL('https://mypos.com/vmp/checkout-test/');
$cnf->setLang('en');
$cnf->setVersion('1.4');
// WITH Configuration package
$configurationPackage = 'your-configuration-package';
$cnf->loadConfigurationPackage($configurationPackage);
$purchase = new \Mypos\IPC\Purchase($cnf);
$purchase->setUrlCancel('http://mysite.com/ipc_cancel'); // User comes here after purchase cancellation
$purchase->setUrlOk('http://mysite.com/ipc_ok'); // User comes here after purchase success
$purchase->setUrlNotify('https://mysite.com/ipc_notify'); // IPC sends POST request to this address with purchase status
$purchase->setOrderID(uniqid()); // Some unique ID
$purchase->setCurrency('EUR');
$purchase->setNote('Some note'); // Not required
// 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);
$purchase->setCart($cart);
$purchase->setCardTokenRequest(\Mypos\IPC\Purchase::CARD_TOKEN_REQUEST_PAY_AND_STORE);
$purchase->setPaymentParametersRequired(\Mypos\IPC\Purchase::PURCHASE_TYPE_SIMPLIFIED_PAYMENT_PAGE);
try {
$purchase->process();
} catch(\Mypos\IPC\IPC_Exception $ex) {
echo $ex->getMessage();
// Invalid params. To see details use "echo $ex->getMessage();"
}
Store card without Payment
To make only a token request without payment, set the appropriate value to setCardTokenRequest().
$cart object is unnecessary, so it may be skipped.
require_once './IPC/Loader.php';
$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);
$purchase = new \Mypos\IPC\Purchase($cnf);
$purchase->setUrlCancel('http://mysite.com/ipc_cancel');
$purchase->setUrlOk('http://mysite.com/ipc_ok');
$purchase->setUrlNotify('https://mysite.com/ipc_notify');
$purchase->setOrderID(uniqid());
$purchase->setCurrency('EUR');
$purchase->setCardTokenRequest(\Mypos\IPC\Purchase::CARD_TOKEN_REQUEST_ONLY_STORE);
$purchase->setPaymentParametersRequired(\Mypos\IPC\Purchase::PURCHASE_TYPE_SIMPLIFIED_PAYMENT_PAGE);
try {
$purchase->process();
} catch(\Mypos\IPC\IPC_Exception $ex) {
// Invalid params. To see details use "echo $ex->getMessage();"
}
Handle Token Notification (Notify URL)
Once the process is completed on myPOS site, your site will receive a Notify request containing confirmation data and token (if requested).
require_once './IPC/Loader.php';
$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);
try {
$response = \Mypos\IPC\Response::getInstance($cnf, $_POST, \Mypos\IPC\Defines::COMMUNICATION_FORMAT_POST);
} catch(\Mypos\IPC\IPC_Exception $e) {
echo 'Error';
}
$data = $response->getData(CASE_LOWER);
// $data is an array containing confirmation data and token (if requested)
2. Store a card with IPCIAPurchase, charge a stored card with IPCIAPurchase
If you want to store a card without your customer being redirected to the myPOS checkout hosted page, you have to host the checkout page at your side. As it is hosted on your side, you should also take care of the communication with the issuing bank’s ACS. The communication with issuing bank’s ACS happens through a so-called 3DS MPI (merchant plug-in).
We recommend this method only for PCI-SAQ D compliant merchants, as it involves serious dedication and it might not be feasible for smaller merchants. Obtaining the PCI SAQ D compliance might be a painful process.