如何以paypal支付形式显示项目列表

时间:2016-10-01 01:47:48

标签: php html twitter-bootstrap paypal payment-gateway

我正在建立一个paypal立即购买按钮

我显示了购物车商品的总价

购物车是一个自定义的PHP购物车,它使用cookie来存储用户商品数据

但是,我希望paypal付款页面显示我的用户购物车中的商品列表。

我已尝试将cmd从_xclick更改为_cart并添加更多代码行,但是当我测试付款按钮并点击立即购买时,会出现一个paypal页面

检测到错误

您的购物车是空的。

当cmd为_xclick时,购物车内容会传递给PayPal并且我的代码有效,

我做错了什么或错过了什么?除了插入页眉和页脚之外,我对PHP很陌生,所以我对错误或遗漏的内容感到有点迷失

这是我的代码:

paypal付款按钮代码:

<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="item name 1">
<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>

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

请帮助我如此困惑和困惑!我只想在用户购物车中的项目列表显示在paypal表格上并发送到PayPal。

由于

0 个答案:

没有答案