i have a class which in which iam using a method to get information from a session array via a for loop the 2 for loops in each method are used 1.to count total amount of items , and 2. to add up the total
price but neither seem to be returning anything. im using the total amount to check it against the mc_gross posted value from an IPN and if the values are equal i plan to commit the sale to a database as it has been verified. for the method where im looking to get the total
price im getting 0.00 returned to me. i think ive got the syntax wrong here somehow here is my class for purchase the two methods iam having trouble with are the gettotalcost() and gettotalitems() shown below is my class.
<?php
class purchase {
private $itemnames; // from session array
private $amountofitems; // from session array
private $itemcost; //session array
private $saleid; //posted transaction id value to be used in sale and sale item tables
private $orderdate; //get current date time to be entered as datetime in sale table
private $lastname; //posted from ipn
private $firstname; //posted from ipn
private $emailadd; //uses sessionarray value
public function __construct($saleid,$firstname,$lastname)
{
$this->itemnames = $_SESSION['itemnames'];
$this->amountofitems =$_SESSION['quantity'];
$this->itemcost =$_SESSION['
price'];
$this->saleid = $saleid;
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->emailadd = $SESSION['username'];
mail($myemail, "session vardump ", echo var_dump($_SESSION), "From:
[email protected]" );
mail($myemail, "session vardump ",count($_SESSION['itemnames']) , "From:
[email protected]" );
}
public function commit()
{
$databaseinst = database::getinstance();
$databaseinst->connect();
$numrows = $databaseinst->querydb($query);
//to be completed
}
public function gettotalitems()
{
$numitems;
$i;
for($i=0; $i < count($this->amountofitems);$i++)
{
$numitems += (int) $this->amountofitems[$i];
}
return $numitems;
}
public function gettotalcost()
{
$totalcost;
$i;
for($i=0; $i < count($this->amountofitems);$i++)
{
$numitems = (int) $this->amountofitems[$i];
$costofitem =doubleval($this->itemcost [$i]);
$totalcost += $numitems * $costofitem;
}
return $totalcost;
}
}
?>
and here is where i create an instance of the class and attempt to use it.
include("purchase.php");
$purchase = new purchase($_POST['txn_id'],$_POST['first_name'],$_POST['last_name']);
$fullamount = $purchase->gettotalcost();
$fullAmount = number_format($fullAmount, 2);
$grossAmount = $_POST['mc_gross'];
if ($fullAmount != $grossAmount) {
$message = "Possible
Price Jack attempt! the amount the customer payed is : " . $grossAmount .
" which is not equal to the full amount. the
price of the products combined is " . $fullAmount. "
the transaction number for which is " . $_POST['txn_id'] . "\n\n\n$req";
mail("XXXXXXXXXXXX", "
Price Jack attempt ", $message, "From:
[email protected]" );
exit(); // exit
}
thanks for the help in advance!
ive also added these lines to my constructor. the mail returns that there is nothing in the vardump uh oh!
mail($myemailaddress, "session vardump ", var_dump($_SESSION), "From:
[email protected]" );
also added
session_start();
at the top of the constructor and it dont work! help