depojones Posted September 14, 2008 Author Share Posted September 14, 2008 I changed this $out = "GET /vapp/XML-Landing2.jsp?xmlData=" . rawurlencode($xmlRequest) . " HTTP/1.1 \r\n"; TO: $out = "POST /vapp/XML-Landing2.jsp?xmlData=" . rawurlencode($xmlRequest) . " HTTP/1.1 \r\n"; And it outputted: HTTP/1.1 411 Length Required Content-Type: text/html Date: Sun, 14 Sep 2008 15:58:47 GMT Connection: close Content-Length: 24 Length Required Quote Link to comment Share on other sites More sharing options...
448191 Posted September 14, 2008 Share Posted September 14, 2008 This works. It doesn't interpret the response though: <?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, 'ManualAuthorisationCode' => null, '3dSecureCavv' => null, '3dSecureECI' => null, '3dSecureXID' => null, 'Track2' => 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; private $_xml; public function __construct($raw) { $this->_raw = $raw; } public function getRaw() { return $this->_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); $body = "xmlData=" . rawurlencode($request->asXml()); $lines = array( "POST {$this->getLocation()} HTTP/1.1", "Host: www.vwire.co.za", "Content-Type: text/html", "Content-Length: " . strlen($body), '', '', $body ); fwrite($fp, implode("\r\n", $lines)); $response = ''; while(!feof($fp)) { $response .= fgets($fp, 128); } fclose($fp); } return new LinqResponse($response); } } $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'); $response = $gateway->request($request); echo(htmlspecialchars($response->getRaw())); Quote Link to comment Share on other sites More sharing options...
depojones Posted September 14, 2008 Author Share Posted September 14, 2008 This works. It doesn't interpret the response though: <?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, 'ManualAuthorisationCode' => null, '3dSecureCavv' => null, '3dSecureECI' => null, '3dSecureXID' => null, 'Track2' => 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; private $_xml; public function __construct($raw) { $this->_raw = $raw; } public function getRaw() { return $this->_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); $body = "xmlData=" . rawurlencode($request->asXml()); $lines = array( "POST {$this->getLocation()} HTTP/1.1", "Host: www.vwire.co.za", "Content-Type: text/html", "Content-Length: " . strlen($body), '', '', $body ); fwrite($fp, implode("\r\n", $lines)); $response = ''; while(!feof($fp)) { $response .= fgets($fp, 128); } fclose($fp); } return new LinqResponse($response); } } $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'); $response = $gateway->request($request); echo(htmlspecialchars($response->getRaw())); I run this code and this is what i got HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Set-Cookie: JSESSIONID=C4916509F667DD79295D8A63197F6062; Path=/vapp Content-Type: text/html;charset=UTF-8 Transfer-Encoding: chunked Date: Sun, 14 Sep 2008 16:11:24 GMT 19e <enMobileAPI> <AuthorisationResponse> <ResponseCode></ResponseCode> <ResponseDescription></ResponseDescription> <ResponseReference></ResponseReference> <ResponseDate></ResponseDate> <ReconReference>null</ReconReference> <RootTransactionID>null</RootTransactionID> <AmountSettled>false</AmountSettled> </AuthorisationResponse> </enMobileAPI> 0 Quote Link to comment Share on other sites More sharing options...
448191 Posted September 14, 2008 Share Posted September 14, 2008 Yes, as I said, it doesn't interpret the XML response. But, since I already went way overboard on this one, I did that for you as well: <?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, 'ManualAuthorisationCode' => null, '3dSecureCavv' => null, '3dSecureECI' => null, '3dSecureXID' => null, 'Track2' => 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; private $_xml; private $_dom; public function __construct($raw) { $this->_raw = $raw; } public function getRaw() { return $this->_raw; } public function getXml() { if($this->_xml === null) { $this->_xml = preg_replace('/^.*(<enMobileAPI\\>(.*)\\<\/enMobileAPI>).*$/sm', '$1', $this->getRaw()); } return $this->_xml; } public function getDomDoc() { if($this->_dom === null) { $this->_dom = new DOMDocument(); $this->_dom->loadXML($this->getXml()); } return $this->_dom; } public function get($key) { $nodeList = $this->getDomDoc()->getElementsByTagName($key); if($nodeList->length === 0) { return null; } elseif($nodeList->length > 1) { throw new LinqException('Ambigous key'); } return $nodeList->item(0)->nodeValue; } } 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); $body = "xmlData=" . rawurlencode($request->asXml()); $lines = array( "POST {$this->getLocation()} HTTP/1.1", "Host: www.vwire.co.za", "Content-Type: text/html", "Content-Length: " . strlen($body), '', '', $body ); fwrite($fp, implode("\r\n", $lines)); $response = ''; while(!feof($fp)) { $response .= fgets($fp, 128); } fclose($fp); } return new LinqResponse($response); } } $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'); $response = $gateway->request($request); echo $response->get('AmountSettled'); Quote Link to comment Share on other sites More sharing options...
depojones Posted September 14, 2008 Author Share Posted September 14, 2008 Superb thank you to 448191 for your time and knowledge. I believe i get what is happening here now. When i run your last script you provided, i got 0 after this closing tag </enMobileAPI>. I believe its displaying the amount charged. Let me just give you a clue about what we are achieving. A customer provides his/her credit card information over the telephone and our sales assistance login to our secure system with a username and password. They enter the credit card details electronically and press the submit button. This is sent to our Credit card processing server for charging. If the credit card is not valid, it should return error else, there should be a successful message. My final question is, in my html form, should there be an input for amount to be deducted from the credit card, which i believe so. If yes, do i need to assign a specific names to all the input from the front end like this; Card holder's name --------- <input name="?" type="text" size="25"> Credit card number --------- <input name="?" type="text" size="25"> CV2 --------- <input name="?" type="text" size="5" maxlenght="5"> Amount to charge ---------- <input name="?" type="text" size="15"> Then Submit. Or i can assign any name for all the input boxes. Thanks in advance Quote Link to comment Share on other sites More sharing options...
448191 Posted September 14, 2008 Share Posted September 14, 2008 Superb thank you to 448191 for your time and knowledge. I believe i get what is happening here now. When i run your last script you provided, i got 0 after this closing tag </enMobileAPI>. I believe its displaying the amount charged. Let me just give you a clue about what we are achieving. A customer provides his/her credit card information over the telephone and our sales assistance login to our secure system with a username and password. They enter the credit card details electronically and press the submit button. This is sent to our Credit card processing server for charging. If the credit card is not valid, it should return error else, there should be a successful message. My final question is, in my html form, should there be an input for amount to be deducted from the credit card, which i believe so. If yes, do i need to assign a specific names to all the input from the front end like this; Card holder's name --------- <input name="?" type="text" size="25"> Credit card number --------- <input name="?" type="text" size="25"> CV2 --------- <input name="?" type="text" size="5" maxlenght="5"> Amount to charge ---------- <input name="?" type="text" size="15"> Then Submit. Or i can assign any name for all the input boxes. Thanks in advance Check the doc. It has all the info you need to interpret the response. if($response->get('AuthorisationResponse') !== 'Approved') { //Authorisation not granted } if($response->get('AmountSettled') === 'false') { //Amount not charged from creditcard } Oh, and you make out the check to '448191 International - att. John Kleijn, president/CEO'. Sorry, little in-joke. Quote Link to comment Share on other sites More sharing options...
depojones Posted September 14, 2008 Author Share Posted September 14, 2008 This is how my HTML form looks like <form name="cardone" action="the_file_you_created.php" method="post"> <table width="490" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="25" height="35"> </td> <td width="114"> </td> <td width="20"> </td> <td width="15"> </td> <td width="148"> </td> <td width="45"> </td> <td width="123"> </td> </tr> <tr> <td height="31"> </td> <td valign="top">Card Number </td> <td> </td> <td colspan="3" valign="top"><label> <input name="CardNumber" type="text" id="CardNumber" /> </label></td> <td> </td> </tr> <tr> <td height="24"> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td height="28"> </td> <td valign="top">Expiry date </td> <td> </td> <td colspan="3" valign="top"><input name="month" type="text" id="month" size="5" maxlength="2" /> <input name="year" type="text" id="year" size="5" maxlength="2" /></td> <td> </td> </tr> <tr> <td height="26"> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td height="31"> </td> <td valign="top">CV2</td> <td> </td> <td colspan="3" valign="top"><input name="cvv" type="text" id="cvv" size="8" maxlength="5" /></td> <td> </td> </tr> <tr> <td height="16"></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td height="25"></td> <td valign="top">Amount to charge </td> <td></td> <td colspan="3" valign="top"><input name="amount_to_charge" type="text" id="amount_to_charge" size="15" /></td> <td></td> </tr> <tr> <td height="23"></td> <td> </td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td height="28"></td> <td></td> <td></td> <td> </td> <td valign="top"> <input name="submit" type="submit" value="Process"> </td> <td> </td> <td></td> </tr> </table> </form> Where do i need to interpret the response 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.