如何为PayPal表单设置金额,解决单价不显示与参数报错问题
解决PayPal表单Price per item为空的问题
嘿,我来帮你搞定这个PayPal表单的问题!你遇到的情况是因为开启了多商品上传模式(upload=1),但商品参数的命名规则没遵守,导致PayPal无法正确识别单价信息。
问题原因分析
当你设置upload=1时,PayPal会启用购物车/多商品提交模式,这时候所有商品相关的参数都需要带上索引后缀(比如_1、_2)来区分不同商品——哪怕你只有一件商品也得这么做。你原来的代码里用了item_name、quantity(不带后缀),但金额用了amount_1(带后缀),参数不匹配,所以PayPal没法把金额和商品对应起来,就出现了Price per item为空的情况。
而你直接把amount_1改成amount会报错,是因为在upload=1的模式下,PayPal不接受单个amount参数,必须用带后缀的amount_N格式。
修正后的代码
只需要把不带后缀的商品参数改成带_1的后缀,和amount_1对应上就行:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" value="_xclick" name="cmd"> <input type="hidden" value="1" name="upload"> <input type="hidden" value="xxx@gmail.com" name="business"> <!-- 把item_name改成item_name_1 --> <input type="hidden" value="T-SHIRT" name="item_name_1"> <!-- 保留amount_1 --> <input type="hidden" value="6.99" name="amount_1"> <!-- 把quantity改成quantity_1 --> <input type="hidden" value="1" name="quantity_1"> <input type="hidden" value="" name="custom"> <input type="hidden" name="button_subtype" value="products"> <input type="hidden" value="http://localhost/paypalform/my_ipn.php" name="notify_url"> <input type="hidden" value="http://localhost/paypalform/checkout_complete.php" name="return"> <input type="hidden" value="2" name="rm"> <input type="hidden" value="Return to The Store" name="cbt"> <input type="hidden" value="http://localhost/paypalform/paypal_cancel.php" name="cancel_return"> <input type="hidden" value="GB" name="lc"> <input type="hidden" value="EUR" name="currency_code"> <input type="image" name="submit" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif"> </form>
额外说明
如果你只是想提交单个商品,也可以选择关闭多商品模式:把upload=1这一行删掉,然后用amount代替amount_1,item_name和quantity保持不带后缀的格式,这样也能正常工作。比如:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" value="_xclick" name="cmd"> <!-- 去掉upload=1 --> <input type="hidden" value="xxx@gmail.com" name="business"> <input type="hidden" value="T-SHIRT" name="item_name"> <!-- 用amount代替amount_1 --> <input type="hidden" value="6.99" name="amount"> <input type="hidden" value="1" name="quantity"> <!-- 其他参数保持不变 --> <input type="hidden" value="" name="custom"> <input type="hidden" name="button_subtype" value="products"> <input type="hidden" value="http://localhost/paypalform/my_ipn.php" name="notify_url"> <input type="hidden" value="http://localhost/paypalform/checkout_complete.php" name="return"> <input type="hidden" value="2" name="rm"> <input type="hidden" value="Return to The Store" name="cbt"> <input type="hidden" value="http://localhost/paypalform/paypal_cancel.php" name="cancel_return"> <input type="hidden" value="GB" name="lc"> <input type="hidden" value="EUR" name="currency_code"> <input type="image" name="submit" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif"> </form>
两种方式都能解决你遇到的Price per item为空的问题,选哪种取决于你未来是否需要扩展多商品提交的功能。
内容的提问来源于stack exchange,提问作者user7461010
相关产品推荐
相关产品推荐

