ChrisNTR

Just another web developer weblog

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.

PHP:
  1. //Create new ePDQ object and populate values
  2. $epdq = new EPDQc();
  3. $epdq->setCardNumber($card_number);
  4. $epdq->setEndDate($card_end_month."/".$card_end_year);
  5. $epdq->setCvv2($card_cvv);
  6. $epdq->setTransactionType("Auth");
  7. $epdq->setAmount($total);
  8. $epdq->setOrderId($orderID);
  9. $epdq->setEmailAddress($email);
  10. $epdq->setStreet1($addr_1);
  11. $epdq->setPostalCode($addr_postcode);
  12.  
  13. //If the card is Maestro or Switch then populate these values too.
  14. if ($_REQUEST['card_switch_issue'] != ""
  15. && $card_type == "Maestro/Switch") {
  16. $epdq->setIssueNumber($card_switch_issue);
  17. }
  18. if($_REQUEST['card_start_month'] != ""
  19. && $_REQUEST['card_start_year'] != ""
  20. && $card_type == "Maestro/Switch") {
  21. $epdq->setStartDate($card_start_month. "/" .$card_start_year);
  22. }
  23.  
  24. if($epdq->getErrormessage != '') {
  25. // display your error
  26. } else {
  27. $epdq->ProcessTransaction();
  28.  
  29. unset($SUCCESS);
  30. unset($_REQUEST['SUCCESS']);
  31. $SUCCESS = false;
  32. $error = $epdq->getCcErrorCode();
  33. if ($errorcode != 1) {
  34. echo "ePDQ:ProcessTransaction():Payment Authorisation".
  35. "Failed - Please check you card details.";
  36. // handle failed txn here
  37. } else {
  38. $SUCCESS = true;
  39. }

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

13 Responses to Barclaycard ePDQ (MPI) with PHP (Online payments) »»

  1. Comment by Don | 2007/10/26 at 19:46:48

    Hi

    Do you have any sample PHP code for MPI? I mean full class

  2. Comment by ChrisNTR | 2007/10/26 at 20:10:41

    Hi Don,

    I think the best thing to do would be to get in touch with the people at Aqua Technologies Limited (linked above) since the class was bought from them and I’m not sure how much I can say about it. They are very useful with any questions you might have but essentially they are trying to sell their ePDQ class ‘product’.

    Hope this is O.K,

    Chris

  3. Comment by Lucy | 2007/10/27 at 20:10:41

    Wow, interesting stuff!

    Good work!

  4. Comment by Mark | 2008/03/18 at 07:10:21

    Thank you so much for this code.. I am working on a similar way to deal with transactions and this helped me out a bunch

  5. Comment by Durai | 2008/05/21 at 12:03:09

    Hi

    Do you have any full code for Barclays payment?

    I need to implement the Code from my Site.

  6. Comment by Ayya | 2008/05/22 at 08:11:20

    Hi Do you have any Barclays Payment (All Class File) Php Code?

  7. Comment by steve Conneely | 2008/06/07 at 04:34:22

    hi whats the monthly fee to use the epdq? machine and the transaction fee? As im trading via ebay and dont use paypal as it takes to long to transfer the funds to my bank account.

    Kind Regrds

    Steve

  8. Comment by Alli Price | 2008/08/07 at 17:19:22

    Hi Chris,

    I found this page through google and was wondering if you could clarify something for me, as I’m integrating via MPI also.

    Does this class work standalone, in a sense, not requiring input from any other code from Barclays, as some other Payment Gateways e.g. HSBC require you grab a hash from a script.

    So if I got this class, would all I need be the merchant account details etc?

    Thanks! :D

  9. Comment by ChrisNTR | 2008/08/09 at 12:22:23

    Hi Steve,
    I have no idea what the monthly fee is for using epdq - best be would be to give Barclay’s a call and ask them direct. Chances are it’s a lot more than just using ebay though.

    Good luck!
    Chris

  10. Comment by ChrisNTR | 2008/08/09 at 12:25:51

    Hi Alli,
    The class does work standalone, all you need to do is enter in you merchant details - send it over to Barclays and work out what response they send back to display a success or error message. I know HSBC use the “3D Secure” method which is horrible in terms of user interface and security but that way must be a horrible way of doing it. This in all works really nicely and integrates brilliantly with the site.

    Hope this helps,
    Chris

  11. Comment by Ed | 2008/08/29 at 19:21:49

    Hi Chris, I am trying to implement a CPI edpq into my site so that people can make online payments. Its not a store as such and is very similar to your work with the donation section, i.e the visitors enter how much they want to send.

    Any help or pointers would be very much appreciated!

    Cheers, Ed

  12. Comment by ChrisNTR | 2008/08/30 at 08:54:06

    Hi Ed,

    What sort of pointers are you after? Using the EPDQ class was very useful just to get an idea of what’s going on with the web service etc and it’s really easy to customise it.

    Let me know with anything I can help you with,

    Chris

  13. Comment by Ed | 2008/09/01 at 22:28:57

    Hi Chris, Is the class only for MPI? as I am using Barclaycards CPI system and won’t be handling the card details on the site.

    Thanks


Leave a Reply »»