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.

JSON: an items component
{
  "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" }
  ]
}
What an items component holds
MemberWhat it isLimit
labelOptional caption: what the list is, in a few words.At most 200 characters
currencyOne ISO 4217 code for the whole component, such as CAD, JPY or BHD.One per component
rowsThe 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
totalsOptional 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 name is at most 30 characters and its detail at most 160. A longer one is refused, not trimmed: the 400 INVALID_SCHEMA error names it in field, such as /interaction/source/components/0/rows/1/name, with its length and the limit.
  • Amounts are whole numbers in the currency’s smallest unit. 1250 is $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.50 is refused; 1250 is $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.
Response: 400 INVALID_SCHEMA, a subtotal that does not add up
{
  "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 in selected, 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 carries quantities, one per row, and null for a row without one.
JSON: choose the items to return
{
  "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 }
  ]
}
Typed result: the shoes and the water bottle
{ "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 with 400 INVALID_SCHEMA at the component’s editable.
  • 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.
JSON: a purchase order with editable quantities (the interaction’s source and actions)
{
  "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" }
  ]
}
The response: 12 boxes, sent with Request changes
{ "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.

Common transactions and what to send
TransactionWhat to sendNote
Invoice to approveItems with totals; actions approve and reject—
Store receipt or order confirmationItems; a record (merchant, date, card’s last four digits); action continue—
Quote or estimate to acceptItems; a record (valid until); action approveThe date is text in the record.
Refund, full or partialItems with positive amounts under a “Refund” label, or select: "many" to choose the lines—
Expense claimItems; a field (category); actions approve and request_changeSess carries no files, such as photos of receipts: keep them in your own storage.
Purchase orderItems with editable: ["quantity"]; actions request_change and approveA changed quantity comes back as a change request.
Subscription change or upgradeItems (old plan, new plan, prorated credit); a record (next charge date)Recurring terms are text.
Request to payItems; action approveSess takes no payment: after the approval, your agent charges through your own payment provider.
Partial payment or balance dueTotals lines with roles paid (negative) and due—
Prices that include tax (EU, Japan)A tax line with included: trueShown, never added.
Several taxes (GST and PST, VAT by rate)One tax line each—
Discounts, coupons and creditsA negative row, or a discount line—
Shipping, fees and tipsshipping, fee or tip lines, or rows—
Tip prompt (10, 15 or 20%)A field with the choices, beside the itemsYour agent works out the tip for the next revision.
Split billItems; a field (each share)Your agent does the arithmetic.
Price in another currencyTwo items components, or a record row with the rateSess never converts; your agent states the rate.
Timesheet or payroll linesItems, with hours and rate in detail—
Donation with a chosen amountA number field, and items for any fixed part—
Booking with a depositItems with the total; the deposit due now in a recordOnce it is paid, a paid line and the amount due.
Dispute or chargeback evidenceA record and textNot a bill: no items.
A line with a wrong priceAction request_change, with a field for the disputed line—
More than 100 linesSeveral items components (per category, say), or a summaryThe limit holds: a bill that long is a document, not a question.
Statement of many transactionsItems, with each date in detailA 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.

Shell: write invoice.json
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
Shell: create it and print the Sess link
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:

Shell: 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}]}'
Response (selected fields)
{
  "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.

Shell
npm install @sess.si/sdk@0.5.0
JavaScript, invoice.mjs
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

Was this page useful?

Tell us more

Thanks for telling us.

You’ve sent a lot of answers in the last hour. Please try again later.

This couldn’t be sent right now. Please try again later.

That didn’t go through. Keep your note under 280 characters and send it again.

No account needed. We keep your answer, your note and this page’s address for a year, with a one-way code of your network address to stop abuse. Please leave out personal details.