and it also didn't work plus it stop the process half way meaning it got stuck right on the sim.php file but it doesn't show the payment process page.
So it does go across to the payment gateway - just fails to process?
also to explain listItems function better:
$input = array();//create array to store data
while($row = mysql_fetch_array($result)){//loop through all items in the cart
$input[] = array($row['itemId'],$row['itemName'],$row['qty']);
//add the data we want for each item into the array
}
//send the data needed in the listItems function to work out what the costs are
$cartdata = listItems($input,$_POST['country'],$sstat);
my listItems function is out of date from yours but should be similar enough to get the idea, that data is then passed to this function:
function listItems($input,$ship_country,$taxcode){
//3 variables expected when you call listItems
//$input = array - itemid, itemname & quantities to work out the costs of
//$ship_country = string - the country worked out in shipping
//$taxcode = string - the taxes to be applied to this cart
//CONFIG ARRAY
$foods = getFoodArray();//get item prices and which category the item is in
$foodKeyArray = getFoodKeyArray();//dont need this anymore
//VARIABLES
$running = array('fruit'=>0,'vegetable'=>0);//define var running total of sales cost
$output = array('fruit'=>'','vegetable'=>'');//define var html output
$tax = array('fruit'=>0,'vegetable'=>0);//define var tax
//LOOP THROUGH INPUT
foreach($input as $item){//loop through the items in $input (the cart)
$key = $item[0];//set $key = first value in array (the itemid)
$qty = $item[1];//set $qty = second value in array (the quantity)
if(isset($foods['fruit']['items'][$key]) || isset($foods['vegetable']['items'][$key])){
//if itemid exists in $foods
$type = (isset($foods['fruit']['items'][$key])) ? 'fruit' : 'vegetable';
//if exists in fruit, type is fruit else it is a vegetable
$unit = $foods[$type]['items'][$key];
//$unit = the value set in the getFoodArray() function
/*from getFoodArray() -> $foods[$row['cat']]['items'][$row['itemId']] = $row['some_number'];*/
$cost = number_format($qty * $unit,2);
//$cost = the quantity of the item times $unit
$output[$type] .= "<tr><td>$foodKeyArray[$key]</td><td>$qty</td><td>$unit</td><td class=\"right\">$cost</td></tr>";
//add html row to display in the cart
$running[$type] += $cost;//$add the cost of this item*quantity to the running total of this type(fruit or veg)
}
}
//loop finished, all the items costs added to running total
//DO TOTALS FOR OUTPUT
//1) Tax
$tax['fruit'] = getTax($taxcode, 'Fruit', $running['fruit']);
//get the tax for the total fruit cost
$fruit_tax_label = (($tax['fruit']/$running['fruit'])*100).'%';
//work out the tax % applied to the fruit
$tax['vegetable'] = getTax($taxcode, 'vegetable', $running['vegetable']);
//get the tax for the total veg cost
$vegetable_tax_label = (($tax['vegetable']/$running['vegetable'])*100).'%';
//work out the tax % applied to the veg
$total_tax = $tax['fruit'] + $tax['vegetable'];
//$total_tax = fruit tax + veg tax
//2) Sales Total
$total_sales = $running['vegetable'] + $running['fruit'];
//$total_sales = total beg cost + total fruit cost (no tax)
//3) Shipping
//use $ship_country and $total_sales to work out the shipping
$domestic = array('United States');
if(in_array($ship_country,$domestic)){
//----------Domestic Shipping--------------//
if ($total_sales > 0 && $total_sales <= 100){$ship = 6.50;}
if ($total_sales > 100 && $total_sales <= 300){$ship = 10.50;}
if ($total_sales > 300 && $total_sales <= 500){$ship = 14.00;}
if ($total_sales > 500 && $total_sales <= 700){$ship = 18.00;}
if ($total_sales > 700 && $total_sales <= 1000){$ship = 20.00;}
if ($total_sales > 1000){$ship = 25.00;}
}else{
//----------International Shipping--------------//
if ($total_sales > 0 && $total_sales <= 100){$ship = 30.00;}
if ($total_sales > 100 && $total_sales <= 300){$ship = 35.00;}
if ($total_sales > 300 && $total_sales <= 500){$ship = 40.00;}
if ($total_sales > 500 && $total_sales <= 700){$ship = 45.00;}
if ($total_sales > 700 && $total_sales <= 1000){$ship = 50.00;}
if ($total_sales > 1000){$ship = 50.00;}
}
//4) Bill Total
$total_bill = $total_sales + $total_tax + $ship;
//$total_bill = $total_sales + $total_tax + $ship
//BUILD TOTAL HTML
//display this worked out data in a html table
$total =
"<tr><td colspan=\"4\"><hr /></td></tr>
<tr><td colspan=\"3\">Total Fruits</td><td class=\"right\">" . number_format($running['fruit'], 2) . "</td></tr>
<tr><td colspan=\"3\">Total Vegetables</td><td class=\"right\">" . number_format($running['vegetable'],2) . "</td></tr>
<tr><td colspan=\"3\">Total Sales</td><td class=\"right\">" . number_format($total_sales,2) . "</td></tr>
<tr><td colspan=\"3\">Shipping Cost</td><td class=\"right\">" . number_format($ship,2) . "</td></tr>
<tr><td colspan=\"4\"><hr /></td></tr>
<tr><td colspan=\"3\">Fruit Tax @ $fruit_tax_label</td><td class=\"right\">" . number_format($tax['fruit'], 2) . "</td></tr>
<tr><td colspan=\"3\">Vegetable Tax @ $vegetable_tax_label</td><td class=\"right\">" . number_format($tax['vegetable'], 2) . "</td></tr>
<tr><td colspan=\"3\">Total Tax</td><td class=\"right\">" . number_format($total_tax, 2) . "</td></tr>
<tr><td colspan=\"4\"><hr /></td></tr>
<tr><td colspan=\"3\">Total Bill</td><td class=\"right\">" . number_format($total_bill, 2) . "</td></tr>";
$returndata = array();create array to return data to the script that called it
$returndata['html'] = "<tr><th>ITEM</th><th>QTY</th><th>UNIT/\$</th><th>COST/\$</th></tr>" . $output['fruit'] . $output['vegetable'] . $total;
//$returndata['html'] = the html to show the contents of the cart worked out previously
$returndata['veg_tax_label'] = $vegetable_tax_label;
//the tax % for veg
$returndata['fruit_tax_label'] = $fruit_tax_label;
//the tax % for fruit
$returndata['shipping'] = $ship;
//$returndata['shipping'] = the shipping for this cart, as worked out above
$returndata['totaltax'] = $total_tax;
//$returndata['totaltax'] = the tax for this cart, as worked out above
$returndata['totalsales'] = $total_sales;
//$returndata['totalsales'] = the sales cost for this cart(no tax), as worked out above
$returndata['totalbill'] = $total_bill;
//$returndata['totalbill'] = the sales cost + tax + shipping for this cart, as worked out above
return $returndata;//return the array $returndata for use by the calling script
}
now we are back into checkout2.php
$cartdata = listItems($input,$_POST['country'],$sstat);
//$cartdata = $returndata from the function, eg. $cartdata['totalbill'] == $returndata['totalbill']
$totalCost += $cartdata['totalsales'];
//$totalCost = the total sales cost of the cart
$ship = $cartdata['ship'];
//$ship = the shipping cost of the cart
$taxx = $cartdata['taxx'];
//$taxx = the total tax of the cart
//----------store important values in session--------------//
$_SESSION['tcost'] = $totalCost;//store it in the session
$_SESSION['ship'] = $ship;//store it in the session
$_SESSION['taxx'] = $taxx;//store it in the session
//----------store important values in session--------------//
echo $cartdata['html'];//print out the html to show the cart
as you can see it is doing the same thing yours did, the only question i have is has this line been corrected in getFoodArray() $foods[$row['cat']]['items'][$row['itemId']] = $row['some_number'];
but when i asked you this bit earlier:
This what it dump, it's duplicated
string(36) "SELECT * from orders where id = 2255"
array(46) {
[0]=>
string(4) "2255"
["id"]=>
string(4) "2255"
[1]=>
string(4) "3348"
["cust_id"]=>
string(4) "3348"
[2]=>
NULL
["user"]=>
NULL
[3]=>
string(6) "186.50"
["cart_total"]=>
string(6) "186.50"
[4]=>
string(4) "10.5"
["shipping"]=>
string(4) "10.5"
[5]=>
string(2) "no"
["express"]=>
string(2) "no"
[6]=>
string(8) "Jonny"
["s_first"]=>
string(8) "Jonny"
[7]=>
string(7) "LAst"
["s_last"]=>
string(7) "LAst"
i saw the cart_total is being saved OK so there isn't anything wrong on checkout2.php, it's doing exactly what its supposed to(though you didnt post everything i assume its in), the error must be further along if it contains all the data required for authorise.net to process an order.
btw the duplication comes from using mysql_fetch_array()
, it returns the data as a number and as the column name, if you just want the column name use mysql_fetch_assoc()
or just numbers use mysql_fetch_array($res,MYSQL_NUM);