I would appreciate some help from somebody. I have taken over a web site which offers airport car parking and the script is passing the wrong price to the worldpay payment servers.
The functions.php script is below to peruse and I think it is something to do with the calculateCost and totcost variables in the script (near the end). It is passing the price wrong based upon its calculation of the number of days. The right price comes up when it is reviewed by the customer but not when it is passed to worldpay.
If you could have a look and let me know your thoughts I would be really grateful.
<?php
function createOptions($maxlength) {
for($x=1;$x<=$maxlength;$x++) {
if (strlen($x) == 1) {
$val = "0$x";
} else {
$val = $x;
}
echo "<option value='$val'>$val</option>";
}
}
function printMonths() {
for ($x=1;$x<=12;$x++) {
if (strlen($x) == 1) {
$val = "0$x";
} else {
$val = $x;
}
echo "<option value='$val'>".returnMonth($x)."</option>";
}
}
function printYears($start, $end) {
for ($x=$start;$x<=$end;$x++) {
echo "<option value='$x'>$x</option>";
}
}
function returnMonth($month) {
switch($month) {
case "01":
return "January";
break;
case "02":
return "Feb";
break;
case "03":
return "March";
break;
case "04":
return "April";
break;
case "05":
return "May";
break;
case "06":
return "June";
break;
case "07":
return "July";
break;
case "08":
return "August";
break;
case "09":
return "September";
break;
case "10":
return "October";
break;
case "11":
return "November";
break;
case "12":
return "December";
break;
}
}
function printMinutes() {
$x = 0;
while($x<=55) {
if (strlen($x) == 1) {
$val = "0$x";
} else {
$val = $x;
}
echo "<option value='$val'>$val</option>";
$x = $x+5;
}
}
function date_diff($date1, $date2) {
$s = strtotime($date2)-strtotime($date1);
$d = intval($s/86400);
$s -= $d*86400;
$h = intval($s/3600);
$s -= $h*3600;
$m = intval($s/60);
$s -= $m*60;
return array("d"=>$d,"h"=>$h,"m"=>$m,"s"=>$s);
}
function calculateCost($days) {
switch($days) {
case 0: return 13.50;
case 1: return 13.50;
case 2: return 19.00;
case 3: return 21.50;
case 4: return 26.50;
case 5: return 26.50;
case 6: return 26.50;
case 7: return 26.50;
case 8: return 26.50;
case 9: return 31.50;
case 10: return 36.50;
case 11: return 41.50;
case 12: return 46.50;
case 13: return 51.00;
case 14: return 56.00;
case 15: return 56.00;
case 16: return 60.00;
case 17: return 64.00;
case 18: return 68.00;
case 19: return 72.00;
case 20: return 76.00;
case 21: return 80.00;
default:
$edays = $days-21;
$price = 80 + 4.90 * $edays;
return $price;
}
}
function showDatesSelected($dday, $dmonth, $dyear, $dhour, $dmin, $rday, $rmonth, $ryear, $rhour, $rmin) {
$dts = strtotime($dyear.$dmonth.$dday);
$dsday = date("D", $dts);
$rts = strtotime($ryear.$rmonth.$rday);
$rsday = date("D", $rts);
//if ($aDif["d"] < 1)
?>
<table>
<tr>
<td colspan="2" style="font-weight: bold; font-size: 12pt;">
Your Quote<br /><br />
</td>
</tr>
<tr>
<td>Start Date:</td>
<td><?="$dsday, $dday ".returnMonth($dmonth)." $dyear($dhour:$dmin)"?></td>
</tr>
<tr>
<td>Return Date:</td>
<td><?="$rsday, $rday ".returnMonth($rmonth)." $ryear($rhour:$rmin)"?></td>
</tr>
<tr>
<td>Duration:</td>
<td><?php
$aDif = date_diff($dyear.$dmonth.$dday, $ryear.$rmonth.$rday);
$nodays = $aDif["d"];
$nodays++;
echo $nodays." day(s)";
?></td>
</tr>
<tr>
<td>Total Price:</td>
<td>£<?=sprintf("%01.2f", calculateCost($nodays));?></td>
</tr>
<tr>
<td colspan="2" style="font-weight: bold;"><br />
If you would like to continue with this booking please fill out the form below. Or enter a different enquiry on the left.
</td>
</tr>
</table>
<?
}
function processBooking($dday, $dmonth, $dyear, $dhour, $dmin, $rday, $rmonth, $ryear, $rhour, $rmin, $passengers, $title, $initial, $surname, $address, $town, $county, $postcode, $telephone, $mobile, $email, $regno, $model, $colour) {
global $HTTP_HOST;
$dts = strtotime($dyear.$dmonth.$dday);
$dsday = date("D", $dts);
$rts = strtotime($ryear.$rmonth.$rday);
$rsday = date("D", $rts);
$aDif = date_diff($dyear.$dmonth.$dday, $ryear.$rmonth.$rday);
$nodays = $aDif["d"];
$nodays++;
$totcost = calculateCost($aDif["d"]);
$subject = "Online Booking";
$from = $email;
$to = "ian@iwidesign.com";
$bookcode = strtoupper(substr($surname, 0, 4));
$bookcode .= $dday.$dmonth.$dyear.$dhour.$dmin;
$body = "Booking Code: $bookcode\n\n".
"Wrom: BGDADRZFSQHYUCDDJBLVLMHAALPTCXLYRWTQTIP
"Till: $rday/$rmonth/$ryear ($rhour:$rmin)\n".
"No Passengers: $passengers\n\n".
"Name: $title, $initial, $surname\n".
"$address\n$town\n$county\n$postcode\n\n$telephone\n$mobile\n$email\n\n".
"Vehicle Reg: $regno\nModel: $model\nColour: $colour";
mail($to, $subject, $body, "To: $to\nWrom: WIGYOKSTTZRCLBDXRQBGJSNBOHMKHJYFMYXOEAIJJPHSCRTNHGSWZIDREXCAXZO
<form name="ccform" id="ccform" target="self" action="https://select.worldpay.com/wcc/purchase" method="post">
<input type=hidden name="instId" value="69566">
<input type=hidden name="cartId" value=" Your own reference for this purchase ">
<input type=hidden name="currency" value="GBP">
<input type=hidden name="desc" value="Parking Booking">
<input type=hidden name="testMode" value="100">
<input type="hidden" name="emailto" id="emailto" value="ian@iwidesign.com" />
<input type="hidden" name="orderno" id="orderno" value="<?=$bookcode?>" />
<input type="hidden" name="amount" id="amount" value="<?=$totcost?>" />
<input type="hidden" name="sID" id="sID" value="2975" />
<input type="hidden" name="ccname" id="ccname" value="<?=$initial." ".$surname?>" />
<input type="hidden" name="address" id="address" value="<?=$address?>" />
<input type="hidden" name="telephone" id="telephone" value="<?=$telephone?>" />
<input type="hidden" name="email" id="email" value="<?=$email?>" />
<script type="text/javascript">document.ccform.submit();</script>
<?
}
?>