流程交易功能paypal

时间:2018-05-29 14:03:52

标签: php paypal

我正在通过视频学费​​构建电子商务应用程序。

我有一个process_transaction函数,可以在成功购买后从网址解析PayPal个tx参数,并填充phpMyAdmin 4.8.0中的“订单”表。

以前,如果您刷新我的thank_you.php页面,订单会继续填充我的'订单'表(因为之前没有会话销毁内置到上述功能中)。

问题是,我们的导师为此功能阻止这样做的代码不起作用。运行时,'orders'表不再从事务中填充,也不会运行session_destroy。

我想知道这个功能有什么问题。

  

thank_you.php

<?php require_once("../resources/config.php"); ?>
<?php require_once("../resources/cart.php"); ?> 
<?php include('../resources/templates/front/header.php') ?>   



<?php

process_transaction();

?> 



    <!-- Page Content -->
    <div class="container">

      <h1 class="text-center">THANK YOU</h1>

      <h3>Nippon will get your products shipped today</h3>

    </div>
    <!-- /.container -->




 <?php include('../resources/templates/front/footer.php') ?>
  

cart.php(无法正常工作 - 不会在db中保留订单,或会话销毁)

function process_transaction(){

  if(isset($_GET['tx'])){

    $amount = $_GET['amt']; // get amount
    $currency = $_GET['cc'];
    $transaction = $_GET['tx']; // 
    $status = $_GET['st']; // get status ie completed
    $total = 0;
    $item_quantity = 0;


    foreach ($_SESSION as $name => $value) {

      if($value > 0 ) {

        if (substr($name, 0, 8) == "product_") {

          $length = strlen($name); 
          $id = substr($name, 8, $length);

           $send_order = query("INSERT INTO orders (order_amount,order_transaction,order_status,order_currency) VALUES('{$amount}','{$transaction}','{$status}','{$currency}')");
           $last_id = last_id(); 
           confirm($send_order); 


          $query = query("SELECT * FROM products WHERE product_id = " . escape_string($id) . " ");
          confirm($query);

          while($row = fetch_array($query)) {
            $product_price = $row['product_price'];
            $product_title = $row['product_title'];
            $sub = $row['product_price'] * $value;
            $item_quantity += $value;
            $insert_report = query("INSERT INTO reports (product_id, order_id, product_title, product_price,product_quantity) VALUES ('{$id}','{$last_id}','{$product_title}','{$product_price}','{$value}')");
            confirm($insert_report);
          }

          $total += $sub;
          echo $item_quantity;
        }
      }
    }
    session_destroy();
  } else {
    redirect("index.php");
  }
}
  

的functions.php

<?php

function query($sql) {


global $connection;

return mysqli_query($connection, $sql);


}


function fetch_array($result) {

return mysqli_fetch_array($result); 


}




function escape_string($string){

global $connection;

return mysqli_real_escape_string($connection,$string);  


}






?>

enter image description here

0 个答案:

没有答案