2015-12-09 51 views
0

我想列出所有在Paypal結帳中購買的商品。我已經嘗試了下面的代碼,但它沒有顯示項目。它只是在結帳時顯示輸入字段。我也添加了貝寶的快照。我第一次嘗試將我的網站與PayPal整合在一起。 enter image description here在PayPal支票結賬中顯示所有購物車內容

代碼

<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> 
<!-- Identify your business so that you can collect the payments. --> 
<input type="hidden" name="business" value="[email protected]"> 
<!-- Specify a Buy Now button. --> 
<input type="hidden" name="cmd" value="_xclick"> 
<?php 
if(isset($_SESSION['cart'])){ 
    foreach($_SESSION['cart'] as $id => $value){ 
    $count=1; 
?> 
<input type="text" name="item_name_<?php echo $count ?>" value="<?php echo $value['name'] ?>"> 
<input type="text" name="item_qty_<?php echo $count ?>" value="<?php echo $value['quantity'] ?>"> 
<input type="text" name="amount_<?php echo $count ?>" value="<?php echo $value['price'] ?>"> 
    <input type="text" name="color_<?php echo $count ?>" value="<?php echo $value['color'] ?>"> 
    <input type="text" name="size_<?php echo $count ?>" value="<?php echo $value['size'] ?>"> 
    <input type="text" name="currency_code_<?php echo $count ?>" value="USD"> 

<?php 
$count++; 
    }} 
    ?> 
<!-- Display the payment button. --> 
    <input type="image" name="submit" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online"> 
    <img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" > 
    </form> 
+0

對你有幾個問題,OP。爲什麼在顯示每個項目前,'$ count'總是被設置爲'1'? (*此外,爲什麼你在循環結尾增加'count'?*)$ _SESSION ['cart']'存儲了一個鍵控數組的鍵控數組嗎?如果您有權訪問服務器的錯誤日誌,那麼在運行代碼時是否會看到任何與PHP相關的錯誤? (*如果是這樣,它們是什麼?*)您是否考慮過使用[標準的PayPal購物車實施](https://goo.gl/wLlRYy)? – SpencerD

+0

@SpencerDoak我在PayPal文檔中看到了這樣的情況:每個商品的名稱都應該像這個'item_1'' item_2'一樣傳遞。這是我初始化櫃檯的原因。 – tabia

+0

@SpencerDoak從這個鏈接https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/buynow_buttons/ – tabia

回答

1

item_name_x僅適用於車上傳命令。

您需要將cmd值更改爲「_cart」,並添加另一個名爲upload的變量和值爲1

下面是一個例子:

cmd = _cart 
upload = 1 
amount_1 = 0.01 
item_name_1 = Test Item 
item_number_1 = 123 
currency_code = USD 
... 

之後,您的代碼應工作。請致電HTML Variables of PayPal Payment Standard

+0

它幫助了我:)但是,你可以告訴我變量名稱以傳遞'size'和'color'。我在文檔 – tabia

+1

@tabia中找不到答案爲此,您必須使用'on0'或'on1',這是標籤。至於值,你將使用'os0'或'os1'。例如,如果'on0'是'size','os0'將會是'large'。 'color'也一樣。它全部記錄在我上面發佈的鏈接上。 –

相關問題