ValulogDashboard

How to stack discounts without confusing the refund

Published

Two discounts on the same basket are easy to describe and easy to get wrong. “10 percent off, then £6 off” can mean two different things, depending on whether the £6 is shared using the original line values or the amounts left after the 10 percent. Valulog makes you choose, records the choice, and caps every share so a line cannot go below zero.

The two bases

Every rule has an application_base. REMAINING_BALANCE, the default, applies the rule to what is left after earlier rules. ORIGINAL_SUBTOTAL ignores earlier discounts when working out the new amount, and uses the pre-discount line values as the weights for the split. (A third value, PER_LINE, uses the remaining balance and is about which lines are in scope.)

In both cases, a share is then capped at what is still left on the line, so the second discount cannot drive a line negative.

A worked example where the line split changes

A £20.00 line and a £10.00 line, with 50 percent off the £10.00 line only, then £6.00 off the basket.

After the 50 percent, the lines stand at £20.00 and £5.00. If the £6.00 uses REMAINING_BALANCE, it is shared 480 pence and 120 pence, and the customer has paid £15.20 and £3.80. If the £6.00 uses ORIGINAL_SUBTOTAL, it is shared 400 pence and 200 pence against the original £20 / £10 weights, and the customer has paid £16.00 and £3.00. The basket total is £19.00 either way; the lines differ. A later return of one line would refund different amounts.

Pick the base that matches the offer you sold

If your offer is “£6 off what you would have paid after other discounts”, use REMAINING_BALANCE. If your offer is “£6 off, worked out from the shelf prices, even if something else has already been applied”, use ORIGINAL_SUBTOTAL. Write the same wording in the customer’s basket so the refund later matches what they were shown.

The snapshot is the source for the refund

Valulog stores each rule, its base, and how many pence it took from each line, on a frozen snapshot with a hash. Refunds read that snapshot. Nothing is recalculated from today’s prices. Valulog does not move the money and does not give tax advice.

50% off one line, then £6 off the basket (request body)
{
    "currency": "GBP",
    "items": [
      { "id": "line-1", "sku": "TEE", "unit_price_cents": 2000, "quantity": 1 },
      { "id": "line-2", "sku": "MUG", "unit_price_cents": 1000, "quantity": 1 }
    ],
    "discounts": [
      { "rule_id": "HALF-MUG", "type": "PERCENTAGE", "basis_points": 5000,
        "applicable_items": ["line-2"] },
      { "rule_id": "SIXOFF", "type": "FIXED_AMOUNT", "amount_cents": 600,
        "application_base": "REMAINING_BALANCE" }
    ]
  }
  // REMAINING_BALANCE → line-1 paid 1520, line-2 paid 380, total 1900.
  // Change the base to ORIGINAL_SUBTOTAL → line-1 paid 1600, line-2 paid 300, total 1900.

Valulog is not a payment processor and does not give tax advice. Payments stay with your payment provider; Valulog records how prices, discounts and refunds were calculated.

Run this exact payload in Sandbox

50% off the mug, then £6 off (choose the base): calculate the basket, then refund 1 unit of line-1 from the frozen snapshot. Free test key, no card.

# 1. Calculate and freeze the basket (needs jq to read the transaction_id)
TX=$(curl -s https://api.valulog.com/v1/calculate \
  -H "Authorization: Bearer $VALULOG_KEY" \
  -H "Idempotency-Key: demo-base-calc" \
  -H "Content-Type: application/json" \
  -d '{
  "currency": "GBP",
  "items": [
    {
      "id": "line-1",
      "sku": "TEE",
      "unit_price_cents": 2000,
      "quantity": 1
    },
    {
      "id": "line-2",
      "sku": "MUG",
      "unit_price_cents": 1000,
      "quantity": 1
    }
  ],
  "discounts": [
    {
      "rule_id": "HALF-MUG",
      "type": "PERCENTAGE",
      "basis_points": 5000,
      "application_base": "REMAINING_BALANCE",
      "applicable_items": [
        "line-2"
      ]
    },
    {
      "rule_id": "SIXOFF",
      "type": "FIXED_AMOUNT",
      "amount_cents": 600,
      "application_base": "REMAINING_BALANCE"
    }
  ]
}' | jq -r .transaction_id)

# 2. Refund 1 unit(s) of line-1 from the frozen snapshot
curl https://api.valulog.com/v1/refunds \
  -H "Authorization: Bearer $VALULOG_KEY" \
  -H "Idempotency-Key: demo-base-refund-1" \
  -H "Content-Type: application/json" \
  -d "{\"transaction_id\": \"$TX\", \"line_item_id\": \"line-1\", \"quantity\": 1, \"reason\": \"Customer return\"}"
Try it here first, no sign-in

The button keeps this payload in your browser and opens your dashboard (sign in with your email first if you are not already), where it is ready to run with your vl_test_ key.

Change the numbers and watch the refund

No sign-in. Edit the basket and the discount rules, then refund a line. This runs Valulog’s own pricing engine (engine 1.3.0) in your browser: nothing is sent or stored, and the IDs, hash and timestamps are generated for this simulation.

Basket (prices in pence)
LineSKUUnit priceQtyDiscountableRemove
line-1
line-2
Discount rules (applied in this order)

Result: how each discount was split

Refund part of the order

Refunds come from the frozen line, not today’s prices. Refund the same line again to see the over-refund guard; the last unit takes any leftover penny.

POST /v1/calculate · … response

…

Copies a ready-to-run curl script for this exact basket and refund, and keeps it on your dashboard. Free sandbox: no card, 1,000 operations a month.

Related