Forum Moderators: coopster
The value of array[3] contains a number (300=approved, 301=approved with warning, 105&106=declined)
At the bottom of my code nothing gets displayed. Can someone help me with the switch/case thing or tell me what am I missing. Thank you
$res = `/usr/bin/curl -m 120 -d "$data" '$url' `;
$fp = fopen("ccdata.txt","w");
if(!$fp) {
print "error! The file could not be opened";
exit;
}
fwrite($fp, $res);
fclose($fp);
$fp = fopen('ccdata.txt', 'r');
if ($fp) {
$array = explode("\n", fread($fp, filesize('ccdata.txt')));
echo "Merchant messages:<br>";
echo "status: $array[2]<BR>";
echo "result: $array[3]<BR>";
switch ($array[3]){
case "300":
$Approved = true;
$Merr = false;
$MMessage = "Transaction Sucessfull";
break;
case "301":
$Approved = true;
$Merr = false;
$MMessage = "Transaction Sucessfull with warning";
break;
case "105":
$Approved = false;
$Merr = true;
$MMessage = "Declined";
break;
case "106":
$Approved = false;
$Merr = true;
$MMessage = "Declined";
break;
default:
$Approved = false;
$Merr = true;
}
if($Merr==true){
echo "result: $array[4]<BR>";
}else{
echo “declined”;
}
}
Note: After the above code excutes, the ccdata.txt file contains the following:
-----ccdata.txt starts here------
<?xml version="1.0" encoding="UTF-8"?>
- <response>
<status>2</status>
<result>300</result>
<msg>Approved</msg>
<error>no errors</error>
</response>
-----ccdata.txt ends here------
NOTE2:
$res variable gets populated from the result of [ $res = `/usr/bin/curl -m 120 -d "$data" '$url' `; ]
$url = "path to credit card processing server";
$data = "url.encode KEY=VALUE etc.";
$Merr = "some pre determend merchant error";
echo "declined"; statement. Why do you want to display a declined message when $Merr is false? In the switch() [php.net] statement you set $Merr to false when the transaction was successful, yet you echo() [php.net] a declined message :o.
Andreas
One question, is there anyway to capture the merchant result into an array without having to write it to ccdata.txt and reading it from ccdata.txt?
I am new to php and jumping from ASP windows to unix php is quite a thrill. PHP is a beautiful versatile language and free.
At my work, we are looking at the possibility to switch from win2000server asp to linux php due to the overwhelming cost of licensing and the cost of Microsoft products. So far, with my poor green php coding. The performance already beats Microsoft sql on win 2000 server.