Skip to content

Payments

Dmitri Chudinov edited this page Aug 28, 2026 · 1 revision

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.


1. The payment lifecycle

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
Loading
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.

2. The providers

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.

3. Payment methods, and T-Pay

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.

4. Webhooks are not signed — and what is done about it

YooKassa authenticates notifications by source IP only. There is no signature.

Two defences, and the second is the one that matters:

  1. YooKassaProvider.verify_webhook checks the source against the published ranges.
  2. PaymentsService.handle_webhook re-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.

5. Refunds

Two paths, and they are different things:

  • A manager's refund — issue_refund, moving the order to refunded. Reachable from paid through post_production.
  • An SLA credit — PaymentsService.refund_sla_credit returns 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.

6. Money is walled off

VIEW_FINANCIALS is deliberately separate from every production permission. The practical consequences:

  • The console dashboard needs view_all_orders, not view_production, because it carries revenue, spend and margin beside the machine states.
  • The post-production and packing boards show no money at all.
  • payment.settled carries an amount, and every holder of VIEW_PRODUCTION is 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.

7. Configuration

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.

8. Endpoints

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

9. Testing

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.

10. What remains unproven

  • 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.

Clone this wiki locally