PayPal购物车折扣显示调整:将折扣置于税费上方
Yes, you can adjust the display order so the discount appears above the tax line—though it requires a small tweak to your form since the standard discount_amount_cart parameter’s position in PayPal’s checkout interface is fixed (it shows after tax by default). Here’s how to do it:
The Workaround: Replace Cart-Level Discount with a Negative Line Item
Instead of using the discount_amount_cart hidden field, add a dedicated line item for your discount with a negative amount. This will make PayPal display the discount after your product items but before the tax line, aligning with your desired visual flow.
Modified Form Code
Here’s your updated form with this change applied:
<form class="paypalform" action="https://www.sandbox.paypal.com/bn/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="dummy-facilitator@dummysite.com"> @foreach (var item in Model) { <input type="hidden" name="item_name_@count" value="@item.ProductName"> <input type="hidden" name="amount_@count" value="@item.Price"> count++; cartTotal += @item.Price; } <!-- Add discount as a negative line item --> <input type="hidden" name="item_name_@count" value="Discount"> <input type="hidden" name="amount_@count" value="-@ViewBag.DiscountAmount"> count++; <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="tax_cart" value="@ViewBag.TaxAmount" /> <input type="image" src="http://www.sandbox.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form>
Key Notes:
- Tax Calculation: Since you’re already calculating tax based on the discounted total, this change won’t affect the final amount—PayPal will sum all line items (products + negative discount) to get the subtotal, then apply the tax on top, matching your existing logic.
- Visual Clarity: The discount will now show up as a separate line item labeled "Discount" with a negative value, positioned right after your product items and before the tax line. This eliminates the confusion of tax appearing to be calculated pre-discount.
- Testing: Be sure to test this in the PayPal Sandbox first to confirm the display order and final amounts are correct before rolling out to production.
If you’re open to moving to PayPal’s newer REST API (Orders API), you’d have even more granular control over the checkout page’s line item ordering and labeling, but the above workaround is a quick, effective fix for your current classic form setup.
内容的提问来源于stack exchange,提问作者BrainPain

