depojones Posted September 13, 2008 Share Posted September 13, 2008 A request was made to develop a front and back end to process credit card transaction. We got the API from the credit card processing company. My question is, how do we go about developing the back end structure to communicate with the processing company. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted September 13, 2008 Share Posted September 13, 2008 that's a giant question. do you have anything specific you have a question about? Quote Link to comment Share on other sites More sharing options...
depojones Posted September 13, 2008 Author Share Posted September 13, 2008 How to use cURL to connect to the credit card processing website and return success or error message to the user on the front end. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 13, 2008 Share Posted September 13, 2008 Your CC processor likely has examples of how to use their API, given how important it is to make it work and work securely. Quote Link to comment Share on other sites More sharing options...
depojones Posted September 13, 2008 Author Share Posted September 13, 2008 @PFMA, They did provided us with <enMobileAPI>, but myself and my colleague are finding it difficult to send customer's credit card information from our server to theirs. Quote Link to comment Share on other sites More sharing options...
depojones Posted September 14, 2008 Author Share Posted September 14, 2008 Your CC processor likely has examples of how to use their API, given how important it is to make it work and work securely. They surely provided how to use their API. The question is, how do we use the information at hand. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted September 14, 2008 Share Posted September 14, 2008 They should also provide documentation on how to implement it. Perhaps contact them regarding this. Quote Link to comment Share on other sites More sharing options...
depojones Posted September 14, 2008 Author Share Posted September 14, 2008 They should also provide documentation on how to implement it. Perhaps contact them regarding this. Trust. We have contacted them and the only they provide us is a bunch of XML code without an actual process of communicating and ending data to their server. Please have a look at what they provided us. String msisdn = "27820001234"; String pin = "1234"; String amount = "100.00"; String cardPresent = "0"; String cardNumber = "4242424242424242"; String expiry = "1109"; String cvc = "123"; String reconReference = "recon ref"; String budgetPeriod = "00"; String reference = "test"; String clientTel = "27820001234"; String isTxManuallyAuthed = "0"; String autoSettle = "1"; String isThreeDSecure = "0"; String algorithm = "1"; String checksum = "12821821AAFEDD328328238923D2389329BBC"; String xml = "<OnlineLinQ>" + "<TxRequest>" + "<Msisdn>" + msisdn + "</Msisdn>" + "<PIN>" + pin + "</PIN>" + "<Amount>" + amount + "</Amount>" + "<CardEntry>" + "<CardPresent>" + cardPresent + "</CardPresent>" + "<Track2></Track2>" + "</CardEntry>" + "<CardNumber>" + cardNumber + "</CardNumber>" + "<ExpiryDate>" + expiry + "</ExpiryDate>" + "<CVC>" + cvc + "</CVC>" + "<ReconReference>" + reconReference + "</ReconReference>" + "<BudgetPeriod>" + budgetPeriod + "</BudgetPeriod>" + "<Reference>" + reference + "</Reference>" + "<ClientTel>" + clientTel + "</ClientTel>" + "<ManualAuth>" + "<IsTxManuallyAuthed>" + isTxManuallyAuthed + "</IsTxManuallyAuthed>" + "<ManualAuthCode></ManualAuthCode>" + "</ManualAuth>" + "<AutomaticSettlement>" + autoSettle + "</AutomaticSettlement>" + "<ThreeDSecure>" + "<IsThreeDSecured>" + isThreeDSecure + "</IsThreeDSecured>" + "<CAVV></CAVV>" + "<ECI></ECI>" + "<XID></XID>" + "</ThreeDSecure>" + "<Security>" + "<Algorithm>" + algorithm + "</Algorithm>" + "<Checksum>" + checksum + "</Checksum>" + "</Security>" + "</TxRequest>" + "</OnlineLinQ>"; Quote Link to comment Share on other sites More sharing options...
448191 Posted September 14, 2008 Share Posted September 14, 2008 Looks like a generic ASP.NET Webservice to me. Try simply writing the XML to an open stream (use curl or the socket functions), and see what the response is. You'd still need to know how to calculate that checksum though. Quote Link to comment Share on other sites More sharing options...
depojones Posted September 14, 2008 Author Share Posted September 14, 2008 I thought this would be as easy as creating a simple HTML form and encoding the form action to the CC processing server. But by the look of things, its getting way beyond my PHP/XML knowledge. @448191 ay i provide you with the API the company provided us with? Maybe you could detect what's going on there. Quote Link to comment Share on other sites More sharing options...
448191 Posted September 14, 2008 Share Posted September 14, 2008 I thought this would be as easy as creating a simple HTML form and encoding the form action to the CC processing server. But by the look of things, its getting way beyond my PHP/XML knowledge. @448191 ay i provide you with the API the company provided us with? Maybe you could detect what's going on there. I seriously doubt I could do this without full access to your code and a full API description. Even then it might take a full day to get it working. I'm sorry, but it looks like you're screwed. Quote Link to comment Share on other sites More sharing options...
depojones Posted September 14, 2008 Author Share Posted September 14, 2008 I thought this would be as easy as creating a simple HTML form and encoding the form action to the CC processing server. But by the look of things, its getting way beyond my PHP/XML knowledge. @448191 ay i provide you with the API the company provided us with? Maybe you could detect what's going on there. I seriously doubt I could do this without full access to your code and a full API description. Even then it might take a full day to get it working. I'm sorry, but it looks like you're screwed. I do not have any working code at the moment expect the HTML front end to capture the credit card information. Aside from this, i have a well detailed API configuration from our CC processing company. (Take a look at the file below.) [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
448191 Posted September 14, 2008 Share Posted September 14, 2008 Something like this should work. <?php $merchantAccountPhone = '27820001234'; $merchantAccountPin = '1234'; $cardNumber = '4242424242424242'; $exp = '1110'; $lastThreeNumbersOnBack = '123'; $amount = '100.00'; $merchantOrderNumber = 'recon ref'; $merchantInvoiceNumber = 'test'; $phone = '132456789'; $xmlRequest = <<<XML <enMobileAPI> <AuthorisationRequest msisdn="$merchantAccountPhone" pin="$merchantAccountPin"> <Amount>$amount</Amount> <CardPresent>false</CardPresent> <BudgetPeriod>00</BudgetPeriod> <CardNumber>$cardNumber</CardNumber> <ExpiryDate>$exp</ExpiryDate> <Cv2>$lastThreeNumbersOnBack</Cv2> <ReconReference>$merchantOrderNumber</ReconReference> <Reference>$merchantInvoiceNumber</Reference> <ClientTel>$phone</ClientTel> <AutomaticSettlement>true</AutomaticSettlement> </AuthorisationRequest> </enMobileAPI> XML; $fp = fsockopen("ssl://www.vwire.co.za", 443, $errno, $errstr, 30); if(!$fp) { trigger_error("$errstr ($errno)", E_USER_ERROR); } else { $out = "GET /vapp/XML-Landing2.jsp?xmlData=" . rawurlencode($xmlRequest) . " HTTP/1.1 \r\n"; $out .= "Host: www.vwire.co.za\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); $response = ''; while(!feof($fp)) { $response .= fgets($fp, 128); } fclose($fp); } echo $response; Quote Link to comment Share on other sites More sharing options...
depojones Posted September 14, 2008 Author Share Posted September 14, 2008 @448191 Should this file be my HTML form action. Like this; <form name="form1" action="the_file_you_created.php" method="post"> // HTML form design ( the front end to collect the credit card information) </form> Quote Link to comment Share on other sites More sharing options...
448191 Posted September 14, 2008 Share Posted September 14, 2008 Well, you still have to do some validation and retrieve the correct values from $_POST, but yes. Edit: but that code only outputs the response. You have to do something with it (like check if the transaction was successful). Oh, and I forgot to add ssl:// to the url, that's why it didn't work. Though I'm not getting back any data using these credentials. Quote Link to comment Share on other sites More sharing options...
depojones Posted September 14, 2008 Author Share Posted September 14, 2008 @448191 i can do the validation and retrieve the correct values as you have said. Let me run your script and feed you back. Thanks for your precious time. Quote Link to comment Share on other sites More sharing options...
depojones Posted September 14, 2008 Author Share Posted September 14, 2008 I ran your code on my server and this is what i received. HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Set-Cookie: JSESSIONID=49E5E564861316C95DC6ECC57C8CD444; Path=/vapp Content-Type: text/html;charset=UTF-8 Date: Sun, 14 Sep 2008 14:04:39 GMT Connection: close Quote Link to comment Share on other sites More sharing options...
448191 Posted September 14, 2008 Share Posted September 14, 2008 I know, that's what I got as well. The script works fine, it's just not getting any body. Which is odd, because commonly if something was wrong you would expect a response describing the error. Quote Link to comment Share on other sites More sharing options...
depojones Posted September 14, 2008 Author Share Posted September 14, 2008 so where do you think the problem is generating from??? Quote Link to comment Share on other sites More sharing options...
448191 Posted September 14, 2008 Share Posted September 14, 2008 The example XML that you posted doesn't match the one in the document. Which is it? Quote Link to comment Share on other sites More sharing options...
depojones Posted September 14, 2008 Author Share Posted September 14, 2008 After complaining to the CC processing company. They told us that they only program in Java and they can provide us with a similar method in deriving the XML request structure. Quote Link to comment Share on other sites More sharing options...
448191 Posted September 14, 2008 Share Posted September 14, 2008 You don't need code, you need a working API. They give you two completely different API's, now which one is it? Quote Link to comment Share on other sites More sharing options...
depojones Posted September 14, 2008 Author Share Posted September 14, 2008 The one in the attached document. Quote Link to comment Share on other sites More sharing options...
448191 Posted September 14, 2008 Share Posted September 14, 2008 Well, I don't know what to tell you then. I've build a little on that script, creating some small classes. It send this to their server by GET over SSL. This is in complete compliance with the API in the doc. <enMobileAPI> <AuthorisationRequest msisdn="27820001234" pin="1234"> <AutomaticSettlement>true</AutomaticSettlement> <BudgetPeriod>00</BudgetPeriod> <CardPresent>false</CardPresent> <ClientTel></ClientTel> <Reference></Reference> <CardNumber>4242424242424242</CardNumber> <Cv2>123</Cv2> <ExpiryDate>1110</ExpiryDate> <Amount>100.00</Amount> <ReconReference>123456798</ReconReference> </AuthorisationRequest> </enMobileAPI> Classes: <?php class LinqException extends Exception {} abstract class LinqRequest { protected $_data = array(); /** * Session * * @var LinqSession */ private $_session; public function setSession(LinqSession $session) { $this->_session = $session; } /** * get the Request session * * @return LinqSession */ public function getSession() { return $this->_session; } public function setClientTel($string) { $this->_data['ClientTel'] = $string; return $this; } public function setReference($string) { $this->_data['Reference'] = $string; return $this; } abstract public function asXml(); } class LinqRequestDefault extends LinqRequest { /** * Default data values * * @var unknown_type */ protected $_data = array( 'AutomaticSettlement' => 'true', 'BudgetPeriod' => '00', 'CardPresent' => 'false', 'ClientTel' => null, 'Reference' => null ); public function __construct($cardNumber, $cv2, $exp, $amount, $reconRef) { $this->_data['CardNumber'] = $cardNumber; $this->_data['Cv2'] = $cv2; $this->_data['ExpiryDate'] = $exp; $this->_data['Amount'] = $amount; $this->_data['ReconReference'] = $reconRef; } public function asXml() { $xml = "<AuthorisationRequest msisdn=\"{$this->getSession()->getMsisdn()}\" pin=\"{$this->getSession()->getPin()}\">"; foreach($this->_data as $key => $value) { $xml .= "<$key>$value</$key>"; } $xml .= "</AuthorisationRequest>"; return "<enMobileAPI>$xml</enMobileAPI>"; } } class LinqResponse { private $_raw; public function __construct($raw) { $this->_raw = $raw; } } class LinqSession { private $_msisdn; private $_pin; public function __construct($msisdn, $pin) { $this->_msisdn = $msisdn; $this->_pin = $pin; } public function getMsisdn() { return $this->_msisdn; } public function getPin() { return $this->_pin; } } class LinqGateway { private $_host; private $_location; private $_ssl; private $_port; /** * Reqeuest session * * @var LinqSession */ private $_session; public function __construct($host, $location, $ssl = true, $port = null) { $this->_host = $host; $this->_location = $location; $this->_ssl = $ssl; } public function startSession(LinqSession $session) { $this->_session = $session; } public function getHost() { return $this->_host; } public function getLocation() { return $this->_location; } public function getProtocol() { return $this->_ssl ? 'ssl' : 'tcp'; } public function getPort() { if($this->_port === null) { return $this->_ssl ? 443 : 80; } return $this->_port; } public function request(LinqRequest $request) { $fp = fsockopen("{$this->getProtocol()}://{$this->getHost()}", $this->getPort(), $errno, $errstr, 30); if(!$fp) { throw new LinqException("$errstr ($errno)"); } else { $request->setSession($this->_session); $out = "GET {$this->getLocation()}?xmlData=" . rawurlencode($request->asXml()) . " HTTP/1.1\r\n"; $out .= "Host: www.vwire.co.za\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); $response = ''; while(!feof($fp)) { $response .= fgets($fp, 128); } fclose($fp); } return new LinqResponse($response); } } Usage: <?php $gateway = new LinqGateway('www.vwire.co.za', '/vapp/XML-Landing2.jsp'); $gateway->startSession(new LinqSession('27820001234', '1234')); $request = new LinqRequestDefault('4242424242424242', '123', '1110', '100.00', '123456798'); $response1 = $gateway->request($request); var_dump(htmlspecialchars($request->asXml()), $response1); Maybe the given credentials are wrong? Quote Link to comment Share on other sites More sharing options...
448191 Posted September 14, 2008 Share Posted September 14, 2008 Actually I misread the doc. It says the request should be done by POST. I modified it and it works. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.