Fix manual refund validation error when entering negative amounts #3107
Fix manual refund validation error when entering negative amounts #3107shivam-pawar-7217 wants to merge 1 commit intofossasia:devfrom
Conversation
There was a problem hiding this comment.
Sorry @shivam-pawar-7217, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Follow-up: Stripe Webhook Refund Sync@mariobehling - This PR fixes the manual refund validation layer. For Stripe webhook refund syncing (charge.refunded events → order refunds), that's handled by the eventyay-stripe plugin. If that's still not working, it may need a separate issue/PR in the eventyay-stripe repository. Should we verify that part is working correctly or create a follow-up issue for it? |
There was a problem hiding this comment.
Pull request overview
Fixes manual refund validation issues in the control order refund flow, primarily addressing negative refund inputs and precision mismatches that caused erroneous “selected vs expected” validation failures.
Changes:
- Added validation to reject negative refund values across manual, gift card, offsetting, provider-specific, and per-payment refund inputs.
- Normalized totals with currency rounding before comparing
refund_selectedvsfull_refund, and enhanced mismatch error output with the computed amounts. - Added/updated regression tests for negative manual and negative gift card refund inputs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| app/eventyay/control/views/orders.py | Adds negative-value validation, rounds totals before comparison, improves mismatch error message, and logs mismatches. |
| app/tests/tickets/control/test_orders.py | Updates refund validation expectations and adds a regression test ensuring negative gift card input does not create gift cards. |
Comments suppressed due to low confidence (1)
app/eventyay/control/views/orders.py:1041
- The gift card is created immediately when
giftcard_value > 0, before validating thatis_validis still true and thatrefund_selected == full_refund. If the request later fails validation or the totals don’t match, this leaves a newly issued gift card without a corresponding successful refund. Defer gift card issuance (and relatedOrderRefundcreation) until after the final validation passes (or wrap the whole operation in a transaction and only commit on success), and add a regression test for the mismatch path.
refund_selected += giftcard_value
giftcard = self.request.organizer.issued_gift_cards.create(
expires=self.request.organizer.default_gift_card_expiry,
currency=self.request.event.currency,
testmode=self.order.testmode,
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
app/eventyay/control/views/orders.py:1045
issued_gift_cards.create(...)is executed immediately whengiftcard_value > 0, even if later validation fails (e.g., another field is invalid) or ifrefund_selected != full_refund. In those failure paths theOrderRefundobjects are never saved, but theGiftCardrecord has already been created, leaving an orphaned/phantom gift card. Consider deferring gift card creation until afterrefund_selected == full_refund and is_validis confirmed (or wrap the whole operation in an atomic transaction and roll back/delete the gift card on failure).
refund_selected += giftcard_value
giftcard = self.request.organizer.issued_gift_cards.create(
expires=self.request.organizer.default_gift_card_expiry,
currency=self.request.event.currency,
testmode=self.order.testmode,
)
giftcard.log_action('eventyay.giftcards.created', user=self.request.user, data={})
…n, improve error messages (fossasia#3096)
c35309c to
f9bd087
Compare
|
This PR does not have a screenshot or screencast showing before and after. Hence closing this for now. |
Fixes #3096
The Problem
When trying to process refunds manually, you get an error:
"The refunds you selected do not match the selected total refund amount."
Root causes:
Fixes
Manual refund validation layer:
Notes
Stripe webhook refund syncing is handled by the eventyay-stripe plugin (separate repo).
If Stripe webhooks aren't syncing refunds:
This PR focuses on unblocking manual refund processing immediately.