2012-03-22 23 views
0

我有一個類中使用一種方法來得到一個會話陣列信息的IAM通過一個for循環2使用每種方法中的循環1.計算物品的總量,2.將總價加起來,但似乎都沒有返回任何東西。即時通訊使用總金額來檢查它從IPN的mc_gross發佈的價值,如果這些值是相等的,我計劃將銷售提交到數據庫,因爲它已被驗證。對於即時獲得總價格即時得到0.00返回給我的方法。我認爲我的語法錯在這裏不知何故這裏是我的類購買兩種方法IAM有麻煩的是下面顯示的gettotalcost()和gettotalitems()是我的類。

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







} 

?> 

這裏是我創建類的一個實例,並嘗試使用它。

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 

    } 

感謝您的幫助!

我也將這些行添加到我的構造函數中。郵件返回,vardump中沒有任何東西哦!

mail($myemailaddress, "session vardump ", var_dump($_SESSION), "From: [email protected]"); 

還添加
在session_start();

在構造函數的頂部,它不工作!幫助 好吧,我得到了vardump打印在一個單獨的PHP頁面,它給了我這個。 (9){[「token」] => string(32)「964885a70512d21933d139663a8fe48a」[「ID」] => string(19)「XXXXXXXX」[「username」] => string(19)「XXXXXX 「[」password「] => string(5)」XXX「[」admin「] => string(1)」0「[」set「] => string(4)」true「[」itemnames「] => [3] => string(30)「Naomh Ciaran:Pilgrim Islander」[2] => string(35)「(3){[0] => string(43) O Driscolls:Past and Present(2005)「} [」quantity「] => array(3){[0] => int(2)[1] => string(1)」1「[2] => string (1)「1」} [「price」] => array(3){[0] => string(5)「12.73」[1] => string(5)「23.99」[2] => string 5)「11.76」}}

+0

你確定在創建類的時候$ _SESSION值設置正確並且會話已經啓動了嗎? – 2012-03-22 10:16:23

+0

你爲什麼要寫「$ totalcost; $ i;」和「$ numitems; $ i;」明確地在函數中? – 2012-03-22 10:26:02

+0

@OM永恆的東西只是我習慣用java來完成的方式。 – eoin 2012-03-22 11:03:52

回答

0

好嗎這裏就是答案,IPN不會處理會話變量,因爲我離開我的網站處理事務,所以我必須將它們保存到我的數據庫,然後如果所有檢查都通過我的IPN腳本,我可以將事務標記爲在我的數據庫中使用一個獨特的交易號碼,我將創建一個自定義變量,我將傳遞給貝寶。如果檢查失敗,我會郵寄()購買商品的人,並使用相同的唯一交易號刪除他們,我將從paypal作爲ipn自定義變量返回。哇,stackoverflow通常比這更好的幫助,也許我的問題有點太模糊!

0

您必須在session_start();之前開始會話

嘗試打印一個numItems和TOTALCOST變量有函數本身調試......

+0

會話數組全部創建並正常工作,因爲我使用它們來填充我的購物車。 – eoin 2012-03-22 10:19:00

+0

如果它已經創建,我必須在類裏面開始會話嗎? – eoin 2012-03-22 10:21:09

+0

在實例化任何類的對象並使用同一類中的會話之前,應該開始會話 – 2012-03-22 10:24:12

0
<?php 
session_start(); 
include("purchase.php"); 

var_dump($_SESSION) 

exit; 

$purchase = new purchase($........... 
?> 

嘗試,並檢查什麼是轉儲值,以確保您擁有有效會話

+0

好吧生病嘗試,現在就做。我在一分鐘前休息一下,現在我放在構造函數中的郵件沒有發送給我,這變得非常煩人 – eoin 2012-03-22 14:06:02

+0

我顯示了我的var轉儲上面! – eoin 2012-03-22 15:40:49

+0

即時回到頁面後離開在貝寶網站上做一些處理!這可能是問題!我應該在構造函數和腳本中調用session_start?! – eoin 2012-03-22 16:23:34