Do I actually make money on an order? Unit economics and contribution margin per order
TL;DR
Difficulty: Intermediate
Revenue says how busy you are, contribution says whether it pays.
- Contribution per order is net revenue minus every cost the order causes: cost of goods, payment fees, fulfilment, expected returns, then marketing.
- In the example, a shop with a 52% margin keeps £19.86 of a £72 order before ads and £12.79 after, and £5,820 a month after fixed costs.
- Split by category and basket size: small baskets bought with ads lose money, and breakeven ROAS ranges from 3.34 for lamps to 4.24 for furniture.
- Breakeven ROAS is price divided by contribution before marketing.
- Price a delivery threshold with the top up, pay or leave formula, then test it.
What to read first
An order comes in and the revenue line moves up. But how much of that order is actually yours once VAT, suppliers, payment providers, carriers, returns and ad platforms have taken their share? This chapter works it out line by line for one example shop, then per category, per basket size and straight from the shop database.
The question behind every order
An order comes in. The confirmation email goes out, the payment provider shows a green tick, and the revenue line on the dashboard moves up. It feels like money earned. But how much of that order is actually yours once everybody else has taken their share?
That is the question this chapter answers, and it is the most useful question a shop owner can ask. Revenue tells you how busy you are. Contribution tells you whether being busy pays. The two can point in opposite directions for months before the bank account settles the argument.
By the end you will be able to take any order, any product category or any basket size and say, to the penny, what it leaves behind. You will know which orders lose money, what a free delivery threshold really does, how high your return on ad spend has to be before an advert pays for itself, and how to pull all of it straight out of your shop database. If some of the terms are new, the glossary chapter of this series defines every one of them.
Example: Priya's two numbers
The example for the whole series is Wrenfield Home, an online homeware shop in Leeds run by Priya, with Callum as her developer. It sells ceramics, kitchen textiles, lamps and small furniture, around 1,400 products. The example's monthly baseline: 110,000 sessions, a conversion rate of 1.8%, so 1,980 orders (1,300 of them from new customers), an average order value of £72 including VAT, after discounts and excluding delivery, a gross margin of 52% on product, a return rate of 9% of orders, £14,000 a month on Google and Meta ads and £19,500 a month of fixed costs. Wrenfield Home currently delivers free on every order.
Priya knows two numbers by heart. Revenue is £142,560 a month (1,980 orders at £72). Margin is 52%. Multiply them in her head and it sounds like about £74,000 a month. By the end of this chapter you will have the real figure, worked out line by line. After every cost that moves with orders, ads and fixed costs, it is £5,820. Nothing is wrong with the shop. Every pound in between went somewhere real, and the point of unit economics is to know exactly where.
Contribution margin is the number that answers the question
Unit economics means looking at the business one unit at a time. In a shop the natural unit is the order. The number you want for each order is its contribution margin: what is left after you take away every cost that only exists because this order happened.
That last part is the whole trick. Some costs move with orders: the product itself, the payment fee, the parcel, the packaging, the minutes someone spends picking and packing, the chance the order comes back. Other costs do not move at all when one more order arrives: rent, salaries, software subscriptions, the accountant. Contribution takes away the first kind and leaves the second kind alone. Whatever contribution is left over is what pays for the fixed costs, and only after those are covered is there profit.
Here is the contribution margin of one order, is the revenue from that order after VAT, and is each variable cost the order causes, summed over all of them. It is a subtraction, nothing more, but every line in it hides a decision about what to count. If the idea of a margin as a share of revenue needs a refresher, see Foundations: ratios and rates.
Example: one order, all the lines
Here is the average Wrenfield Home order, which the rest of the chapter takes apart line by line. All figures are the example's.
| Line | Amount |
|---|---|
| Customer pays, including VAT | £72.00 |
| VAT | £12.00 |
| Net revenue | £60.00 |
| Cost of goods | £28.80 |
| Payment fees | £1.22 |
| Fulfilment (carrier, packaging, pick and pack) | £6.50 |
| Expected cost of returns | £3.62 |
| Contribution before marketing | £19.86 |
| Marketing per order | £7.07 |
| Contribution after marketing | £12.79 |
Of the £72 the customer pays, £12.79 is left to pay rent and wages. The next sections show where each number comes from, so you can build the same table for your own shop.
Take out VAT first, because it was never yours
The price a consumer pays in a UK shop includes VAT. The standard rate is 20%1. That money passes through your account on its way to HMRC. It is not revenue, it is a debt you collect on someone else's behalf.
is the price the customer paid including VAT, is the VAT rate as a decimal ( for 20%), and is what remains for you. Note that VAT is of a VAT inclusive price at 20%, not 20% of it. Taking 20% off £72 gives £57.60, which is wrong by £2.40 on every order. Foundations: percentages explains why a percentage of a total and a percentage added on top are not the same thing.
Example: VAT on the average order
So pounds of the price is VAT and £60.00 is Priya's net revenue. The trap shows up when someone calculates a margin against the gross price. £72.00 minus £28.80 cost of goods looks like £43.20, a "60% margin". The true figure on net revenue is £31.20, or 52%. Every later number inherits whichever mistake you make here, so the rule is simple: every margin in this chapter is calculated on net revenue.
Discounts come off your margin, not just off the price
The 52% Priya quotes is the margin she actually achieves, after discounts. At full price it would be higher. Some orders use a newsletter code, some products are on sale, and a few customers get a goodwill voucher. A discount does not reduce cost of goods at all, so every pound of discount comes straight out of margin.
That is why a 10% discount feels small to the customer and large to the shop. If your margin is 52%, a 10% discount removes almost a fifth of what you earn on that product. The chapter on offers and promotions works through that maths in full. Here only its effect on the average order matters.
Example: what Wrenfield Home's discounts cost
At full price, the goods in the average basket would cost the customer £78.00. Discounts take off £6.00, leaving the £72.00 actually paid. Cost of goods is £28.80 either way. At full price the net revenue would have been pounds, so the margin at full price is:
That is . After discounts it is:
So the full price margin of 55.7% becomes 52.0% in the orders. In money, the £6.00 of discount is pounds of net revenue per order that would otherwise have been pure margin, so on 1,980 orders £9,900 a month. Nobody decided to spend that much. It just accumulated, code by code.
Cost of goods means everything it took to get the product on the shelf
Cost of goods sold, or COGS, is what the products in the order cost you. The common mistake is to use only the supplier's unit price. The honest number is the landed cost: the purchase price, plus inbound freight, plus import duty where it applies, plus any cost of preparing the product to be sold (labelling, quality checks, the inner carton a fragile mug needs before it can go on a shelf).
Once you have landed cost, the first level of contribution falls out directly. I will call it CM1, contribution margin one: net revenue minus cost of goods.
is the first contribution level, is net revenue as above and is the landed cost of everything in the order (Foundations: ratios and rates). CM1 tells you whether your pricing works at all. If CM1 is thin, nothing further down the page can rescue the order.
Example: CM1 for the average order
As a share of net revenue that is , the 52% Priya knows. Roughly half of each net pound survives the first cut. The other half went to her suppliers and the freight company. If a supplier puts prices up by 5% and Priya does not, cost of goods becomes and CM1 falls to £29.76, which costs her almost £2,900 a month before anything else has changed.
Payment fees are a percentage plus a fixed amount
Every card or wallet payment costs a fee, and almost every provider prices it the same way: a percentage of the amount, plus a fixed amount per transaction. The fixed part is why small orders feel the fee far more than large ones.
For a UK business, Stripe's published price for standard UK cards is 1.5% plus 20p per successful payment. Premium UK cards cost 2.8% plus 20p, cards from the European Economic Area 2.5% plus 20p and other international cards 3.15% plus 20p, with 2% more if a currency conversion is needed. Stripe also states that when you refund a payment, the original processing fee is not returned (all checked on Stripe's UK pricing page on 22 November 2026)2. That last point matters for returns.
is the fee on one order, is the amount charged including VAT (fees are charged on what the customer actually pays), is the percentage rate as a decimal and is the fixed fee per transaction. If you take several payment methods, and become weighted averages, weighted by how many orders use each method. A weighted average is covered in Foundations: mean.
Example: what Priya pays in fees
The series uses a blended figure of about 1.7% of order value for Wrenfield Home's mix of cards and wallets. On the average order:
For comparison, a single standard UK card payment through Stripe on the same order costs pounds, or 1.78%. So the blended 1.7% is plausible, and a shift towards premium cards or more expensive wallets would push it up. Check your own figure against your provider statements, not against a price page.
Now the fixed part. On a £14 mug paid by card the fee is pounds, which is 2.9% of the basket. Small orders pay a higher fee rate because the 20p does not shrink with them. The example keeps the flat 1.7% for simplicity, so for small baskets it slightly flatters the numbers.
Fulfilment: carrier, packaging and pick and pack
Three costs sit between the warehouse shelf and the customer's door, and shops often lump them together. Keep them apart in your own records, because they move for different reasons.
- Carrier cost is what the parcel company charges you, per parcel, on your contract. It depends on size and weight far more than on value. A lamp shade in a big box costs more to send than a pair of earrings worth ten times as much.
- Packaging is the box, the filler, the tape and, for ceramics, the protective wrap that stops a mug arriving in three pieces.
- Pick and pack is the labour: finding the items, checking them, packing them, printing the label. Measure it as minutes per order times the loaded hourly cost of the person doing it.
The £72 order value excludes delivery. If you charge for delivery, that charge is revenue and belongs in net revenue. Do not net it against the carrier cost in your head. Keep revenue as revenue and cost as cost, otherwise you cannot see what a delivery offer changes.
Example: fulfilment on the average order
Wrenfield Home's fulfilment averages £6.50 per order: £3.90 carrier, £0.90 packaging and £1.70 pick and pack. The spread behind that average is wide. A parcel of tea towels costs £3.40 to send out in total, a sideboard needs a two person delivery and costs £21.70. Because Wrenfield Home delivers free, all of it is cost with no delivery income against it. That is a choice, and later in the chapter it gets a price.
Returns are an expected cost on every order
Here is the line most order level calculations leave out. A returned order does not simply cancel itself. Some of its costs are gone for good, and the return creates new ones.
When a customer in the UK cancels an online purchase within the cancellation period, the trader must refund what the customer paid, including the standard delivery charge, within 14 days of being told (in the usual case for goods, counted from receiving them back or from proof they were sent)3. The shop gets the product back. What it does not get back: the outbound carrier cost, the packaging, the picking labour and the payment fee, which Stripe keeps on a refund2. Those costs are already on every order's bill above, kept or not. On top, the return itself costs money: return postage if the shop pays it, the time to inspect and restock, and an allowance for goods that cannot be sold again. This is general information about the rules, not legal advice. The chapter on returns covers the law, return rates and what to do about them in depth.
Since you do not know which order will come back, you charge every order its expected share. That is an expected value: the probability of a return times what the return costs.
is the expected cost of returns carried by every order, is the return rate as a decimal, is the margin you lose when the sale is undone (net revenue minus cost of goods, since the goods go back on the shelf) and is the handling cost of one return (return postage, inspection, restocking and the allowance for write offs). See Foundations: expected value if expected values are new.
Example: the expected return cost at Wrenfield Home
For the average order, the margin lost on a return is the £31.20 of CM1, and handling a return costs Priya £9.00. With a return rate of 9%:
So pounds is charged to every order, even the 91% that stay. Now the same for a lamp order: £98.00 paid, £81.67 net, £40.84 cost of goods, so . Lamps come back on 6% of orders and a lamp return costs £9.00 to handle:
So pounds: a lamp order carries £2.99 of expected return cost. The same method per category follows below.
Marketing per order
The last variable cost is the one that brought the customer in. The simplest honest version is total ad spend divided by total orders. It is crude, and later sections refine it, but it is the right starting point because no attribution setting can flatter it.
Two warnings. First, this average spreads the cost of winning new customers over repeat orders that cost little or nothing to win. The chapter on customer acquisition cost separates the two and shows why a first order may rightly lose money. Second, an average is not a margin. The last £1,000 of ad spend usually buys fewer orders than the first £1,000. Foundations: marginal versus average explains the difference, and the chapter on ROAS, POAS and MER uses it to steer budgets.
Example: marketing per Wrenfield Home order
So pounds per order goes to Google and Meta. Subtracted from the £19.86 left after returns, that leaves £12.79. Spread only over the 1,300 orders from new customers, the same budget is pounds per new customer, the starting point of the next chapter. The figure covers only the ad platforms. If Priya pays an agency fee, a tool for email or influencer gifts, they belong here too.
Three levels of contribution, and why each one exists
You now have every line. Grouping them into levels turns a long list into three questions you can ask about any order, product or channel.
| Level | Calculation | The question it answers |
|---|---|---|
| CM1 | Net revenue minus cost of goods | Does the price work against what the product costs? |
| CM2 | CM1 minus payment fees, fulfilment and expected returns | Does the order work once it has to be delivered and might come back? |
| CM3 | CM2 minus marketing | Does it still work once you have paid to win it? |
A note for anyone who works with German accounts. The German terms Deckungsbeitrag I, II and III look like the same three levels, but in the classic cost accounting textbook they are built differently: DB I is revenue minus variable costs, DB II then subtracts fixed costs that belong to one product, and DB III fixed costs that belong to a product group or division4. Online retailers often use the labels for variable cost layers per order instead, as above. Neither is wrong, but say which one you mean when two people compare numbers.
Example: the three levels as a waterfall
Here is the whole average order in one picture. Each bar shows what one line takes away, and the full bars show the running totals.
Across the month, CM2 is pounds. Take off the £14,000 of ads and £25,320 is left. Take off £19,500 of fixed costs (rent, wages including Priya's own, software, insurance) and the profit is £5,820 a month. On £1.71 million of revenue a year, that is a thin cushion. A cost that rises by 30p per order (a carrier surcharge, a shift to premium cards) takes pounds a month, a tenth of the profit. And the average hides orders that earn well and orders that quietly lose, which the next sections show.
The average order does not exist, so split by category
An average order is a useful summary and a dangerous guide. Averages describe nobody in particular, a point the article on why averages mislead makes at length. Run the same calculation per product category and the shop looks different.
The method is identical to the average order: price paid, VAT, cost of goods at that category's margin, the payment fee, that category's own fulfilment, and its own return rate and return handling cost.
Example: a mug, a lamp and a sideboard
All figures per order and from the example. They are rounded, so the weighted average of the last rows differs from £19.86 by a penny.
| Per order | Ceramics | Kitchen textiles | Lamps | Small furniture |
|---|---|---|---|---|
| Share of orders | 35% | 30% | 25% | 10% |
| Paid, including VAT | £38.00 | £32.00 | £98.00 | £246.00 |
| Net revenue | £31.67 | £26.67 | £81.67 | £205.00 |
| Cost of goods | £13.30 | £10.67 | £40.84 | £107.37 |
| Payment fees | £0.65 | £0.54 | £1.67 | £4.18 |
| Fulfilment | £4.60 | £3.40 | £6.80 | £21.70 |
| Contribution if kept | £13.12 | £12.06 | £32.36 | £71.75 |
| Return rate | 8.0% | 11.9% | 6.0% | 11.4% |
| Handling per return | £7.00 | £6.00 | £9.00 | £23.23 |
| Expected returns cost | £2.03 | £2.62 | £2.99 | £13.78 |
| CM2 | £11.09 | £9.44 | £29.37 | £57.97 |
| CM2 as share of net revenue | 35.0% | 35.4% | 36.0% | 28.3% |
Per order, small furniture earns the most by far. Per pound of revenue, it earns the least: 28.3% against about 35% everywhere else, because a two person delivery, a collection and a higher return rate eat into it. Kitchen textiles have the opposite problem. A margin of 60% looks excellent, but a basket of £32 leaves only £9.44, and once the average £7.07 of marketing is taken off, pounds remain. Nearly 12% of textile orders come back, mostly because colours look different on screen.
This gives Priya two concrete levers. If better colour photos bring textile returns down from 11.9% to 6%, the expected returns cost becomes and CM2 per textile order rises from £9.44 to £10.74, or about £770 a month across 594 textile orders. If room photos and exact dimensions bring furniture returns from 11.4% to 7%, the expected cost becomes , CM2 per sideboard order rises from £57.97 to £63.29, about £1,050 a month across 198 orders. Neither needs one extra visitor.
Small orders that lose money
A mug order and a sideboard order differ in value, but some costs are almost the same for both: the label, the box, the minutes at the packing bench. Those fixed per order costs are why every shop has a basket size below which an order loses money.
You can find that basket size with a simple straight line. Each extra pound of basket brings in a contribution rate , and each order costs a fixed amount regardless of its size.
is the contribution of an order with basket value (including VAT, and see Foundations: regression for straight lines of this kind), is the contribution per pound of basket after cost of goods, fees and expected returns, and is the fixed cost per order. The break even basket is where :
is the smallest basket that covers its own costs. The formula is the straight line solved for zero, the same idea as in Foundations: ratios and rates. Add marketing per order to and you get the break even basket after paying for the customer.
Example: the break even basket at Wrenfield Home
Small baskets at Wrenfield Home are mostly ceramics and textiles: a margin of about 58%, a return cost of about 5% of basket value. Per pound of basket including VAT, Priya keeps of margin, minus of payment fee, minus for expected returns:
A small parcel costs to fulfil. Before marketing:
Any basket above £11.05 covers its own costs. Add the average £7.07 of marketing and the break even basket is pounds. A single £15 mug makes pounds before marketing. If that customer arrived through an ad that cost the average £7.07, the order loses £5.43.
Two cautions before cutting small orders. First, the average £7.07 is not what a particular small order cost to win. A customer who came back from the newsletter cost almost nothing, and for them the before marketing bar is the right one. Second, a small first order can be the start of a valuable customer. Whether it is worth losing money on is the question of the chapter on acquisition cost and payback. What the chart does say is that small baskets bought with paid ads lose money on the order itself, and that a delivery charge on small baskets is worth pricing.
The maths of a free delivery threshold
Extra costs are the most common reason people give for leaving a checkout. In Baymard Institute's research, once the shoppers who were "just browsing" are set aside, 40% of the remaining abandonment reasons are "extra costs too high (shipping, tax, fees)"5. So free delivery sells. The question is whether it pays.
The best known study of this is by Lewis, Singh and Fay, who analysed an online retailer that had tried many different delivery fee schedules. They found customers very sensitive to delivery charges, and free delivery and threshold offers very effective at generating extra sales, but the lost delivery revenue and the many customers who did not respond made those promotions unprofitable for that retailer6. Both halves of that finding matter. Free delivery works on behaviour and can still lose money, and a charge can cost orders and still make money.
Who tops up, who pays, who walks away
Any threshold, whether you introduce one, raise one or lower one, affects only the customers whose baskets fall in the band that changes. Each of them does one of three things: adds items to reach the threshold, pays the delivery charge, or leaves. Write down what each choice is worth and you have the whole decision.
is the change in monthly contribution, the number of orders a month in the affected band, , and the shares who top up, pay or leave (they add up to 1), the contribution per pound of basket from the previous section, the average top up, the delivery charge net of VAT and the contribution of an order you lose. Each term is a probability times a value, so this is an expected value again, as in Foundations: expected value.
Example: free delivery only from £35
Priya considers charging £4.95 for delivery on baskets under £35 and keeping it free above. In the example, 640 orders a month fall under £35, averaging £24. She estimates that 30% of those customers would add something, on average £14 worth, 50% would pay the charge and 20% would leave.
The pieces: a top up earns pounds, a paid charge brings pounds net (ignoring the few pence of payment fee), and a lost £24 order would have earned pounds.
- Top ups:
- Paid delivery:
- Lost orders:
About £1,750 a month better, almost a third of the current profit. Now a gloomier case: only 20% top up, 30% pay and half the customers leave. Then , a small loss.
Solving for the walk away share that makes , with 30% still topping up:
So : the charge only loses money on these orders if almost half of the small basket customers walk away. That margin of safety is large, but the formula counts only this order. Many small baskets are first orders from new customers, and a customer who walks away never makes the second purchase. That is exactly the cost the study above warns about, and it is why the decision ends in a test rather than in a spreadsheet.
Measure the test on contribution per visitor, not on conversion rate or average order value. A threshold can lift average order value and still lose money, and a charge can cut conversion and still earn more. The chapter on experiments inside your own shop shows how to split traffic and how long to run such a test.
Breakeven ROAS and breakeven CPA come straight from contribution
Return on ad spend, or ROAS, is the revenue an advertising platform attributes to your ads divided by what you spent. Google's own help page calculates it that way, for example £5 of sales for £1 of ad spend is a ROAS of 500%7. The number is everywhere, and on its own it says nothing about profit. A ROAS of 4 is comfortable for one shop and a loss for another. What turns it into a decision is the breakeven point, and contribution gives you that directly.
The most you can pay for an order without losing money is its contribution before marketing. That is the breakeven cost per acquisition, or CPA. Divide the revenue the platform counts by that figure and you have the breakeven ROAS.
is the highest ad cost per order that still breaks even, is contribution before marketing per order and is the revenue per order exactly as the platform counts it. Check that last part in your settings: if your tracking sends revenue including VAT, use the price including VAT. The ratio idea is in Foundations: ratios and rates.
If you want each order to leave a profit after marketing, subtract it first: the target CPA is and the target ROAS is .
Example: what ROAS Wrenfield Home needs
For the average order, with revenue sent including VAT:
If Callum set the tracking to send net revenue, the breakeven would be instead. Same shop, same economics, different number, which is why the VAT setting has to be known before anyone compares ROAS figures.
If Priya wants £5.00 per order after ads, the target CPA is and the target ROAS is .
Now per category, again with revenue including VAT:
| Category | Paid per order | CM2 per order | Breakeven ROAS |
|---|---|---|---|
| Ceramics | £38.00 | £11.09 | 3.43 |
| Kitchen textiles | £32.00 | £9.44 | 3.39 |
| Lamps | £98.00 | £29.37 | 3.34 |
| Small furniture | £246.00 | £57.97 | 4.24 |
Suppose a lamp campaign and a furniture campaign both report a ROAS of 3.8, comfortably above the shop's 3.63. For a lamp order, the ad cost is pounds against £29.37 of contribution, so £3.58 is left. For a furniture order it is pounds against £57.97, a loss of £6.77 on every order. One target ROAS for the whole shop treats both campaigns as equally good. The fix is to send contribution rather than revenue as the conversion value, which the article on auto bidding with your own data explains step by step, and the chapter on ROAS, POAS and MER builds into a weekly steering routine. When a customer returns to buy again, the first order can carry a higher CPA, which is the subject of the chapter on acquisition cost and payback.
Building the per order profit view from your shop database
Everything above can live in a spreadsheet, but a spreadsheet is a snapshot. The shop database knows every order, every line, every refund. If your shop runs on Solidus, the open source Ruby on Rails framework I build shops on, most of what you need is already stored. A few things are not, and knowing which is half the work.
What Solidus stores for you (verified against its database schema8):
spree_ordersholdstotal,included_tax_total(VAT inside the prices, the UK case),additional_tax_total(tax added on top, the case for shops that show prices before tax),promo_total,stateandcompleted_at.spree_line_itemsholdsquantity,priceandcost_price. Solidus copies the variant's cost price onto the line item when the item is added, so later changes to the product's cost do not rewrite history9.spree_paymentsholds each payment'samount,stateandpayment_method_id.spree_reimbursementsholds refunds per order with areimbursement_status, andspree_return_itemsrecords each returned unit with itsreception_statusand whether it isresellable.
What it does not store: what the carrier charged you, and what a payment provider charged you. The cost column on spree_shipments is what the customer was charged for delivery, not what the parcel cost. Using it as a cost is one of the most common mistakes in shop reporting. Since Solidus 4.5, orders, shipments, payments and customer returns have an admin_metadata column for your own data10, which is a tidy place to keep the real carrier cost and the real return cost.
Example: Callum records the real carrier cost
Each week the carrier sends Priya an invoice file with the tracking number and the net cost of every parcel. Callum imports it into the shipment it belongs to:
# Store the carrier's invoiced cost on each shipment
CSV.foreach(path, headers: true) do |row|
shipment = Spree::Shipment.find_by(tracking: row["tracking_number"])
next unless shipment
shipment.update!(
admin_metadata: shipment.admin_metadata.merge("carrier_cost" => row["net_cost"].to_d)
)
end
The loop reads one line per parcel, finds the shipment by its tracking number and adds the cost to that shipment's metadata without touching anything else. Return costs (return postage plus the minutes spent inspecting) go onto each customer return the same way, under return_cost.
Example: the contribution query
With that in place, one PostgreSQL query gives the contribution of every order. It is long but not hard: each block collects one cost per order, and the last block subtracts them. The first part gathers revenue and the costs every order has.
-- Step 1: revenue and the costs every completed order carries
CREATE VIEW order_costs AS
WITH fee_rates (method_name, pct, fixed) AS (
VALUES ('Card', 0.015, 0.20), ('PayPal', 0.029, 0.30)
),
goods AS (
SELECT order_id, SUM(quantity * COALESCE(cost_price, 0)) AS cogs
FROM spree_line_items GROUP BY order_id
),
fees AS (
SELECT pay.order_id, SUM(pay.amount * r.pct + r.fixed) AS payment_fees
FROM spree_payments pay
JOIN spree_payment_methods pm ON pm.id = pay.payment_method_id
JOIN fee_rates r ON r.method_name = pm.name
WHERE pay.state = 'completed'
GROUP BY pay.order_id
),
parcels AS (
SELECT order_id,
SUM(COALESCE((admin_metadata ->> 'carrier_cost')::numeric, 0)) AS carrier_cost,
COUNT(*) * 2.60 AS pack_and_pick -- average packaging plus labour per parcel
FROM spree_shipments WHERE state = 'shipped' GROUP BY order_id
)
SELECT o.id AS order_id, o.number, o.completed_at,
o.total - o.included_tax_total - o.additional_tax_total AS net_revenue,
COALESCE(g.cogs, 0) AS cogs,
COALESCE(f.payment_fees, 0) AS payment_fees,
COALESCE(p.carrier_cost, 0) + COALESCE(p.pack_and_pick, 0) AS fulfilment
FROM spree_orders o
LEFT JOIN goods g ON g.order_id = o.id
LEFT JOIN fees f ON f.order_id = o.id
LEFT JOIN parcels p ON p.order_id = o.id
WHERE o.completed_at IS NOT NULL AND o.state <> 'canceled';
The fee_rates list holds the rates from your own payment contracts and must use the names you gave your payment methods in the Solidus admin. The 2.60 is the example's average for packaging and pick and pack per parcel. The second part adds what returns took back and gives contribution per order.
-- Step 2: refunds, restocked goods and return costs, then CM2 per order
WITH refunds AS (
SELECT order_id, SUM(total) / 1.20 AS refunded_net -- 20% VAT comes back with the refund
FROM spree_reimbursements WHERE reimbursement_status = 'reimbursed'
GROUP BY order_id
),
returned_units AS (
SELECT li.order_id, ri.customer_return_id, ri.resellable, li.cost_price
FROM spree_return_items ri
JOIN spree_inventory_units iu ON iu.id = ri.inventory_unit_id
JOIN spree_line_items li ON li.id = iu.line_item_id
WHERE ri.reception_status = 'received'
),
restocked AS (
SELECT order_id, SUM(cost_price) AS cogs_back
FROM returned_units WHERE resellable GROUP BY order_id
),
return_costs AS (
SELECT x.order_id, SUM(COALESCE((cr.admin_metadata ->> 'return_cost')::numeric, 0)) AS return_cost
FROM (SELECT DISTINCT order_id, customer_return_id FROM returned_units) x
JOIN spree_customer_returns cr ON cr.id = x.customer_return_id
GROUP BY x.order_id
)
SELECT c.number,
ROUND(c.net_revenue - COALESCE(r.refunded_net, 0)
- (c.cogs - COALESCE(s.cogs_back, 0))
- c.payment_fees - c.fulfilment
- COALESCE(rc.return_cost, 0), 2) AS cm2
FROM order_costs c
LEFT JOIN refunds r ON r.order_id = c.order_id
LEFT JOIN restocked s ON s.order_id = c.order_id
LEFT JOIN return_costs rc ON rc.order_id = c.order_id
WHERE c.completed_at >= date '2026-08-01' AND c.completed_at < date '2026-09-01'
ORDER BY cm2;
Read it in plain words. A refund removes revenue, so it is subtracted net of VAT. A returned unit that can be sold again puts its cost back on the shelf, so its cost of goods is added back. A unit that cannot be sold again stays as a cost, which is exactly a write off. The payment fee and the outbound delivery stay as costs whether or not the order came back, which matches Stripe's rule that the fee is not returned2. The query looks at August while it is run in late October, because returns arrive weeks after the order. Look at last week's orders and you will see a shop with almost no returns, and a contribution that is too good to be true.
Example: three orders from the result
Three rows from Priya's August result, worked through by hand so you can check the query on your own data:
| Order | What happened | Net revenue kept | Cost of goods | Fees | Fulfilment | Return cost | CM2 |
|---|---|---|---|---|---|---|---|
| R482103776 | One mug, £14, card | £11.67 | £4.90 | £0.41 | £5.20 | £0.00 | £1.16 |
| R482119054 | One lamp, £98, card, kept | £81.67 | £40.84 | £1.67 | £7.20 | £0.00 | £31.96 |
| R482127310 | One sideboard, £246, PayPal, returned and resellable | £0.00 | £0.00 | £7.43 | £22.20 | £23.30 | minus £52.93 |
The lamp: . The sideboard: revenue fully refunded ( removed), cost of goods fully restocked, but pounds gone. One returned sideboard wipes out the contribution of more than one and a half kept lamp orders, and the mug barely covers its own box. Sort the result by contribution, as the query does, and the orders that cost money stand at the top of the list every month, where they cannot hide.
A monthly routine that keeps the numbers honest
Unit economics are not a one off calculation. Prices, carrier contracts, payment mixes and return rates drift, and each drift moves contribution. A short routine, once a month, keeps the numbers current.
| Step | What to check | Why |
|---|---|---|
| 1 | Cost prices on new products and supplier price changes | A missing cost price makes an order look like pure profit |
| 2 | The carrier invoice against what is stored per shipment | Fuel surcharges and size bands creep in quietly |
| 3 | Payment mix and effective fee rate | A shift towards premium cards or wallets raises the fee line |
| 4 | Return rate and return cost by category, on orders at least 45 days old | Returns lag, so young orders flatter the numbers |
| 5 | CM2 by category and by basket band | Shows where the next pound of effort pays most |
| 6 | Breakeven ROAS per category against what the platforms report | Catches campaigns that look good and lose money |
Example: Priya's first routine
In her first month, step 1 finds 37 products without a cost price, all from one new lamp supplier. Their orders were showing a contribution of over £80 each. Step 4 shows textile returns at nearly 12%, which moves better colour photography to the top of Callum's list. Step 6 shows the furniture campaign at a reported ROAS of 3.8 against a breakeven of 4.24, so Priya moves part of its budget to lamps until the furniture return rate falls. None of these decisions needed a new tool. They needed the numbers in the right order.
Conclusion
Revenue counts what customers pay. Contribution counts what stays. In the example, a shop with a 52% margin keeps £19.86 of a £72 order before marketing and £12.79 after it, and after fixed costs a business turning over £1.71 million a year makes £5,820 a month. The average hides small baskets that lose money once they are paid for with ads, and categories whose breakeven ROAS differs enough to turn a good looking campaign into a loss.
The method is the same for any shop. Take out VAT, account for discounts, then cost of goods, payment fees, fulfilment and the expected cost of returns, and only then marketing. Do it per category and per basket size, not just on average. Use the result to set breakeven ROAS per category, to price a delivery threshold before you test it, and to find the orders that cost you money. Then get the numbers out of the database every month, so the next decision rests on what happened rather than on what the dashboard implied.
I build shops on Ruby on Rails and Solidus where every one of these costs is recorded where the order lives, and I run the analytics and the advertising for clients on the same numbers. If you want to know what your own orders really leave behind, that is a good first conversation.