...

View Full Version : PHP performing on XML response



kaidine
11-22-2011, 07:36 AM
I send off this:



<?php
$data = "<egateway>
<eCardExpiryMonth>01</eCardExpiryMonth>
<eCardExpiryYear>04</eCardExpiryYear>
<eCardHoldersName>Joe Bloke</eCardHoldersName>
<eCardNumber>4444333322221111</eCardNumber>
<eCVN>123</eCVN>
<eTotalAmount>100</eTotalAmount>
</egateway>
";
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $edata);
curl_setopt($ch, CURLOPT_URL, "https://www.example.com/gateway_cvn/testpage.asp");
curl_exec($ch);
curl_close($ch);
?>


In return, I get the following XML:



<eResponse>
<eTrxnStatus>True</eTrxnStatus>
<eTrxnNumber>20219</eTrxnNumber>
<eAuthCode>123456</eAuthCode>
<eReturnAmount>100</eReturnAmount>
<eTrxnError>00,Transaction Approved(Test CVN Gateway)</eTrxnError>
</eResponse>


Is there a way to make it so this does not show, and instead I can make PHP do something like:

if (eTrxnStatus == True) {// do stuff};

?

kaidine
11-22-2011, 10:53 AM
I'm using:



$response = simplexml_load_string(curl_exec($ch));
if ($response -> eTrxnStatus == 'True') {
echo "True 1111111111111.";
}


... but getting these errors:


PHP Warning:
simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found
simplexml_load_string(): 1
simplexml_load_string(): ^

PHP Notice: Trying to get property of non-object


The response code I am getting back in XML is:


<eResponse><eTrxnStatus>True</eTrxnStatus><eTrxnNumber>11673</eTrxnNumber><eTrxnReference/><eReturnAmount>100</eReturnAmount><eTrxnError>00,Transaction Approved(Test CVN Gateway)</eTrxnError></eResponse>


What could be causing this? I can't make any sense of it at all!

kaidine
11-22-2011, 11:07 AM
I solved the problem with:


curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum