Jump to content

PHP performing on XML response


Noonga

Recommended Posts

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};

 

?

Link to comment
https://forums.phpfreaks.com/topic/251596-php-performing-on-xml-response/
Share on other sites

Would be easy with SimpleXML:

 

$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');
$xml = simplexml_load_string(curl_exec($ch));

if ($xml->eTrxnStatus == 'True')
   echo 'It\'s true!';
else
   echo 'It\'s false!';

Joel,

 

That wouldn't help because I would not be able to set variables on the page being sent to me. Thanks anyway though. :)

 

 

silkfire. Thanks for that mate. I'll start reading into that string now to see how it works exactly.

 

Do you know how I can hide the response XML?

I tried this, but am getting the same result as before. Have I mucked up?

 

$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');
$response = simplexml_load_string(curl_exec($ch));
if ($response -> eTrxnStatus == 'True') {
	echo "True 1111111111111.";
}
curl_exec($ch);
curl_close($ch);
?>

Yeah, I noticed the double execution myself and removed it. :)

I close $ch with curl_close() because that is how curl_close() is used in the PHP manual.

 

Correct, the echo is not working. all I see is the output response (the XML).

 

I am getting these issues in my error log:

 

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

Oh Dear. Thats what I thought aswell! This is the response I get:

 

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

 

What could be wrong with it?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.