Prev | Current Page 740 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"


CHAPTER 20 ?–  PROCESSING CREDIT CARD TRANSACTIONS 635
?– Note If you want to see exactly which elements are mandatory and which are optional for each kind of
request, check the XML API frequently asked questions document from DataCash.
The next kind of request we must be able to make to the DataCash system is a fulfill request. The XML for this kind
of request is prepared in the MakeXmlFulfill() method.
We then have the GetRequest() method that returns the last XML document built by either MakeXmlPre() or
MakeXmlFulfill():
// Get the current XML
public function GetRequest()
{
return $this->_mXml;
}
Finally, the GetResponse() method actually sends the latest XML request file, built by a call to either MakeXmlPre()
or MakeXmlFulfill() and returns the response XML. Let??™s take a closer look at this method.
GetResponse() starts by initializing a cURL session and setting the POST method to send your data:
// Send an HTTP POST request to DataCash using cURL
public function GetResponse()
{
// Initialize a cURL session
$ch = curl_init();
// Prepare for an HTTP POST request
curl_setopt($ch, CURLOPT_POST, 1);
// Prepare the XML document to be POSTed
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->_mXml);
// Set the URL where we want to POST our XML structure
curl_setopt($ch, CURLOPT_URL, $this->_mUrl);
/* Do not verify the Common name of the peer certificate in the SSL
handshake */
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
// Prevent cURL from verifying the peer's certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
To return the transfer into a PHP variable, we set the CURLOPT_RETURNTRANSFER parameter to 1, send the
request, and close the cURL session:
/* We want cURL to directly return the transfer instead of
printing it */
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
CHAPTER 20 ?–  PROCESSING CREDIT CARD TRANSACTIONS 636
// Perform a cURL session
$result = curl_exec($ch);
// Close a cURL session
curl_close ($ch);
// Return the response
return $result;
}
The test_datacash.


Pages:
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752
Pozycjonowanie sklep obrączki ślubne kraków imprezy integracyjne warszawa włosy