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
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!';

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.