简体   繁体   中英

_xcart not working properly on Paypal payment form “Your shopping cart is empty”

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

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'];?> ">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM