Skip to content
Tutorials Center
My learning

Topics

Lesson 22 of 40 ยท Shipping and Fulfillment

Fulfillment, Returns and Refunds

Understand order fulfillment from pick, pack and ship to split shipments, tracking, 3PLs, RMAs, restocking, refunds versus exchanges versus store credit and reverse logistics.

An order is not finished when the customer pays. Someone still has to find the goods, put them in a box, hand them to a carrier and make sure the customer knows where the parcel is. Later, some customers send items back. How well a shop handles these two flows, fulfillment and returns, decides whether people buy from it again. It also decides how much money it quietly loses: online fashion shops, for example, often see a large share of orders come back.

This lesson explains the physical flow, how to model it in software, and how refunds, exchanges and store credit differ. It builds on The Order Lifecycle and State Machines, which keeps payment and fulfillment as separate states, and on Authorization, Capture, Refunds and Chargebacks for the money side.

From paid order to parcel: pick, pack, ship

Inside a warehouse (or a back room) fulfillment follows three steps:

  1. Pick. A worker, or a robot, collects the items for an order. Pick lists are sorted by shelf location so people walk the shortest path. Many warehouses pick several orders at once ("batch picking") and sort them later.
  2. Pack. Items are checked against the order (scanning barcodes catches mistakes), put in a suitable box with padding, and the packing slip goes in.
  3. Ship. A label with a tracking number is created and attached, the parcel is handed to the carrier, and the shop marks the shipment as shipped. This usually triggers the "your order is on its way" e-mail.

The software side is a fulfillment (or shipment) record, separate from the order. An order can have several fulfillments, and each has its own items, quantities, carrier, tracking number and status. Keep the order's own status derived from them: unfulfilled, partially fulfilled, fulfilled.

flowchart LR
    A["Order paid"] --> B["Allocate stock<br/>and location"]
    B --> C["Pick"]
    C --> D["Pack"]
    D --> E["Label + tracking"]
    E --> F["Handed to carrier"]
    F --> G["Delivered"]

The fulfillment pipeline. Each step can fail or be repeated, so each needs a recorded status.

Split shipments

One order often leaves in more than one parcel:

  • Items sit in different warehouses or locations.
  • One item is backordered and arrives later (see Inventory Tracking).
  • The goods are too heavy or too many for one box.
  • Some items are digital or made to order.

Decisions follow: charge shipping once or per parcel? Send all items at once to save postage, or ship what you have so the customer gets something sooner? Whatever you choose, tell the customer clearly, send a tracking e-mail per parcel, and let a partial refund or cancellation cover only the unshipped lines.

The data model that works: an orders table, order_lines, and fulfillments with fulfillment_lines pointing at order lines with a quantity. The sum of fulfilled quantity per line can never exceed the ordered quantity. The next example shows exactly that rule.

Python Fulfillment lines and split shipments

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The order status is computed from the shipments instead of being set by hand, so the two cannot disagree. The rejected call shows the key invariant: you can never ship more than was ordered.

Tracking

A tracking number identifies a parcel in the carrier's system. Store it with the carrier code on the fulfillment, and build the tracking link from both. Carriers report scan events (accepted, in transit, out for delivery, delivered, exception). You can poll their API or, better, subscribe to their webhooks, using the signature and deduplication ideas from Webhooks and Signature Verification. Mirror the main statuses onto your shipment record so the customer's account page and e-mails can say "out for delivery" without calling the carrier on every page view. A common extra status is delivery exception (damaged, address problem, held at customs); route those to support instead of leaving them silent.

Using a 3PL

Many shops do not run their own warehouse. A third-party logistics provider (3PL) stores your stock, packs orders and ships them. The integration usually works like this:

  • You send inbound shipments (purchase orders) so they expect stock.
  • You send each paid order to the 3PL through an API, file or app connector.
  • They return shipment confirmations with tracking numbers and inventory snapshots.

Things that need care: whose numbers are the source of truth for stock (the 3PL's counts are physical, yours are logical), how long they take to receive and ship, cut-off times, and what happens when an order is changed or cancelled after you sent it. Because messages can fail or repeat, apply the idempotency techniques from Idempotency and Reliable Payments. More on syncing external systems comes in Integrations: ERP, PIM, OMS and Marketplaces.

Returns: the RMA process

When a customer wants to send something back, shops use a return merchandise authorization (RMA): a record of the request that gets a number, so the warehouse knows what to expect. The usual flow:

  1. The customer requests a return, picking lines, quantities and a reason (too small, damaged, changed my mind, wrong item).
  2. The shop checks the policy: return window, item condition, final-sale products, and the legal minimum rights of the region (see GDPR, Consumer Law and Accessibility).
  3. The shop approves the request and issues a return label, or asks for photos if the item is damaged.
  4. The customer ships the parcel back.
  5. The warehouse receives and inspects it: resellable, damaged, or not what was ordered.
  6. The shop resolves it: refund, exchange or store credit.
  7. Resellable stock is restocked; the rest is repaired, liquidated or discarded.
stateDiagram-v2
    [*] --> requested
    requested --> approved
    requested --> rejected
    approved --> in_transit: label issued
    in_transit --> received
    received --> inspected
    inspected --> refunded: refund
    inspected --> exchanged: exchange
    inspected --> credited: store credit
    inspected --> rejected: item not eligible
    refunded --> [*]
    exchanged --> [*]
    credited --> [*]
    rejected --> [*]

An RMA moves through well-defined states, and only the inspection step decides the outcome.

Refund, exchange or store credit

  • Refund. Money goes back to the original payment method. This is what many laws require inside the withdrawal period. Partial refunds are normal (a damaged item, a restocking fee where allowed, or shipping that stays non-refundable).
  • Exchange. The customer receives a different size, color or product instead. Model it as a return plus a new (usually zero-balance or price-difference) order, so stock and money both stay correct.
  • Store credit. The shop issues a balance usable on a later purchase. It keeps the money in the business, so shops like it, and some customers accept it for faster resolution. Where the law gives a right to a refund, store credit has to be the customer's choice and not a forced replacement.

Compute refunds from the prices actually paid, not current catalog prices. If a 20% order discount was spread across lines, the refund of one line is its discounted amount plus its share of tax. Keep integer minor units and decide a clear rule for the cent that does not divide evenly (see allocation in Representing Money Correctly).

Python An RMA with legal states and a refund calculation

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The refund for one unit is a third of the line's net price plus a third of its tax. Because a line total can be split unevenly in other cases, production code keeps a running "refunded so far" amount and gives the last refund whatever remains.

Reverse logistics and restocking

Returned goods are not automatically sellable. Reverse logistics is the work of receiving, inspecting, grading and disposing of them. Give each returned unit a disposition: restock as new, restock as open-box, send to refurbishing, return to supplier, or scrap. Only the first adds back to available stock, and it should do so as a recorded stock movement on the ledger from Inventory Tracking, not by editing a number. Track return reasons: a product with many "too small" returns has a sizing problem, and "arrived damaged" points to packaging or a carrier.

Fraud exists here too: wardrobing (wearing then returning), returning a different item, or claiming non-delivery. Inspection, photos and limits on repeat returners help; the risk topics continue in Fraud and Risk Management.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Why should an order's fulfillment status be derived from its shipment records?

    Computing the status from shipped versus ordered quantities keeps one source of truth, and partial fulfillment falls out of the same rule.
  2. 2. What invariant should a fulfillment system enforce for every order line?

    Over-shipping gives away stock for free. Check the remaining quantity before creating a fulfillment line.
  3. 3. What is an RMA?

    A return merchandise authorization gets a number, lines and a reason, and moves through states such as requested, approved, received and resolved.
  4. 4. A 20% order-level discount was applied. How much should a one-line refund be based on?

    Refunds mirror what was paid. Catalog prices change, and list prices ignore discounts, so both give wrong amounts.
  5. 5. A returned item arrives scratched and is sold later as open-box. How should available stock change?

    Every change to stock should be a ledger movement with a reason, and the disposition decides whether it adds to sellable stock and to which pool.

Summary

  • Fulfillment is pick, pack and ship; model it as separate fulfillment records with lines, carrier and tracking, and derive the order's fulfillment status from them.
  • Orders split into several shipments for warehouse, stock or size reasons; never ship more than was ordered.
  • Use carrier webhooks or polling to mirror tracking status, and handle delivery exceptions.
  • A 3PL holds your physical stock; keep integrations idempotent and decide whose counts win.
  • Returns go through an RMA state machine; inspection decides refund, exchange or store credit.
  • Refund what was actually paid, keep money in integers, and record restocking as stock movements with a disposition.

Next: Product Search, Filters and Facets helps customers find the products in the first place.