Skip to main content

Discount Reconciliation Examples

This guide explains how the Discount Reconciliation Layer distributes order-level discounts (coupons, gift cards, points redemptions) across line items when the POS sends them only at the order level. It walks through the algorithm with the same payload shape used by the Order API. Endpoint: POST https://api.gameball.co/api/v4.0/integrations/orders Headers:

Why Reconciliation Is Needed

Many POS and e-commerce systems apply a discount, gift card, or loyalty redemption at the order level (via totalDiscount or a reduced totalPaid) and never push the discount down to the line items. The cashback engine calculates rewards per line item, so without reconciliation the customer is over-rewarded.
The reconciliation layer detects this mismatch and distributes the gap proportionally across eligible line items so that Σ line items = totalPaid.

Field Definitions

Line Item Fields

Order Level Fields

Cashback is earned per line item based on (price × quantity) + taxes - discount. The reconciliation layer ensures the sum of line item totals equals totalPaid before cashback runs.

Reconciliation Formulas

Step 0 — Filter Negative-Price Items

Step 1 — Detect Mismatch

totalPaid includes shipping but line items don’t, so shipping is added on the line-item side of the equation.

Step 2 — Distribute Proportionally Across ALL Items

Items that already have a POS-applied discount aren’t skipped — they’re weighted by their net value, so a more-discounted item naturally receives a smaller share.

Step 3 — Final Validation


Decision Table


Example 1: Order-Level Coupon (Most Common)

Scenario: Customer applied a coupon at checkout. The POS reduced totalPaid and set totalDiscount but left line items at full price.
The discount values shown (6 and 14) are what reconciliation writes onto the line items. The integration only needs to send discount: 0 — Gameball fills these in.

Example 2: Mixed — Some Items Already Discounted

Scenario: Item A has a $5 line discount from the POS. The mismatch is distributed across both items, weighted by net value, so the item with the bigger existing discount automatically gets a smaller share.

Example 3: All Items Already Discounted

Scenario: Every line item already has a POS-applied discount, but their sum still doesn’t match totalPaid. The remaining gap is distributed across all items by net value.

Example 4: External Loyalty Redemption as Payment Method

Scenario: A POS like Square treats a points redemption as a payment method (not a discount). totalPaid is already reduced; line items remain at full price; totalDiscount is zero.
The algorithm doesn’t need to know why there’s a mismatch (coupon, gift card, loyalty as discount, loyalty as payment). It reconciles purely on lineItemTotal vs totalPaid — making it universal across POS patterns.

Example 5: POS Coupon + External Redemption Combined

Scenario: Customer used a 20couponANDredeemed20 coupon AND redeemed 20 of points through the POS. Neither was distributed to line items. Reconciliation handles both in a single pass.
This was the previous double-distribution bug: reconciliation distributed $40, then DistributeRedeemedAmount distributed another $20 on top. The single-pass reconciliation now handles both deductions together, so cashback is correctly calculated on $60.

Example 6: Cap Protection — Discount Larger Than Cheap Item

Scenario: A large redemption could mathematically push a cheap item’s cashback base below zero. The cap ensures the per-item discount never exceeds the item’s value.

Example 7: No Mismatch (Pass-Through)

Scenario: The POS already distributed every discount onto line items. Σ line items already equals totalPaid. Reconciliation runs but does nothing.

Edge Cases Reference


Summary Table


Key Takeaway

Reconciliation guarantees Σ line item cashback base = totalPaid.Integrations don’t need to figure out which deduction caused the gap (coupon, gift card, loyalty as discount, loyalty as payment). Just send:
  • Line items at their natural prices
  • totalPaid reflecting what the customer actually paid
Gameball detects the mismatch, distributes it proportionally across eligible items, and never blocks the order if reconciliation can’t fully close the gap.