ValulogDashboard

How to refund one line of a discounted order

Published

A customer buys two T-shirts at £20 and a mug at £10 with 10% off the whole order, then returns one T-shirt. Refunding the £20 shelf price over-refunds; refunding 10% off a guess can be a penny out. The right figure depends on how the discount was split when the order was placed.

Split the discount when the order is placed

Send the basket and its discount rules to POST /v1/calculate. Valulog splits each discount across the eligible lines, in integer pence, and stores the result as a frozen snapshot with a hash.

For this basket the £5.00 discount is split £4.00 on the T-shirt line (two units) and £1.00 on the mug, so the T-shirt line was paid £36.00 and the mug £9.00.

Refund from the snapshot, not from today’s prices

To refund one T-shirt, call POST /v1/refunds with the transaction_id, the line_item_id and quantity 1. Valulog reads the frozen line (£36.00 for two units) and refunds £18.00.

Prices or promotions you change later do not affect the refund, because nothing is recalculated. The refund is recorded against the line, so the remaining refundable amount is always known.

Rounding that never strands a penny

Per-unit values use round-half-even on integers. When the last units on a line are refunded they take whatever remains, so a line can never be refunded for more, or less, than was paid for it in total.

Where the money moves

Valulog does not move money. Use the refund_amount_cents it returns when you create the refund in your payment provider, and keep the refund_id alongside the provider’s refund reference.

Refund one T-shirt (curl)
curl https://api.valulog.com/v1/refunds \
  -H "Authorization: Bearer $VALULOG_KEY" \
  -H "Idempotency-Key: return-7781" \
  -H "Content-Type: application/json" \
  -d '{ "transaction_id": "<transaction_id from /v1/calculate>",
        "line_item_id": "line-1", "quantity": 1, "reason": "Customer return" }'
# → "refund_amount_cents": 1800, "remaining_refundable_cents": 1800

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

10% off two T-shirts and a mug: 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-tenoff-calc" \
  -H "Content-Type: application/json" \
  -d '{
  "currency": "GBP",
  "items": [
    {
      "id": "line-1",
      "sku": "TEE",
      "unit_price_cents": 2000,
      "quantity": 2
    },
    {
      "id": "line-2",
      "sku": "MUG",
      "unit_price_cents": 1000,
      "quantity": 1
    }
  ],
  "discounts": [
    {
      "rule_id": "TENOFF",
      "type": "PERCENTAGE",
      "basis_points": 1000,
      "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-tenoff-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