The driver flow (cpms/driver/)¶
Drop-in charging for a driver with no account, no app and no login (PRD §2, architecture §3): scan the static QR code, see the price, pay by card, plug in, watch, stop, get a receipt. Goal: QR → charging in under a minute on a phone.
Pages¶
| URL | What |
|---|---|
/ |
only on a host in an organization's driver_hosts: its published sites, each with its public outlets, their live status (the QR page's badge) and a link to /c/<public_id>. The ad hoc price incl. VAT once at the top. HTMX polls every 30 s. A 404 on any other host. |
/c/<public_id> |
the QR code (Outlet.public_id: declared in the site document, or generated on first apply; stable across applies). Station, charge point, outlet, live status, the ad hoc price incl. VAT and the amount reserved, shown before anything starts (AFIR). E-mail for the receipt, accept, optionally "Start later" at a time of day, continue to payment. |
| provider's page | Stripe Checkout (or /pay/fake/<ref> in development) reserves the amount. |
/s/<token> |
the live page. Waiting for the payment → "plug in the cable" (with the time left) → "checking that the cable is locked" → kW, kWh, cost so far incl. VAT, Stop (or, scheduled: "charging starts at 23:00", start now, cancel) → finishing → done, with the receipt. A failed start is said here at once. HTMX polls every 3 s. |
/s/<token>/receipt |
the receipt (seller = the organization). Also e-mailed. |
/login/, /login/code/, /logout/ |
only on a host in an organization's driver_hosts: log in with a one-time code by e-mail, log out ("Driver accounts" below). |
/login/link/<token> |
the account link of a mail about a charge (the mail sent when it starts, or its receipt): makes the receipt address an account on that host and the charge hers, once. |
/s/<token>/account |
POST, from the live page of a charge started without the "create account" box: mail the account link now. |
/me/, /me/receipts/ |
her charges and her receipts at this organization, logged in. |
/me/subscription/ |
the organization's subscription plan and Sign up, or her subscription: state, next invoice, the charges not yet invoiced, her invoices, and a link to the payment provider's own pages (cpms/subscriptions/README.md). |
A logged-in driver whose subscription is in effect and applies at the
outlet's site gets another /c/<public_id>: her plan's price, nothing
reserved, one button, and no provider page. Her drop-in row begins at
authorized with subscription set and no payment; the worker starts it
like any other, and when it has ended its session goes on her next invoice
instead of being captured (cpms/subscriptions/README.md). Everybody else,
and she herself when her subscription has ended, does not apply at the
site, or has an invoice unpaid for longer than the plan's unpaid_days,
gets the flow below unchanged.
<token> is a capability: 24 random bytes, the only key to that one
charge. A reloaded page, a locked phone or a second device finds the
charge again with the link, and the receipt mail links back to it. The
outlet page also remembers the browser's own active charge for a day (a
signed cookie per outlet) and offers "show my charge".
Swedish first (LANGUAGE_CODE = "sv"), English available from the footer.
Strings are English in the source; the catalog is
cpms/locale/sv/LC_MESSAGES/django.po, maintained with
uv run python scripts/messages.py (no GNU gettext needed; --check
lists anything untranslated).
What happens, step by step¶
Views are thin; every change is an action in services.py, journaled in
the actions journal (never with the e-mail address, the tag or the token).
Everything after the payment page is done by the worker
(uv run manage.py worker), so it happens whether or not the driver's
phone is still on the page.
- Begin (
driver_begin). The outlet must be public, priced (the price list's ad hoc channel, flat tariffs only for now) and free: cpms's own read models first, then a liveGET /chargers/{id}to ocpp-rest (responsive? this connector free?) right before any money is reserved. ADropInrow is created with the price shown, and the provider's checkout is opened for the plan'spreauth_amount. - Payment confirmed (
driver_confirm_payment). Triggered by the provider's webhook (stored in the inbox, processed by the worker), by the driver's return (the worker asks the provider a couple of seconds later), or by a once-a-minute check. Each asks the provider directly; the driver's browser is never trusted. The authorization becomes a ledgerPayment. - Start (
driver_start). A one-timeid_tag(DRP+ 17 random characters, 20 in total: the OCPP limit) is pushed withPUT /authorizations/{id_tag}scoped to this one box and expiring after the plug-in window, thenPOST …/connectors/{n}/start. The Aura then waits for the cable. - Track (worker, every second). The session is found as
consumer.Sessionwith this box and thisid_tag(a session the consumer attributes to another organization is never taken). If the gateway missed thesession_startand the session was learned without a tag, the one learned session on this outlet since our start is taken, and only if there is exactly one.- No session within
DRIVER_PLUG_TIMEOUT_S(default 180 s; it must be longer than ocpp-rest'sREMOTE_START_GRACE_S, 120 s): the tag is revoked first, then the reservation is released. - The cost reaches the reservation: the worker sends one RemoteStop.
- The session ends, by our Stop or because the driver unplugged: the
drop-in is
ended. - A session that appears after we gave up (the box started anyway) is stopped: the unpaid-session guard.
- No session within
- Settle (
settle_payment, incpms/ledger/). AfterDRIVER_SETTLE_DELAY_S(30 s) from a definitivesession_end, orDRIVER_SETTLE_DELAY_INFERRED_S(300 s) from an inferred one (a definitive end with the box's own meter value may follow), the session'samount_incl_vatis captured, capped at the authorization; 0 kWh (or anything below the provider's minimum) cancels instead. If the consumer could not price the session, the price shown to the driver is used. - Receipt mail and tag revocation. At least once; a crash between sending and recording resends the same receipt (same number).
Scheduled start (PRD §6, slice 3a)¶
"Start later" on the outlet page takes a time of day in the organization's
time zone, the next time the clock shows it; services.begin takes any
start_at (the driver API passes it on). The session starts at once,
exactly as without it: the RemoteStart carries a limit of 0 A, which
ocpp-rest puts into the first TxProfile, so the cable locks while the driver
is at the car and no energy flows. The balancer is the scheduler
(architecture §9): it reads start_at from GET /api/v1/balancer/sessions,
keeps the session at 0 A until then and gives it its share from the next
cycle after (cpms/balancer/README.md). The drop-in is scheduled from the
session's start until start_at, then charging.
- Start now sets
start_atto now; cancel stops the session (0 Wh, the reservation is released, no failed-start notice: she cancelled). - Only where the fuse group is balanced (
balancing: true): without a balancer nothing would hold the car (scheduling_not_available). - At most the provider's authorization window (Stripe: 7 days for an online
card payment) less
DRIVER_SCHEDULE_MARGIN_S(2 days) ahead (start_too_late): an authorization that expires before the capture loses the money (architecture §3.1). The page offers only the next 24 h. - If no car is plugged in within the plug-in window, or the driver starts now before plugging in, the 0 A is taken off the connector so the next car does not start paused.
A failed start is never silent (PRD §6)¶
The consumer judges each session (Session.failed_start,
cpms/consumer/README.md): it ended within a minute with 0 Wh, ended
without energy after it was allowed current, delivered nothing for five
minutes after it was allowed current (for a scheduled start: after
start_at), or its outlet went Faulted under it. For every drop-in,
scheduled or not:
- the live page says so at once (it reads the session itself, every 3 s): "The charge did not start … unplug the cable, push it firmly in, and start again", or for a running session with no energy, what to check, with Stop;
- the worker records it once (
driver_failed_start, journaled) and e-mails the receipt address (driver_send_failed_start_mail, at least once, like the receipt); - the session settles as usual: 0 Wh cancels the reservation, no receipt.
A charge a fault stops after it has delivered (Jonas, 2026-11-06; the
consumer's Session.interrupted_at) gets the same treatment, but is not a
failed start: "The charge has stopped" on the page at once, with the
re-plug advice and Stop, and one e-mail (driver_interrupted,
driver_send_interrupted_mail). Nothing is stopped automatically. If the
outlet leaves Faulted and the charge resumes, the page shows charging
again; a second fault shows on the page but sends no second e-mail. The
receipt follows as usual for the energy delivered.
Not reported to the driver: a session she stopped herself. Energy delivered
later clears the session's state; the drop-in keeps the record that she was
told. Right after the box starts a session the page shows "checking that the
cable is locked" for DRIVER_LOCK_CHECK_S (15 s, architecture §3.1). Both
numbers are provisional until they are measured on real hardware.
States: paying → authorized → starting → charging → ended (or starting →
scheduled → charging, or scheduled → ended when cancelled), or
abandoned (left the payment page, or DRIVER_CHECKOUT_TIMEOUT_S passed:
the checkout is expired at the provider so it cannot be paid later),
failed (declined, or the start failed), timed_out (no car, or the
driver pressed Cancel). Every non-ended end releases any reservation; a
payment that arrives after the drop-in gave up is recorded and released.
A second driver cannot pay for an outlet that is starting or charging; a driver on the payment page holds the outlet for three minutes.
Driver accounts (architecture §3.1, §6.5, §11)¶
A first, narrow build. No account is ever needed to charge; a driver who wants one logs in on the organization's own host and sees her charges and receipts there. Logging in is django-allauth's code login, the mechanism the portal uses, on the same user table.
Person and customer. The person is a Django user, one per e-mail
address on the instance, holding only what logs her in. The customer
(cpms/customers/) is that person at one organization: a row per
organization with an optional name and reference. One person at two
organizations is two customers, and neither sees the other's. The customer
is created the first time she proves her address at that organization, by
a code or by an account link, and that is journaled (driver_register,
with the customer's id, never the person's or the address).
Logging in. /login/ on a driver host ("log in or create an
account": the page says that an address with no account gets one) takes
any address and e-mails a code, in the organization's name and the page's language, from
DEFAULT_FROM_EMAIL with the organization's name and its address as
Reply-To. An address the instance has not seen becomes a person when the
code is asked for, as allauth's own sign-up creates the user before the
address is confirmed; one that never enters a code is deleted after a day
(the worker's forget_unproved_persons). The answer is the same whether
the address is known, new or switched off. allauth limits code requests
per address (3 a minute) and per client (20 a minute) and wrong codes (3).
A login counts at one organization. The session records the
organization of the host it was made on, and a request on any other host,
or in the portal, is not logged in: cpms/identity.py checks it on every
request, whatever cookie comes with it. Session cookies are host-only as
well. A portal member may be a driver with the same user; a driver login
opens nothing in the portal, which sends a code only to a member.
It lasts DRIVER_LOGIN_AGE_S, 12 months since it was last used
(architecture §3.1): the session's expiry is counted again from the first
request of each day. /logout/ ends it on that browser. Listing and
revoking logins per device is not built.
Create account. On the outlet page of the organization's own host, a
driver who is not logged in sees the box "create account", ticked. Left
ticked, one mail goes to the receipt address as soon as the charge is on
its way (the box has been asked to start): it says that she has started a
charge and has one button, and nothing about energy or money, so that it
is not taken for a receipt. The button is a link, /login/link/<token> on
that host, which makes the address an account without a code: the mail
reached the address. Unticked, the drop-in is what it always was, with no
account and no extra mail.
- Using the link creates her customer, logs her in and makes that charge hers, as if she had started it logged in. She lands on the charge's own page while it runs, otherwise on her pages.
- A link works once and for
DRIVER_RECEIPT_LOGIN_AGE_S, 24 hours (mails are forwarded, receipts to an employer for one). Only its SHA-256 is stored (AccountLink). - Opening the link logs nobody in: it shows a page that names the address with one button, and pressing the button spends the link. Mail scanners and link previews open links, and would otherwise use it up.
- A link that is used, too old, or not this organization's leads to
/login/with a line saying so, and she asks for a code. - The receipt mail carries no link once the charge is somebody's. If the account was asked for and the first link was never used, the receipt carries a fresh one, good for 24 hours from the receipt; the first one keeps working for its own 24 hours. Using either spends every link of that charge, so a receipt forwarded later opens nothing. The receipt asks her to remove the link if she forwards it.
- To an address that is a customer already, the mail says "log in to follow your charge" instead of "create your account". Only the mail and the page behind its link say so; no page tells whoever types an address whether it has an account.
- On the charge's own page, while it is nobody's and nobody is logged in: if the box was ticked, a line says the link was mailed and to which address (a mistyped address is seen while she is still at the car); if it was not, "create account" there mails the link now.
Whose a running charge is. A charge is a customer's (DropIn.customer)
when she started it logged in; when the account link of its own mail was
used; or when it was started in this browser before she logged in and its
receipt address is the address she then proved by code, at the same
organization (accounts.attach, journaled as driver_attach). "This
browser" is the signed cookie per outlet that the outlet page already
keeps to show "my charge" (a day), so nothing more is stored about a
driver who has no account. A charge that only carries her address is not
hers while it runs: anyone can type any receipt address, and a running
charge's page has the Stop button. It becomes hers by address once it has
ended, when the receipt has gone to that address anyway.
What remains: the mail at start goes to whatever address was typed. A mistyped address that somebody else owns gets a button that makes that person an account with this charge in it: she can follow it and stop it, and it stays in her list. The notices of a failed or interrupted start already mail the charge's own link to the typed address, so the address's owner could reach a running charge before; what is new is that every ticked start sends a mail, where the notices are rare. The page of the charge names the address the link went to.
My pages. Every tab starts with her running charges, each with a
button to its own page: this is the way back to a charge, for a subscriber
above all, whose start has no payment page to return from and no receipt
mail. /me/ then lists her charges at this organization, newest first:
where and when, and energy and the amount incl. VAT once there is a
receipt; /me/receipts/ lists her receipts. Each links to the charge's
own page (/s/<token>) or receipt. The newest 100 are shown; there is no
paging yet.
The way around. On the organization's own host the name at the top of every page leads to the station list, and the link beside it to "log in" or, logged in, to her pages. "Log in" pressed on an outlet or on a charge comes back to that page; any other login leads to her running charge if she has exactly one, else to her pages. Her pages have "start a new charge" (the station list) and "log out", which lands on the station list. The outlet page shows "my charge" for the browser that started it and, to a logged-in driver, for her own charge there from any device.
Starting while logged in. The outlet page shows her address instead
of asking for one, the receipt goes there, and the charge is linked to her
customer (DropIn.customer). The price is the drop-in plan's: pricing
through the customer comes with agreements and subscriptions. On another
organization's outlet she is a drop-in driver like anyone.
How allauth is fitted in (cpms/identity.py; allauth is used as it
ships, nothing in it is patched):
AccountAdapter, allauth's hook for this:send_mail,get_from_emailandformat_email_subject(the organization's code mail),get_login_redirect_urlandget_logout_redirect_url(to her running charge or/me/, and to/),get_client_ip(the client's address behind the local proxy, so allauth's limit per client is per client),add_message(allauth's "you are logged in as …" is not shown on a driver host),is_open_for_signup(false: allauth's own sign-up pages are never used).LoginCodeForm(ACCOUNT_FORMS["request_login_code"]): who gets a code. The portal: members only. A driver host: anyone.Audience(middleware) and a receiver on Django'suser_logged_in: bind a login to where it was made, make it slide, and make the charges this browser started hers.- A URLconf of its own for driver hosts (
host_urls.py). allauth finds its pages by fixed URL names (account_login, …), and one name is one address in a Django URLconf. Django lets a request carry its own URLconf (request.urlconf); on a driver host the names lead to/login/…with the organization's templates, elsewhere to the portal's/portal/login/…. django-hosts and django-tenants are built on the same feature. Not thought through: a page that is rendered on a driver host and links to a portal page by name would fail (none does, and the portal and admin are not served there); and anything that builds a URL outside a request (the worker's mails) uses the instance's URLconf, so it must not name the login pages (the account link is underdriver:, which both have).
Not built (hooks left): the driver API's login and driver token (the
served pages use the session cookie); passwords, Google or another
provider, passkeys (allauth carries them; they are settings and
templates); RFID tags, agreements and subscriptions, and so the account
plan; changing the e-mail address; a name or reference set by the driver
or the organization (the fields exist, nothing writes them); the register
actions by which an organization adds a customer; communication
preferences; listing and revoking logins per device; and the erasure job
(Customer.user is nullable for it; it must also end that customer's
logins).
The driver API (/api/driver/v1/, architecture §3.1)¶
The contract for an organization's own driver front end (api.py): a
django-ninja API of its own, with its own OpenAPI document
(/api/driver/v1/openapi.json) and docs page (/api/driver/v1/docs),
separate from the operator API. v1 changes only additively; state and
payment.kind say they may grow. The served pages stay the reference
client: both call the same actions, and a test runs one drop-in through
each and compares the journal and the ledger.
| Endpoint | Credential | What |
|---|---|---|
GET /outlets/{public_id} |
none, any origin | the outlet by its QR id: site, charge point, live status, can_start, the ad hoc price incl. and excl. VAT (exact names the side the tariff states), the amount reserved, and scheduling (available here, how far ahead) |
GET /organizations/{key}/sites |
none, any origin | the published sites and their public outlets, as the home page |
POST /outlets/{public_id}/start |
none | {email, accept, language?, return_url?, start_at?} → 201 {token, session}; the session is payment_required with payment.checkout_url. accept must be true: the driver accepted the price and the reservation shown, as the served page's checkbox asks (422 price_not_accepted otherwise) |
GET /sessions/{id} |
session token | the session, live: state (payment_required, starting, scheduled, charging, finishing, ended, failed_start, cancelled, failed), held, checking_cable, failed_start, interrupted, energy, power, cost, payment |
POST /sessions/{id}/cancel-payment |
session token | the driver left the payment page |
POST /sessions/{id}/cancel |
session token | give up before the car is in; a scheduled charge: stop it |
POST /sessions/{id}/start-now |
session token | a scheduled charge: do not wait |
POST /sessions/{id}/stop |
session token | stop charging |
GET /sessions/{id}/receipt |
session token | the receipt, once captured (404 before) |
- The session token is the capability
/s/<token>is: 24 random bytes, returned once by start, sent asAuthorization: Bearer.{id}is the session's public id (DropIn.ref); a token reaches its own session only, and another id is a 404. - Refusals are errors with the codes the served pages translate:
occupied,starting,offline,out_of_order,not_public,no_price,payments_not_set_up,payment_provider_unavailable,scheduling_not_available,start_too_late,return_url_not_allowed,invalid_email,invalid_language,too_many_requests,price_not_accepted(422; the served page shows the unticked box's message for it). - Allowed origins (
cors.py). The public endpoints answer any origin. Start and the session endpoints answer a browser only from the organization'sdriver_origins(organization document; https, orhttp://localhostfor development) and the hosts the instance serves the driver flow on itself (itsdriver_hosts,PUBLIC_BASE_URL, the namedALLOWED_HOSTS). The same list bindsreturn_urlfor every caller: payment never returns to a page that is not the operator's. Payment returns toreturn_urlwithsession=<id>&payment=doneorpayment=cancelledadded; without it, to the served live page. - Rate limit. Start is limited per client address (an IPv6 /64),
START_LIMIT(10 per 10 minutes), in front of the action, shared with the served page (cpms.core.limits: per process, enough to blunt abuse). - Not yet: the driver token and the login and account endpoints (PRD §7, slice 5a): the served account pages are built ("Driver accounts" above), the API's are not. The subscription endpoints come with the subscriber step.
Theme¶
No project or customer branding is built in (architecture §14). The
organization's name comes from the organization document; an optional
theme block there sets an accent colour and a logo:
organization:
key: demo
name: Demo Laddning AB
theme: {primary: "#0b7a3e", logo_url: "https://example.com/logo.svg"}
Both are validated by the manifest schema (hex colour, https URL), so nothing reaches the page's CSS unchecked. The return URL from the payment page uses the host the driver came in on, so an organization's own domain (charge.example.se pointed at the instance) stays its own through payment.
Design system¶
Server-rendered Django templates + HTMX + Tailwind with daisyUI (PRD §5).
- Partials. A page and its HTMX fragment are the same template: Django
6's template partials (
{% partialdef panel inline %}andrender(…, "driver/live.html#panel")). Small components are includes intemplates/driver/components/(price, stat, receipt, outlet header). - Tailwind without Node at runtime.
scripts/build-css.shdownloads Tailwind's standalone CLI (a single binary with Tailwind built in, published by Tailwind Labs for exactly this) and daisyUI's two plugin files at pinned versions with checked SHA-256s into.tools/(gitignored), and buildscpms/assets/app.cssintocpms/static/cpms/app.css, which is committed. The server never builds CSS; it serves the committed file aftercollectstatic. Rebuild and commit after changing classes in a template. The same approach is the default in Phoenix (thetailwindhex package), in Rails (tailwindcss-rails) and in Django'sdjango-tailwind-cli; daisyUI documents its use with the standalone CLI. Not thought through yet: nothing checks in CI that the committed CSS is up to date with the templates. - htmx 2.0.4 is vendored as
cpms/static/vendor/htmx-2.0.4.min.js. - Mobile first: one column,
max-w-md, tap targets of at least 48 px.
Not built yet¶
Spot-priced drop-in (needs the current spot price on the page), an EVSE id
on the page and receipt (architecture §14, comes with the OCPI slice), the
driver token and the account endpoints of the driver API (slice 5a; the
served account pages are built, above), per-organization sender domains for
mail (today: DEFAULT_FROM_EMAIL with the organization's name, and its
e-mail as Reply-To).