Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ image: assets/banner.png
{
"ucp": { ... },
"id": "order_123456789",
"checkout_id": "chk_123456789",
"checkouts": [{ "id": "chk_123456789", "created_at": "..." }],
"permalink_url": ...,
"line_items": [ ... ],
"fulfillment": {
Expand Down Expand Up @@ -367,8 +367,8 @@ image: assets/banner.png
"type": "refund",
"occurred_at": "2026-01-12T14:30:00Z",
"status": "completed",
"line_items": [{ "id": "li_1", "quantity": 1 }],
"amount": 26550,
"line_items": [{ "id": "li_1", "quantity": -1 }],
"totals": [{ "type": "total", "amount": -26550 }],
"description": "Defective item"
}
],
Expand Down
31 changes: 20 additions & 11 deletions docs/specification/order.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ Orders have three main components:
**Line Items** — what was purchased at checkout:

* Includes current quantity counts (total, fulfilled)
* Can change post-order (e.g. order edits, exchanges)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With order edits now in the picture, can we add a guideline around what line_items SHOULD include post these changes, is it:

  1. A comprehensive list of all the items that once existed in the order, even if they were altered/removed via an edit?
    OR
  2. Only contain remaining items that are present after the latest edit?

My hunch is that 1) is more comprehensive from a data/audit perspective given there may have been adjustments that reference back to these altered products?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option 1 - comprehensive list. Line items should include all items that ever existed on the order, even if altered/removed via an edit. This is why quantity.original exists on line items - it preserves what was originally ordered at checkout, even when quantity.total changes to 0 after an edit. Adjustments can then always reference back to these items.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, makes sense, is it possible to actually add this on top of this bullet here?

i.e. Something along the lines of ; **MUST** include all line items that ever existed on the order regardless of edits or alterations?


**Fulfillment** — how items get delivered:

* **Expectations** — buyer-facing *promises* about when/how items will arrive
* **Events** (append-only log) — what actually happened (e.g. 👕 was shipped)

**Adjustments** (append-only log) — post-order events independent of fulfillment:
**Adjustments** — post-order events independent of fulfillment:

* Typically money movements (refunds, returns, credits, disputes, cancellations)
* Can be any post-order change
* Can happen before, during, or after fulfillment
* Businesses may append new entries or update existing ones in place
(e.g. a single `return` adjustment can transition from `pending` to `completed`)

## Data Model

Expand All @@ -50,7 +53,7 @@ Orders have three main components:
Line items reflect what was purchased at checkout and their current state:

* Item details (product, price, quantity ordered)
* Quantity counts and status are derived
* Quantity counts and fulfillment status

### Fulfillment

Expand Down Expand Up @@ -83,15 +86,17 @@ Expectations can be split, merged, or adjusted post-order. For example:

### Adjustments

**Adjustments** are an append-only log of events that exist independently of
**Adjustments** are post-order events that exist independently of
fulfillment:

* Type is an open string field - businesses can use any values that make sense
(typically money movements like `refund`, `return`, `credit`,
`price_adjustment`, `dispute`, `cancellation`)
* Can be any post-order change
* Optionally link to line items (or order-level for things like shipping refunds)
* Include amount when relevant
* Quantities and amounts are signed—negative for reductions (returns, refunds),
positive for additions (exchanges)
* Include totals breakdown when relevant
* Can happen at any time regardless of fulfillment status

## Schema
Expand All @@ -103,15 +108,15 @@ fulfillment:
### Order Line Item

Line items reflect what was purchased at checkout and their current state.
Status and quantity counts should reflect the event logs.

{{ schema_fields('order_line_item', 'order') }}

**Quantity Structure:**

```json
{
"total": 3, // Current total quantity
"original": 3, // Quantity from the original checkout
"total": 3, // Current total (may differ after edits/exchanges)
"fulfilled": 2 // What has been fulfilled
}
```
Expand Down Expand Up @@ -165,13 +170,15 @@ Examples: `refund`, `return`, `credit`, `price_adjustment`, `dispute`,
}
},
"id": "order_abc123",
"checkout_id": "checkout_xyz789",
"checkouts": [
{ "id": "checkout_xyz789", "created_at": "2025-01-05T09:00:00Z" }
],
"permalink_url": "https://business.com/orders/abc123",
"line_items": [
{
"id": "li_shoes",
"item": { "id": "prod_shoes", "title": "Running Shoes", "price": 3000 },
"quantity": { "total": 3, "fulfilled": 3 },
"quantity": { "original": 3, "total": 3, "fulfilled": 3 },
"totals": [
{"type": "subtotal", "amount": 9000},
{"type": "total", "amount": 9000}
Expand All @@ -181,7 +188,7 @@ Examples: `refund`, `return`, `credit`, `price_adjustment`, `dispute`,
{
"id": "li_shirts",
"item": { "id": "prod_shirts", "title": "Cotton T-Shirt", "price": 2000 },
"quantity": { "total": 2, "fulfilled": 0 },
"quantity": { "original": 2, "total": 2, "fulfilled": 0 },
"totals": [
{"type": "subtotal", "amount": 4000},
{"type": "total", "amount": 4000}
Expand Down Expand Up @@ -238,8 +245,10 @@ Examples: `refund`, `return`, `credit`, `price_adjustment`, `dispute`,
"type": "refund",
"occurred_at": "2025-01-10T14:30:00Z",
"status": "completed",
"line_items": [{ "id": "li_shoes", "quantity": 1 }],
"amount": 3000,
"line_items": [{ "id": "li_shoes", "quantity": -1 }],
"totals": [
{ "type": "total", "amount": -3000 }
],
"description": "Defective item"
}
],
Expand Down
2 changes: 1 addition & 1 deletion generate_ts_schema_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const fs = require('node:fs');
const path = require('node:path');
const { compile } = require('json-schema-to-typescript');

const SOURCE_ROOT = path.resolve(__dirname, 'spec');
const SOURCE_ROOT = path.resolve(__dirname, 'source');
const OUTPUT_FILE = path.resolve(__dirname, './generated/schema-types.ts');
const WRAPPER_NAME = 'SCHEMA_WRAPPER';

Expand Down
Loading
Loading