问题
I cannot figure out what I am doing wrong with my code, I get the error
"We have detected a problem with this shopping cart. If the problem persists, please contact the merchant."
Here is the form I'm submitting...
<form name="paypalForm" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="example@example.com">
<input type="hidden" name="return" value="http://example.com/payment1.php">
<input type="hidden" name="undefined_quantity" value="0">
<input type="text" name="item_name1" value="1 item name">
<input type="text" name="item_number1" value="1">
<input type="text" name="amount1" value="0.4">
<input type="text" name="tax1" value="0.076">
<input type="text" name="item_name2" value="2 item name">
<input type="text" name="item_number2" value="2">
<input type="text" name="amount2" value="3.5">
<input type="text" name="tax2" value="0.665">
<input type="text" name="num_cart_items" value="2">
<input type="text" name="quantity" value="1">
<input type="text" name="currency_code" value="USD">
<input type="text" name="tax" value="0.741">
<input type="text" name="no_shipping" value="0">
<input type="text" name="no_note" value="0">
<input type="text" name="cancel_return" value="example.com/cancel.php">
<input type="text" name="notify_url" value="http://example.com/payment1.php">
</form>
I put type "text" so I could debug..
回答1:
I see quite a few problems:
- You are using 'undefined_quantity' which is only used with buy now buttons.
- You are trying to do a cart upload button but doing the variables incorrectly (you enumerate with '_x', not just 'x' appended to the var name. I will post code below.
- You are missing a required '_cart' button parameter. Cart buttons always have either 'add=1' (add to cart), 'display=1' (view cart, overrides add), and 'upload=1' (upload, for sending multiple items at once).
- Your cancel return URL does not have 'http://' which is required with PayPal.
- PayPal only accepts 'floats' or amounts in two decimal place precision.
- Along with #5, I'm guessing your 'tax' value is supposed to be a percentage, and not the actual amount. For this, you would use 'tax_rate' for percents. Use 'tax_cart' if you know the exact tax for the total of all items in the cart.
See button code for a cart upload button below:
<form target="paypal" action="https://www.sandbox.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="business" value="example@example.com">
<!-- Begin First Item -->
<input type="hidden" name="quantity_1" value="1">
<input type="hidden" name="item_name_1" value="Item A">
<input type="hidden" name="item_number_1" value="Test SKU A">
<input type="hidden" name="amount_1" value="0.01">
<!--<input type="hidden" name="shipping_1" value="0.01">
<input type="hidden" name="tax_1" value="0.02">-->
<!-- End First Item -->
<!-- Begin Second Item -->
<input type="hidden" name="quantity_2" value="1">
<input type="hidden" name="item_name_2" value="Test Item B">
<input type="hidden" name="item_number_2" value="Test SKU B">
<input type="hidden" name="amount_2" value="0.02">
<!--<input type="hidden" name="shipping_2" value="0.02">
<input type="hidden" name="tax_2" value="0.02">-->
<!-- End Second Item -->
<!-- Begin Third Item -->
<input type="hidden" name="quantity_3" value="1">
<input type="hidden" name="item_name_3" value="Test Item C">
<input type="hidden" name="item_number_3" value="Test SKU C">
<input type="hidden" name="amount_3" value="0.03">
<!--<input type="hidden" name="shipping_3" value="0.03">
<input type="hidden" name="tax_3" value="0.03"> -->
<!-- End Third Item -->
<input type="hidden" name="currency_code" value="USD">
<!--<input type="hidden" name="tax_cart" value="5.13"> -->
Upload <br>
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_cart_SM.gif" border="0" name="upload" alt="Make payments with PayPal - it's fast, free and secure!" width="87" height="23">
</form>
You should check for the variables PayPal supports for Website Payments Standard (buttons) here.
回答2:
I had the same Problem, but when I have added a line it solved
<input type="hidden" name="add" value="1">
you can try it. I am not sure is this is the correct solution or not.
来源:https://stackoverflow.com/questions/9136244/paypal-integration-issue