Skip to content

[Bug]: Coupon usage can be consumed even when invoice submission later fails #200

@my-dev-jour

Description

@my-dev-jour

Bug Description

Coupon usage is incremented before invoice submission fully completes, and the helper commits that increment immediately.

If a later validation, stock, or submit step fails, the sale can roll back while the coupon remains consumed.

Expected Behavior

Coupon usage should only be finalized if the invoice submission completes successfully.

Actual Behavior

Coupon usage can be incremented and committed before the rest of the sale lifecycle succeeds.

Steps to Reproduce

  1. Start a sale that uses a limited-use or gift-card-style coupon
  2. Trigger a failure after coupon usage is incremented but before the invoice submission finishes
  3. Check the coupon usage counter afterward

Impact

  • coupon usage counts can drift away from successful invoices
  • failed checkouts can permanently consume limited-use coupons
  • operators may need manual correction after a failed sale

Suggested Fix

  • move coupon usage increment into the same transaction boundary as successful invoice submission
  • avoid helper-level commits during coupon consumption
  • roll back coupon usage automatically when submission fails

Notes

This is separate from coupon cancel rollback and separate from the race-condition issue. The problem here is that a single failed checkout can still consume usage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions