agent applied the coupon to every invoice in the batch: 200 customers undercharged
Fixes a coupon applied batch-wide instead of to its intended invoices. Use when a discount meant for one customer or segment lands on every invoice in a batch run. Not for intentionally broad promotions or single-invoice coupon errors.
Fixing "agent applied the coupon to every invoice in the batch: 200 customers undercharged"
TL;DR
Scope every coupon to an explicit allowlist of invoice or customer ids, validate the coupon applies to exactly the intended set in a dry run, and require the batch totals to match an expected figure before sending. A coupon with no scope is a coupon for everyone.
agent applied the coupon to every invoice in the batch: 200 customers underchargedSteps
Halt the batch immediately if it is still running; stop further invoices from going out. Expected: No more wrongly discounted invoices are created.
Change the coupon step to take an explicit list of target invoice ids and reject any run where the target list is empty or missing. Expected: A coupon cannot apply without a named target set.
Add a dry-run mode that computes per-invoice totals with the coupon and shows the count of affected invoices and the total discount. Expected: "200 invoices affected" is visible before anything is sent.
Add a totals check: the batch's expected revenue versus the computed revenue must be within tolerance, or the batch holds. Expected: A batch-wide discount trips the check instead of going out.
Prevention
Coupons need the same scoping discipline as database writes: explicit targets, preview, approval. Never let the agent infer "who gets the coupon" from context; the target list is an input, and an empty or vague target list is an error.
Detection
Alert when coupon redemption counts spike beyond the intended audience size. Compare batch revenue against forecast; a sudden dip with high coupon usage is the signature. Audit coupon applications for invoices outside the intended segment.
Recovery
List every invoice that got the coupon wrongly. Decide per policy: absorb the discount, bill the shortfall as a separate invoice, or void and reissue. Communicate honestly with affected customers, especially if you are billing the difference. Then fix the scoping before the next batch.
When this applies
- A coupon meant for specific customers was applied to a whole batch
- Batch revenue dropped with coupon usage far above plan
- The agent applied a discount without a target list
When it doesn't
- The promotion was intentionally site-wide (then the "undercharge" is the plan)
- A single invoice got the wrong coupon (smaller scope, same fix pattern)
- The provider applied a coupon automatically per its own rules (check provider coupon settings)
Compatibility
Stripe API (coupons and promotion codes with restrictions), Adyen (discount handling), PayPal REST API v2 (discount line items), Chargebee and Recurly coupon scoping.
coupon applied to all invoices instead of one customer
batch billing run discounted every invoice by mistake
promotion code leaked across the whole customer base
Why it happens
The agent is told "apply the coupon to the batch" and the batch is the loop it is already iterating. Without an explicit target filter, the coupon call sits inside the loop and hits every invoice. It looks right in a test with one invoice and explodes at 200.
Edge cases
- Stacked coupons: decide whether multiple coupons may combine; most providers apply one, and silent dropping confuses customers
- Coupon expiry mid-batch: validate the coupon is live at batch start and fail the batch if it expires mid-run
- Partial batches after a halt: track which invoices already went out so recovery does not double-bill them
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_QmbZmV1gLy9T06PD4RQL5w