Fix seller balance double-deducted when refunding a purchase with active PayPal dispute#4372
Open
Fix seller balance double-deducted when refunding a purchase with active PayPal dispute#4372
Conversation
5d81d37 to
dac3c06
Compare
Contributor
Author
🧪 Local Spec Run — PR #4372Branch:
Result: ✅ No regressions introduced by this PR. The 100 failures on the PR branch vs 96 on The PR's new guard logic ( |
When a buyer files a PayPal dispute and the seller later refunds via the dashboard, the seller's balance was deducted twice: 1. First by the dispute/chargeback clawing back funds 2. Again by the seller-initiated refund Root cause: refund_and_save! had no guard for active chargebacks, and amount_refundable_cents only checked the refunds table (not disputes). Fix: - Add chargedback_not_reversed? guard in refund_and_save! that returns a clear error message - Return 0 from amount_refundable_cents for active chargebacks so the UI correctly shows the purchase as non-refundable - Both guards allow refunds if the chargeback has been reversed Reported case: Purchase 334888748 ($47.19 deducted twice). This has been manually corrected multiple times but the root cause was never fixed. Closes #4358
…! only The guard in amount_refundable_cents was breaking dispute_win_credits which calls amount_refundable_cents to calculate credit amounts after a dispute is won. The chargeback check belongs in refund_and_save! (user-facing refund flow) not in the generic amount calculation.
6bade0c to
c253b43
Compare
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.
Problem
When a buyer files a PayPal dispute and the seller later refunds via the dashboard, the balance is deducted twice. Reported multiple times, manually corrected each time. Purchase 334888748 was the latest case.
Fix
chargedback_not_reversed?guard inrefund_and_save!with clear error messageamount_refundable_centsreturns 0 for active chargebacks so UI shows non-refundableBoth allow refunds if chargeback is reversed. 4 new tests.
Closes #4358