duanmu6752 2016-10-15 19:23 采纳率: 0%
浏览 17

_xcart在Paypal支付表格上无法正常工作“您的购物车是空的”

After weeks of trying to get my Paypal payment form to show a list of the items, I have finally stopped the error messages with my code but when I click on the "buy" button and get taken through to Paypal, Paypal says that my shopping cart is empty even though it isnt.

I have echoed the cart items cookie (using a cookies php cart) but for some reason Paypal is not finding the items in the cart

Here is my code:

cart.php

<?php
$page_title="Cart";
include 'includes/header.php';


$action = isset($_GET['action']) ? $_GET['action'] : "";
$name = isset($_GET['name']) ? $_GET['name'] : "";

if($action=='removed'){
echo "<div class='alert alert-info'>";
    echo "<strong>{$name}</strong> was removed from your cart!";
echo "</div>";
}

$cookie = $_COOKIE['cart_items_cookie'];
$cookie = stripslashes($cookie);
$saved_cart_items = json_decode($cookie, true);

if(count($saved_cart_items)>0){
// get the product ids
$ids = "";
foreach($saved_cart_items as $id=>$name){
    $ids = $ids . $id . ",";
}

// remove the last comma
$ids = rtrim($ids, ',');

//start table
echo "<table class='table table-hover table-responsive table-bordered'>";

    // our table heading
    echo "<tr>";
        echo "<th class='textAlignLeft'>Product Name</th>";
        echo "<th>Price (USD)</th>";
        echo "<th>Action</th>";
    echo "</tr>";

    $query = "SELECT id, name, price FROM products WHERE id IN ({$ids}) ORDER BY name";
    $stmt = $con->prepare( $query );
    $stmt->execute();

    $total_price=0;
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        extract($row);

        echo "<tr>";
            echo "<td>{$name}</td>";
            echo "<td>&#36;{$price}</td>";
            echo "<td>";
                echo "<a href='remove_from_cart.php?id={$id}&name={$name}' class='btn btn-danger'>";
                    echo "<span class='glyphicon glyphicon-remove'></span> Remove from cart";
                echo "</a>";
            echo "</td>";
        echo "</tr>";

        $total_price+=$price;
    }

    echo "<tr>";
            echo "<td><b>Total</b></td>";
            echo "<td>&#36;{$total_price}</td>";
            echo "<td>";
                echo "<a href='payment-page.php?total={$total_price}' class='btn btn-success'>";
                    echo "<span class='glyphicon glyphicon-shopping-cart'>    </span> Checkout";
                echo "</a>";
            echo "</td>";
        echo "</tr>";

echo "</table>";
}

else{
echo "<div class='alert alert-danger'>";
    echo "<strong>No products found</strong> in your cart!";
echo "</div>";
}



include 'includes/footer.php';
?>

And here is my code for the paypal button that links to my cart:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="item_name_1" value="<?php echo $_COOKIE['cart_items_cookie'];?>">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="me@mysite.com">
<input type="hidden" name="item_name" value="Order#21874">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="amount" value="<?php echo $_GET['total'];?> ">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>

Is there something I am missing?

I am rather new to this and have been working on it for weeks now!

Thanks for any help or suggestions

  • 写回答

1条回答 默认 最新

  • dro60731 2017-03-16 06:23
    关注

    instead of passing amount you should pass amount_1. So change this <input type="hidden" name="amount" value="<?php echo $_GET['total'];?> "> to <input type="hidden" name="amount_1" value="<?php echo $_GET['total'];?> ">

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)