# Section payment modes

## Participant settings

`user.is_sekcja = 1` enables period payments. The additive migration
`20261028140000_add_section_per_class_payment.sql` introduces
`user.can_pay_section_per_class`, default 0, for individually priced section
classes. The flags are mutually exclusive. Both off disallows self-service
section payments. The management account editor switches off the other flag;
model validation also rejects conflicting values and crafted requests.
The settings belong to the participant, including when a parent pays.
Existing flags and historical payments are not automatically changed by migration.

`User::canPayForEvent()` governs single group payments. Only participants with
per-class permission can pay section bookings individually, by account-balance
checkout or manual payment. This also covers traditional-transfer instructions
and assigning an unlinked payment. Ordinary group classes remain unaffected.
The separate administrative zero settlement remains available. Period purchases
require period permission at order creation, checkout and payment confirmation.

## Full debt versus payable balance

`User::calculateBalance()` retains all existing debts and persists the full
account balance, including section classes and children's debts. Debt reports,
oldest unpaid dates and enrollment limits retain that full balance.
`User::getPayableBalance()` independently selects payable items from that result
and returns their sum. A section item qualifies only for an opted-in participant.
Views show the full debt and, where different, the amount payable online; section
items requiring period payment do not offer a single-payment action.

Balance checkout freezes only the eligible items and their amounts in
`payment.balance_items_json`. Preview, receipt capture and provider registration
use that same subset. An empty subset cannot start a payment. Confirmation checks
permissions again, with participant locks, before assigning any items. A conflict
marks the received payment for refund/explanation through the existing unlinked
refund flow; it must not partially settle the snapshot. Confirmed historical
payments are not reopened or retroactively filtered.

## Pass eligibility and history

Only `sek` passes can settle `event.is_sekcja = 1` classes, irrespective of the
participant's payment mode. FLEX, OPEN, CLASSIC and technical passes are excluded.
Classic 4 and both Classic 4+4 groups exclude sections in selection, configuration
models, order creation, checkout and confirmation. Participants can still buy
ordinary passes for ordinary classes.

Section+OPEN purchases continue to create the existing pair: `sek` covers section
classes and OPEN covers ordinary classes. Historical standalone OPEN section
assignments remain visible. Existing `passHistory()` SQL must retain its shared-
payment exclusion: production inspection found 120 standalone OPEN section uses
for 13 participants in 2021–2025. This exception never enables new settlements.

## Section report

The report includes per-class participants with **Płatność jednorazowa**. Missing
periods are marked as per-class rather than unpaid/overdue, excluded from period
arrears and missing-plan totals and filters. Paid periods remain visible,
including their actual payment amounts. The same classifications apply to XLSX.
Individual unpaid classes remain in the ordinary account debt and debt reports.

## Deployment and verification

Apply the additive migration before serving the new PHP code (the deployment
runner backs up the database before pending migrations). No configuration,
server files or existing data flags are changed by the migration. Deploy and
verify test-next before promoting the same SHA to production.

One-off corrections of existing payments are performed manually, outside the
repository and migration runner, with a private backup, row locks, a transaction
and an administrator audit. They do not change fiscal or reward snapshots.

Run on an isolated database prepared by `scripts/prepare-rollpoints-tests.php`:
`tests/section_payment_policy_test.php`, `tests/shared_payment_checkout_test.php`,
`tests/payment_confirmation_refund_test.php`, `tests/group_signup_payment_test.php`
and `tests/section_account_test.php`. Database-free regressions include
`tests/pass_used_up_notification_test.php`, `tests/section_payments_report_test.php`
and `tests/account_balance_interface_test.php`.
