This resource is quite uncommon in Techblogs, the main reason why I have decided to startup my blog with this particular post.

Many a time, we are required to integrate a payment gateway, and sometimes we get to provide a request URL to capture data from Gateway Servers. But when the HTTP REQUEST method is POST and content type is TEXT/XML, and the we are unable to process this  with the usual $_POST[”] to get our post values and manipulate.

Before moving ahead, I may need to note that $_POST[”] will only return results for FORM-DATA and X-WWW-FORM-URLENCODED but not for APPLICATION/XML or TEXT/XML.

When we have to return results for TEXT/XML or APPLICATION/XML, then we may need to utilise SIMPLEXML to  get the NODE values from the result. In doing this, there are two simple lines of code we need to call.

$postData = file_get_contents(‘php://input’);

Please take note of the following assumptions for the script to be relevant:
The communication mode is HTTP POST (not SOAP)
The content type is text/xml.
The POST request will contain only XML
The request will be a RAW POST directly to stream and NOT in a parameter.
Here’s my php script to call results and return a response status of “0”.

$postData = file_get_contents(‘php://input’);
$xml = simplexml_load_string($postData);
$db->setQuery(Check if customer exists in database);
if($db->countResultset() == 0)
header("Content-type: text/xml");
echo "<?xml version=’1.0′ encoding=’UTF-8′?>";
echo "<CustomerInformationResponse>";
echo "<MerchantReference>".$merchRef."</MerchantReference>";
echo "<Customers>";
echo "<Customer>";
echo "<Status>0</Status>";
echo "<CustReference>".$custRef."</CustReference>";
echo "<FirstName/>";
echo "<LastName/>";
echo "<OtherName/>";
echo "<Email/>";
echo "<Phone/>";
echo "<ThirdPartyCode/>";
echo "<StatusMessage>Customer is valid</StatusMessage>";
echo "</Customer>";
echo "</Customers>";
echo "</CustomerInformationResponse>";

A sample of the HTTP POST REQUEST

[sourcecode language=”plain”]
<CustomerInformationRequest xmlns:ns2="" xmlns:ns3="">
<ServiceUrl>MY URL</ServiceUrl>

The expected response if properly implemented after data manipulation.

[sourcecode language=”plain”]
<MerchantReference>3527</MerchantReference >
<StatusMessage>Customer is Valid</StatusMessage>

Now, you may want to submit this data into a database or notify the customer via SMS when this transaction is captured.
This will be discussed in detail on my next post on “file_get_contents”.


About the Author

Bruno Otakhogbogie is the Founder and Board Chairman of XtraDot Technologies LLC, incorporated in 2011, even though he had earned a reputation from several innovative IT ventures since 2003. A graduate of Production Engineering, University of Benin; his core flair has been in Operations Research (OR) which has been evident in his approach to problem solving and creative consulting. His programming and design skills are unconventional, with profound understanding of several languages including Python, C, VBasic, Ruby, Java, PHP, amongst others. His advise has been sought by industry leaders both in Finance and in the IT industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

Premium WordPress Themes