Commerce
Sess takes no payment: it shows a person the amounts your agent states and returns what they decide, with a signed receipt.
On this page
The items component
For anything with prices, send an items component, not a table or text. The person sees your rows and totals in order, on one card. Nothing is collapsed.
{
"type": "items", "label": "Invoice 2041", "currency": "CAD",
"rows": [
{ "name": "Design retainer, October", "amount": 420000 },
{ "name": "Stock photography licence", "detail": "2 × $49.99", "amount": 9998 }
],
"totals": [
{ "label": "Subtotal", "amount": 429998, "role": "subtotal" },
{ "label": "GST 5%", "amount": 21500, "role": "tax" },
{ "label": "Total", "amount": 451498, "role": "total" }
]
}
| Member | What it is | Limit |
|---|---|---|
label | Optional caption: what the list is, in a few words. | At most 200 characters |
currency | One ISO 4217 code for the whole component, such as CAD, JPY or BHD. | One per component |
rows | The lines, in the order you send them. | 1 to 100 |
name (a row) | What one line is, shown as you write it. Put quantity and unit price in detail. | At most 30 characters |
detail (a row) | Optional second line: a quantity, a unit price or a reference. | At most 160 characters |
amount (a row) | The line’s amount, or null for a line with no amount (shown as “—”). | A whole number, at most 1,000,000,000,000,000 either side of zero |
totals | Optional totals lines, in the order you send them. | Up to 8 |
label (a totals line) | A word or two. | At most 40 characters |
role (a totals line) | One of subtotal, tax, discount, shipping, fee, tip, paid, due, adjustment, total, other. Only the total, or without one the amount due, looks different. | At most one subtotal, one total and one due |
included (a totals line) | Already in the prices, such as VAT: shown, never added. | Not on a subtotal, total, paid or due line |
A longer bill goes in several items components, one per category for example. Each limit refuses, never trims.
Three things to know first
- Names and details are short, and never cut. An item’s
nameis at most 30 characters and itsdetailat most 160. A longer one is refused, not trimmed: the400 INVALID_SCHEMAerror names it infield, such as/interaction/source/components/0/rows/1/name, with itslengthand thelimit. - Amounts are whole numbers in the currency’s smallest unit.
1250is $12.50 in USD, ¥1,250 in JPY and 1.250 BHD. Sess never rounds, converts or computes them. - Totals must add up. A subtotal must equal the sum of the rows, and a total the subtotal plus the other lines. If they don’t, nothing is created, and the error says what Sess expected, in the smallest unit.
Money rules
- Every amount is an integer in the currency’s smallest unit: cents for USD, yen for JPY (which has nothing smaller) and fils for BHD (a thousandth of a dinar).
12.50is refused;1250is $12.50. - One currency per component. To show a converted price, state the rate in a record, or send a second items component in the other currency. Sess never converts.
- Discounts, credits and payments are negative amounts. The page shows them with a minus sign, not a colour.
- Sess checks the sums you state, exactly, and never fills one in. The subtotal is the sum of the rows; a row with no amount adds nothing. The total is the subtotal plus every other line except paid, due and included ones. The amount due is the total plus the payments (paid lines); without a total, the subtotal plus the other lines and the payments.
- A total without a subtotal is not checked: it may cover lines you don’t list.
- Tax is yours to work out. Sess shows the tax lines you state, as you state them.
{
"error": {
"code": "INVALID_SCHEMA",
"message": "/interaction/source/components/0/totals/0/amount is 430000, but what it sums adds up to 429998, in the currency's smallest unit. Sess never changes your numbers: correct them and send again.",
"request_id": "req_00000000-0000-4000-8000-000000000000",
"field": "/interaction/source/components/0/totals/0/amount",
"expected": 429998,
"actual": 430000
}
}
Choosing lines and changing quantities
A person can answer a bill line by line. Give the component a name for the answer, then:
"select": "many"(checkboxes) or"select": "one"(a single choice) lets them choose rows. The result carries the chosen rows inselected, counted from 0."editable": ["quantity"]lets them change the quantity of each row that carries one, such as{ "value": 10, "unit": "boxes", "max": 50 }: a whole number from 0 to 1,000,000, with a unit of at most 16 characters. The result carriesquantities, one per row, andnullfor a row without one.
{
"type": "items", "label": "Order 4410", "currency": "USD",
"select": "many", "name": "returns",
"rows": [
{ "name": "Running shoes, size 42", "amount": 11900 },
{ "name": "Trail socks, 3 pairs", "detail": "3 × $8.00", "amount": 2400 },
{ "name": "Water bottle", "amount": 1500 }
]
}
{ "returns": { "selected": [0, 2] } }
Changed quantities: request_change
The amounts you state belong to the quantities you state. Sess never works out a new amount from a changed quantity, so a changed quantity goes back to your agent as a request for changes, never as an approval.
- A component with editable quantities needs an action with intent
request_change, such as “Request changes”. Without one, the create or publish is refused with400 INVALID_SCHEMAat the component’seditable. - A changed quantity is sent only with that action. If the person presses Approve instead, the page asks them to send it with Request changes, and keeps their numbers.
- Your agent reads the quantities, works out the new amounts and publishes the next revision to the same link. The person then approves the amounts for the quantities they asked for.
{
"source": { "kind": "sess_surface", "components": [{
"type": "items", "label": "Purchase order 908", "currency": "USD",
"editable": ["quantity"], "name": "order",
"rows": [
{ "name": "Printer paper, A4", "detail": "$4.99 each", "quantity": { "value": 10, "unit": "boxes", "max": 50 }, "amount": 4990 },
{ "name": "Delivery", "amount": 1500 }
]
}] },
"actions": [
{ "id": "change", "label": "Request changes", "intent": "request_change" },
{ "id": "approve", "label": "Approve", "intent": "approve" }
]
}
{ "revision": 1, "action_id": "change", "data": { "order": { "quantities": [12, null] } } }
Which transaction needs what
Every transaction is made of the same few parts: an items component, a record for facts such as a date, a field for an answer, and the actions.
| Transaction | What to send | Note |
|---|---|---|
| Invoice to approve | Items with totals; actions approve and reject | — |
| Store receipt or order confirmation | Items; a record (merchant, date, card’s last four digits); action continue | — |
| Quote or estimate to accept | Items; a record (valid until); action approve | The date is text in the record. |
| Refund, full or partial | Items with positive amounts under a “Refund” label, or select: "many" to choose the lines | — |
| Expense claim | Items; a field (category); actions approve and request_change | Sess carries no files, such as photos of receipts: keep them in your own storage. |
| Purchase order | Items with editable: ["quantity"]; actions request_change and approve | A changed quantity comes back as a change request. |
| Subscription change or upgrade | Items (old plan, new plan, prorated credit); a record (next charge date) | Recurring terms are text. |
| Request to pay | Items; action approve | Sess takes no payment: after the approval, your agent charges through your own payment provider. |
| Partial payment or balance due | Totals lines with roles paid (negative) and due | — |
| Prices that include tax (EU, Japan) | A tax line with included: true | Shown, never added. |
| Several taxes (GST and PST, VAT by rate) | One tax line each | — |
| Discounts, coupons and credits | A negative row, or a discount line | — |
| Shipping, fees and tips | shipping, fee or tip lines, or rows | — |
| Tip prompt (10, 15 or 20%) | A field with the choices, beside the items | Your agent works out the tip for the next revision. |
| Split bill | Items; a field (each share) | Your agent does the arithmetic. |
| Price in another currency | Two items components, or a record row with the rate | Sess never converts; your agent states the rate. |
| Timesheet or payroll lines | Items, with hours and rate in detail | — |
| Donation with a chosen amount | A number field, and items for any fixed part | — |
| Booking with a deposit | Items with the total; the deposit due now in a record | Once it is paid, a paid line and the amount due. |
| Dispute or chargeback evidence | A record and text | Not a bill: no items. |
| A line with a wrong price | Action request_change, with a field for the disputed line | — |
| More than 100 lines | Several items components (per category, say), or a summary | The limit holds: a bill that long is a document, not a question. |
| Statement of many transactions | Items, with each date in detail | A statement is for reading, not a decision. |
A full example
Ask a person to approve the invoice above, with no signup, using SESS_API and the trial from the Quickstart.
cat > invoice.json <<'JSON'
{
"interaction": {
"mode": "interactive",
"title": "Approve invoice 2041?",
"source": {
"kind": "sess_surface",
"components": [
{
"type": "items", "label": "Invoice 2041", "currency": "CAD",
"rows": [
{ "name": "Design retainer, October", "amount": 420000 },
{ "name": "Stock photography licence", "detail": "2 × $49.99", "amount": 9998 }
],
"totals": [
{ "label": "Subtotal", "amount": 429998, "role": "subtotal" },
{ "label": "GST 5%", "amount": 21500, "role": "tax" },
{ "label": "Total", "amount": 451498, "role": "total" }
]
}
]
},
"actions": [
{ "id": "decline", "label": "Decline", "intent": "reject" },
{ "id": "approve", "label": "Approve", "intent": "approve" }
]
}
}
JSON
curl -sS -X POST "$SESS_API/v1/trial/sessions" \
-H "Content-Type: application/json" \
--data-binary @invoice.json -o invoice-trial.json -w '%{http_code}\n'
export SESSION_ID="$(jq -r .id invoice-trial.json)"
export SESS_TRIAL_KEY="$(jq -r .management_credential invoice-trial.json)"
jq -r .human_url invoice-trial.json # send this link to the person
Expected result: 201. Open the link and choose Approve, then read the answer:
curl -sS "$SESS_API/v1/trial/sessions/$SESSION_ID" \
-H "Authorization: Bearer $SESS_TRIAL_KEY" \
| jq '{status, responses: [.responses[] | {revision, action_id, data}]}'
{
"status": "responded",
"responses": [
{ "revision": 1, "action_id": "approve", "data": {} }
]
}
The answer is the action, approve, bound to revision 1: the exact amounts the person saw. The signed receipt records it. What happens to the money next is up to your agent.
The same invoice with the Node.js SDK: invoice() builds the items component and its actions, and adds up the subtotal and total for you. It needs an API key.
npm install @sess.si/sdk@0.5.0
import { Sess, invoice } from '@sess.si/sdk';
const sess = new Sess({ apiKey: process.env.SESS_API_KEY });
const { data } = await sess.sessions.create({ interaction: invoice({
title: 'Approve invoice 2041?', label: 'Invoice 2041', currency: 'CAD', // amounts in cents
rows: [{ name: 'Design retainer, October', amount: 420000 },
{ name: 'Stock photography licence', detail: '2 × $49.99', amount: 9998 }],
lines: [{ label: 'GST 5%', amount: 21500, role: 'tax' }],
}) });
console.log('Open this link on your phone:', data.human_url);
const { response } = await sess.sessions.waitForResponse(data.id, { revision: data.revision });
console.log(response.action_id); // 'approve' or 'decline'
Over a limit, invoice() throws before anything is sent: a SessError with code INVALID_SCHEMA, outcome not_sent, and the value’s JSON pointer in field, with its length and the limit.
What Sess does not do
- Take payment, or hold card or bank details. After the person approves, your agent charges through your own payment provider.
- Work out prices, tax or totals, round amounts or convert currencies. It checks the sums you state.
- Make invoices. The signed receipt proves what the person saw and decided; it is not an invoice.
- Keep orders or stock. A bill is a revision of an ordinary Session.
- Show your logo or brand. There is no logo or branding upload: a Sess page looks the same whoever sends it.
- Appear inside your site. Sess pages send
frame-ancestors 'none', so no other site can frame them: send the person the Sess link.
Where next
- The items component in the API reference: every member, generated from the OpenAPI contract.
- Limits: the limits on every other part of a page.
- Verify receipts: check the signed receipt of an approval.