在有人标记为重复之前,我已经阅读了所有其他关于添加多个项目到快递结帐的帖子,并没有能够解决我的问题。
我正在使用PayPal提供的工作购物车演示,尽管他们所有的演示或文档只提供了将单个项目添加到购物车的示例,但在演示中不可能添加多个项目。我找不到任何关于如何正确添加多个项目的文档。
在下面的代码中(直接取自paypal演示,但添加了一个额外的产品),它允许交易有效,但是当用户登录到他们的paypal帐户时,它只显示第一个产品,但该产品的价格也是两个产品的总和。
例如,显示如下:
- 单反相机$20.00 USD
- 税$2.00 USD
- 运费$5.00 USD
- 运费折扣$-3.00 USD
- 处理$1.00美元
- 保险$2.00 USD
它没有显示第二个产品。什么好主意吗?由于
代码:
<!--Form containing item parameters and seller credentials needed for SetExpressCheckout Call-->
<form class="form" action="paypal_ec_redirect.php" method="POST">
<div class="row-fluid">
<div class="span6 inner-span">
<!--Demo Product details -->
<table>
<tr><h3> DIGITAL SLR CAMERA </h3></tr>
<tr><img src="img/camera.jpg" width="300" height="250"/></tr>
<tr><td><p class="lead"> Buyer Credentials:</p></td></tr>
<tr><td>Email-id: <input type="text" id="buyer_email" name="buyer_email" readonly></input> </td></tr>
<tr><td>Password:<input type="text" id="buyer_password" name="buyer_password" readonly></input></td></tr>
</table>
</div>
<div class="span6 inner-span">
<p class="lead"> Item Specifications:</p>
<table>
<!-- First item -->
<tr><td>Item Name:</td><td><input type="text" name="L_PAYMENTREQUEST_0_NAME0" value="DSLR Camera"></input></td></tr>
<tr><td>Item ID: </td><td><input type="text" name="L_PAYMENTREQUEST_0_NUMBER0" value="A0123"></input></td></tr>
<tr><td>Description:</td><td><input type="text" name="L_PAYMENTREQUEST_0_DESC0" value="Autofocus Camera"></input></td></tr>
<tr><td>Quantity:</td><td><input type="text" name="L_PAYMENTREQUEST_0_QTY0" value="1" readonly></input></td></tr>
<tr><td>Quantity:</td><td><input type="text" name="L_PAYMENTREQUEST_0_AMT0" value="10.00" readonly></input></td></tr>
<!-- Second item -->
<tr><td>Item Name:</td><td><input type="text" name="L_PAYMENTREQUEST_0_NAME1" value="Item 2"></input></td></tr>
<tr><td>Item ID: </td><td><input type="text" name="L_PAYMENTREQUEST_0_NUMBER1" value="12345"></input></td></tr>
<tr><td>Description:</td><td><input type="text" name="L_PAYMENTREQUEST_0_DESC1" value="Description"></input></td></tr>
<tr><td>Quantity:</td><td><input type="text" name="L_PAYMENTREQUEST_0_QTY1" value="1" readonly></input></td></tr>
<tr><td>Quantity:</td><td><input type="text" name="L_PAYMENTREQUEST_0_AMT1" value="10.00" readonly></input></td></tr>
<tr><td>Price:</td><td><input type="text" name="PAYMENTREQUEST_0_ITEMAMT" value="20.00" readonly></input></td></tr>
<tr><td>Tax:</td><td><input type="text" name="PAYMENTREQUEST_0_TAXAMT" value="2" readonly></input></td></tr>
<tr><td>Shipping Amount:</td><td><input type="text" name="PAYMENTREQUEST_0_SHIPPINGAMT" value="5" readonly></input></td></tr>
<tr><td>Handling Amount:</td><td><input type="text" name="PAYMENTREQUEST_0_HANDLINGAMT" value="1" readonly></input></td></tr>
<tr><td>Shipping Discount:</td><td><input type="text" name="PAYMENTREQUEST_0_SHIPDISCAMT" value="-3" readonly></input></td></tr>
<tr><td>Insurance Amount:</td><td><input type="text" name="PAYMENTREQUEST_0_INSURANCEAMT" value="2" readonly></input></td></tr>
<tr><td>Total Amount:</td><td><input type="text" name="PAYMENTREQUEST_0_AMT" value="27" readonly></input></td></tr>
<tr><td><input type="hidden" name="LOGOIMG" value=<?php echo('http://'.$_SERVER['HTTP_HOST'].preg_replace('/index.php/','img/logo.jpg',$_SERVER['SCRIPT_NAME'])); ?>></input></td></tr>
<tr><td>Currency Code:</td><td><select name="currencyCodeType">
<option value="AUD">AUD</option>
<option value="BRL">BRL</option>
<option value="CAD">CAD</option>
<option value="CZK">CZK</option>
<option value="DKK">DKK</option>
<option value="EUR">EUR</option>
<option value="HKD">HKD</option>
<option value="MYR">MYR</option>
<option value="MXN">MXN</option>
<option value="NOK">NOK</option>
<option value="NZD">NZD</option>
<option value="PHP">PHP</option>
<option value="PLN">PLN</option>
<option value="GBP">GBP</option>
<option value="RUB">RUB</option>
<option value="SGD">SGD</option>
<option value="SEK">SEK</option>
<option value="CHF">CHF</option>
<option value="THB">THB</option>
<option value="USD" selected>USD</option><br></td></tr>
<tr><td>Payment Type: </td><td><select>
<option value="Sale">Sale</option>
<option value="Authorization">Authorization</option>
<option value="Order">Order</option>
</select><br></td></tr>
<tr><td colspan="2"><br/><br/><div id="myContainer"></div></td></tr>
<tr><td> -- OR -- </td></tr>
<tr><td ><input type="Submit" alt="Proceed to Checkout" class="btn btn-primary btn-large" value="Proceed to Checkout" name="checkout"/></td></tr>
</table>
</div>
</div>
</form>
我发现了,他们的演示代码只手动检查post数据中的一个项目。
POST数据以及返回和取消url被发送给CallShortcutExpressCheckout函数(paypal_functions.php),该函数只检查预定的参数,而不是实际循环遍历任何POST数据。
例如,它只手动检查参数是否为issset(),但只检查一个项:
function CallShortcutExpressCheckout( $paramsArray, $returnURL, $cancelURL) {
//it manually checks for all the paramters, i just have shown one for example
if(isset($paramsArray["PAYMENTREQUEST_0_SHIPDISCAMT"])){
$nvpstr = $nvpstr . "&PAYMENTREQUEST_0_SHIPDISCAMT=" . $paramsArray["PAYMENTREQUEST_0_SHIPDISCAMT"];
$_SESSION['shippingDiscAmt'] = $paramsArray["PAYMENTREQUEST_0_SHIPDISCAMT"];
}
//And here it only looks for one item
if(isset($paramsArray["L_PAYMENTREQUEST_0_NAME0"]))
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_NAME0=" . $paramsArray["L_PAYMENTREQUEST_0_NAME0"];
if(isset($paramsArray["L_PAYMENTREQUEST_0_NUMBER0"]))
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_NUMBER0=" . $paramsArray["L_PAYMENTREQUEST_0_NUMBER0"];
if(isset($paramsArray["L_PAYMENTREQUEST_0_DESC0"]))
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_DESC0=" . $paramsArray["L_PAYMENTREQUEST_0_DESC0"];
if(isset($paramsArray["L_PAYMENTREQUEST_0_AMT0"]))
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_AMT0=" . $paramsArray["L_PAYMENTREQUEST_0_AMT0"];
if(isset($paramsArray["L_PAYMENTREQUEST_0_QTY0"]))
$nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_QTY0=" . $paramsArray["L_PAYMENTREQUEST_0_QTY0"];
if(isset($paramsArray["LOGOIMG"]))
$nvpstr = $nvpstr . "&LOGOIMG=". $paramsArray["LOGOIMG"];
我只是删除了所有的代码,并放入一个简单的foreach循环:
function CallShortcutExpressCheckout( $paramsArray, $returnURL, $cancelURL)
{
if(isset($returnURL))
$nvpstr = $nvpstr . "&RETURNURL=" . $returnURL;
if(isset($cancelURL))
$nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;
foreach ($paramsArray as $k => $value){
$nvpstr = $nvpstr . "&" . $k . "=" . $value;
}
最重要的是,由于某种原因,在paypal_ec_redirect.php中,他们确保将单个产品项目金额更改为所有项目金额的总和,好像要确保只发送一个项目,否则它会抛出购物车项目金额的总和与订单金额不匹配(错误代码:10413)。
我刚刚把它注释掉了,现在一切都很好,我可以下多个项目的订单。
//$_POST["L_PAYMENTREQUEST_0_AMT0"] = $_POST["PAYMENTREQUEST_0_ITEMAMT"];
我希望这能帮助别人,我确实看到了另一个stackoverflow问题与完全相同的问题。我不明白为什么他们会故意让演示代码只接受一个项。