Map negative fee amounts to discount in PayPal amount breakdown#4162
Open
popforce wants to merge 1 commit intowoocommerce:masterfrom
Open
Map negative fee amounts to discount in PayPal amount breakdown#4162popforce wants to merge 1 commit intowoocommerce:masterfrom
popforce wants to merge 1 commit intowoocommerce:masterfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This change adjusts the PayPal amount breakdown handling for orders containing negative fees.
At the moment, coupon discounts are added to the PayPal
discountamount, 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
discountinstead of being treated like a regular fee line. Otherwise, the resulting breakdown may produceAMOUNT_MISMATCHerrors becauseamount.valueno longer matches the expected sum ofitem_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
AMOUNT_MISMATCHcan occur.discount.AMOUNT_MISMATCHis returned.item_total/tax_totalas before.Documentation
Changelog Entry