Barclaycard ePDQ (MPI) with PHP (Online payments)
For the last two or so weeks I have been working on donation section for a client at work. What they needed was a way to take online payments/donations through a Barclaycard merchant account. The MPI ePDQ is a way of seemlessly using the Barclays system without re-directing a user to their site at all. This gives an overall better user experience and can stop users from leaving the page after a successful payment. CPI is the other which is a paypal like integration of a payments system which allows custom colours and a custom image but is generic for all sites. Using MPI, originally, the only way to communicate with this system was to either use C (yup, C, not C++...) or Java. As we both know, C is an old old language and Java has not really taken off as well on the web as other technologies. Although it seems most financial websites seem to use Java Script Pages (jsp), most other small business don't which left them stuck.
Recently Barclaycard have opened up a XML API which really is just a way for a web developer to send a formed XML document over to Barclaycard for them to process on their side. The Barclaycard site does include some documents on what you can put into a XML document but doesn't really say what is required at all.
A way of implementing this within PHP was to use a custom ePDQ class created by Aqua Technologies Limited. What this does is basically take out all the fiddly bits which allows to concentrate on how you want to handle the transaction when it comes back. A few things to look out for if you use this path is that although the ePDQ class is very useful, it was not bug proof and still contained typos on variable names and broken logic checking on some passed in variables such as the post code. As side from this, the ePDQ is a useful class which creates an object with all your customer details and your merchant store details and creates the needed XML for you. So with a 600 line class you can cut down the amount of lines needed to validate and send credit card details off to Barclaycard.
-
//Create new ePDQ object and populate values
-
$epdq = new EPDQc();
-
$epdq->setCardNumber($card_number);
-
$epdq->setEndDate($card_end_month."/".$card_end_year);
-
$epdq->setCvv2($card_cvv);
-
$epdq->setTransactionType("Auth");
-
$epdq->setAmount($total);
-
$epdq->setOrderId($orderID);
-
$epdq->setEmailAddress($email);
-
$epdq->setStreet1($addr_1);
-
$epdq->setPostalCode($addr_postcode);
-
-
//If the card is Maestro or Switch then populate these values too.
-
if ($_REQUEST['card_switch_issue'] != ""
-
&& $card_type == "Maestro/Switch") {
-
$epdq->setIssueNumber($card_switch_issue);
-
}
-
if($_REQUEST['card_start_month'] != ""
-
&& $_REQUEST['card_start_year'] != ""
-
&& $card_type == "Maestro/Switch") {
-
$epdq->setStartDate($card_start_month. "/" .$card_start_year);
-
}
-
-
if($epdq->getErrormessage != '') {
-
// display your error
-
} else {
-
$epdq->ProcessTransaction();
-
-
$SUCCESS = false;
-
$error = $epdq->getCcErrorCode();
-
if ($errorcode != 1) {
-
echo "ePDQ:ProcessTransaction():Payment Authorisation".
-
"Failed - Please check you card details.";
-
// handle failed txn here
-
} else {
-
$SUCCESS = true;
-
}
As simple as that! And of course you can modify the class to you specific needs if you have some extra validation that you need to have or what not. I would be quite interested to see what asp.net has in the way of dealing with ePDQ transactions. I'm sure it would be rather simple to create, especially if you use linq but has it actually been done yet?
I will probably be covering payments using Paypal in the near future which is a different kettle of fish completely.
I hope this helps out someone needing some PHP ePDQ developer help and feel free to contact me for more information,
ChrisNTR