Repository navigation
Payments
The rule that governs this area is the same one that governs the printer drivers: a payment gateway is not integrated until a real payment has been run against it.
Three providers exist — manual, mock and yookassa — and only the first two have
ever moved money in a run. See Project Status.
stateDiagram-v2
direction LR
[*] --> created
created --> pending
created --> cancelled
created --> failed
pending --> succeeded
pending --> cancelled
pending --> failed
succeeded --> partially_refunded
succeeded --> refunded
partially_refunded --> partially_refunded
partially_refunded --> refunded
| Status | Means |
|---|---|
created |
Created locally; the customer has not been sent to the provider yet |
pending |
Awaiting the customer at the provider, or awaiting an operator for manual
|
succeeded |
Money moved |
partially_refunded |
Some returned — and it can happen again |
refunded |
Fully returned |
cancelled / failed
|
Terminal, no money moved |
Two derived properties: is_settled (succeeded or partially_refunded — money
actually moved and has not been fully returned) and is_final.
| Provider | What it is |
|---|---|
mock |
In-process, for development and the virtual farm. Refuses to load in production — ADR-0007 applied to money |
manual |
An operator marks the payment settled by hand. POST /payments/{id}/settle-manually
|
yookassa |
The real Russian gateway. Written from the documented API shape; the unit tests prove the request it builds matches that shape |
The API resolves a gateway per request through api.providers.build_provider, so the
choice is a deployment setting rather than something the storefront can influence.
YooKassa accepts several methods. T-Pay (T-Bank's express checkout) is one of them — in
the API it is the method code tinkoff_bank, with redirect confirmation.
| Property | Value |
|---|---|
| Method type | tinkoff_bank |
| Confirmation | redirect (confirmation_url) |
| Payment term | 1 hour |
| Holding / capture | up to 7 days, full or partial |
| Refunds | full and partial |
| Limits | 1 ₽ … 700 000 ₽ (raisable) |
How the choice travels:
StartPayment.payment_method → PaymentsService.start
→ PaymentRequest.payment_method_type
→ body["payment_method_data"] = {"type": ...}
An empty payment_method means "whatever the gateway offers" — the customer picks on
the payment page. An unknown method code is passed through and refused by the
gateway, never re-mapped to a different one: a fallback would charge the customer a way
they did not choose.
YooKassa authenticates notifications by source IP only. There is no signature.
Two defences, and the second is the one that matters:
-
YooKassaProvider.verify_webhookchecks the source against the published ranges. -
PaymentsService.handle_webhookre-reads the payment from the gateway before believing it.
A webhook body that says "succeeded" is worth nothing on its own; the fetch is what settles the order.
Never loosen the IP check to make a test pass. An unauthenticated webhook that marks orders paid is free prints.
payment_notifications records what arrived, so a disputed settlement has a trail.
Two paths, and they are different things:
-
A manager's refund —
issue_refund, moving the order torefunded. Reachable frompaidthroughpost_production. -
An SLA credit —
PaymentsService.refund_sla_creditreturns exactly the outstanding credit through the provider. Capped and predictable rather than an ad-hoc discount somebody applies by hand. See SLA and Variance.
refunds cascades from payments, which itself is a RESTRICT foreign key from the
order — a paid order cannot be deleted out from under its payment record.
VIEW_FINANCIALS is deliberately separate from every production permission. The
practical consequences:
- The console dashboard needs
view_all_orders, notview_production, because it carries revenue, spend and margin beside the machine states. - The post-production and packing boards show no money at all.
-
payment.settledcarries an amount, and every holder ofVIEW_PRODUCTIONis entitled to the event socket — so the amount is stripped on the relay (core.relay.REDACTED_FIELDS). A screen that should show money asks the API, which checks the permission.
| Variable | Default | Meaning |
|---|---|---|
PRINTORIAN_PAYMENT_PROVIDER |
mock |
manual / mock / yookassa
|
PRINTORIAN_YOOKASSA_SHOP_ID |
"" |
merchant shop id |
PRINTORIAN_YOOKASSA_SECRET_KEY |
"" |
secret key, a SecretStr
|
PRINTORIAN_PAYMENT_RETURN_URL |
dev storefront | where the gateway returns the customer |
Console → Settings → Finance also carries VAT percent, whether prices include tax, the prepayment percent, and the same YooKassa credentials as write-only encrypted secrets.
| Endpoint | |
|---|---|
POST /payments |
Start a payment |
POST /payments/webhook/{provider} |
Provider notification |
GET /payments/order/{order_id} |
Payments for an order |
GET /payments/{id} |
One payment |
GET /payments/providers/available |
What this deployment offers |
POST /payments/{id}/settle-manually |
The manual provider's settlement |
YooKassa's own testing page is explicit: card and YooMoney-wallet payments can be tested in a demo store; every other method — T-Pay included — can only be tested in a real, live store. That is a gateway constraint, and it splits the proof in two:
- Demo store proves the whole integration end to end — create, redirect, webhook, settle, refund — with a test card. This is the cheaper first proof and the one to do first.
- Live store is the only place T-Pay itself can be completed, because completing it means scanning a QR in a real T-Bank app.
Step-by-step procedures for both are in
docs/RUNBOOK-PAYMENTS.md.
- T-Pay has not been completed against a live T-Bank account.
- The demo-store card flow has not been run against a live merchant account either.
- 54-ФЗ receipt handling is built and unit-tested but not confirmed against the fiscal operator.
Printorian wiki · the code is the source of truth · open work lives in issues · current state in HANDOFF.md
Concepts
Workflow
Lifecycles
- Order Lifecycle
- Job Lifecycle
- Scheduling and Dispatch
- Materials and Inventory
- Fleet and Drivers
- Post-Production and Packing
Money
Running it
- Installation
- Configuration
- Deployment
- Operations
- Backup and Restore
- Database Maintenance
- Troubleshooting
Building it