Skip to content

Map negative fee amounts to discount in PayPal amount breakdown#4162

Open
popforce wants to merge 1 commit intowoocommerce:masterfrom
popforce:patch-2
Open

Map negative fee amounts to discount in PayPal amount breakdown#4162
popforce wants to merge 1 commit intowoocommerce:masterfrom
popforce:patch-2

Conversation

@popforce
Copy link
Copy Markdown
Contributor

Description

This change adjusts the PayPal amount breakdown handling for orders containing negative fees.

At the moment, coupon discounts are added to the PayPal discount amount, but negative fees are not handled separately. This can lead to incorrect amount breakdowns when negative fees are used as discounts, especially if they are taxable.

In such cases, the negative fee gross amount should be represented as discount instead of being treated like a regular fee line. Otherwise, the resulting breakdown may produce AMOUNT_MISMATCH errors because amount.value no longer matches the expected sum of item_total + tax_total + shipping - discount.

This patch keeps the existing item calculation intact and only adjusts fee handling:
positive fees are still added to item_total / tax_total, while negative fees are added as gross discount amounts.

This is a minimal change that improves compatibility with payment sources that strictly validate the PayPal amount breakdown.

Since this changes amount breakdown handling, an additional review would be appreciated to confirm the behavior across supported payment flows and edge cases.

Steps to Test

  1. Create or use an order/cart with at least one negative fee used as a discount.
  2. Make sure the negative fee is taxable, so the gross discount amount differs from the net fee amount.
  3. Select a PayPal payment method that validates the amount breakdown strictly, for example Pay upon Invoice / RatePay.
  4. Attempt checkout before the patch and verify that an AMOUNT_MISMATCH can occur.
  5. Apply this patch.
  6. Repeat the same checkout with the same cart/order conditions.
  7. Confirm that the PayPal amount breakdown now maps negative fee gross amounts to discount.
  8. Confirm that checkout succeeds and no AMOUNT_MISMATCH is returned.
  9. Confirm that positive fees, if present, are still included in item_total / tax_total as before.

Documentation

  • This PR needs documentation

Changelog Entry

Fix PayPal amount breakdown handling for negative fee discounts by mapping negative fee gross amounts to discount instead of treating them as regular fees.

This change fixes the amount breakdown generation for orders containing negative fees.

At the moment, coupon discounts are added to the PayPal discount amount, but negative fees are not handled separately. This can lead to incorrect amount breakdowns when negative fees are used as discounts, especially if they are taxable.

In such cases, the negative fee gross amount should be represented as discount instead of being treated like a regular fee line. Otherwise, the resulting breakdown may produce AMOUNT_MISMATCH errors because amount.value no longer matches the expected sum of item_total + tax_total + shipping - discount.

This patch keeps the existing item calculation intact and only adjusts fee handling:
positive fees are still added to item_total / tax_total, while negative fees are added as gross discount amounts.

This is a minimal change that improves compatibility with payment sources that strictly validate the PayPal amount breakdown.

Since this changes amount breakdown handling, an additional review would be appreciated to confirm the behavior across supported payment flows and edge cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant