# Finance implementation and verification

Implemented `shared/admin-finance.js`, `admin-atelier/finance.js`, financial regression tests, and reviewed the finance declarations in `shared/admin-api.d.ts`. All state uses the existing `abnabot.world.v1` transaction boundary. Bank approvals modify the canonical ledger; there is no second balance or transaction store.

## Coverage

- Bankcard CRUD, normalized 16-digit numbers, all brief bank prefixes, default wallet, per-wallet visibility, period/capacity instruments, soft deletion, Tehran period boundaries and server-time countdown.
- SafeMode validation, cap conflicts, immediate lower-bound restart, inactive/manual restoration, all three rotation strategies, no repeated adjacent random amount, missed-run single rotation, reason/audit diffs, actual eligible-card minima and no-card warning.
- Payment methods and wallet-specific nullable overrides, lifetime inheritance, SafeMode cap guard on method/link writes, independent cashback links and disabled link creation.
- Cashback bounds and missing-value validation, toggling and soft deletion.
- Tronado validation and masked non-echoing secret replacement.
- Every explicitly named NOWPayments field: grouped batch changes, immediate booleans, masked secret replacement, callback projections and unknown-key ignoring.
- Native nested ALL/ANY rule builder; all condition types/operators/methods; readable summary; real-user, every-leaf tester; base-method warning and serious no-unconditional-method confirmation; save/toggle/hard deletion.
- Fresh setup shares the finance synchronous helpers with operations.

The brief says “30 keys” but enumerates **29 distinct NOWPayments names**. Per the implementation decision, all 29 named fields are present; no invented 30th setting was added. Likewise all nine named SafeMode explanation topics are present.

## Automated API validation

`node --test shared/admin-finance.test.mjs`: **13 passed, zero failed**.

Includes canonical balance/ledger effects, duplicate prevention, period rollover including late processing of prior-period approvals, rollback on invalid SafeMode/cap settings, exact deterministic sequences, history pagination, nullable overrides, cashback link isolation, null/blank numeric rejection, secret secrecy, nested actual-user evaluation, group lifecycle, and shared fresh setup.

## Browser validation

Session `admin-finance`, localhost port8765, Persian RTL phone layouts at360×800 and390×844. Final screenshots followed an explicit full-page reload to load current root modules and styling.

- Actual create/edit/toggle/delete card forms and Persian invalid-number feedback.
- SafeMode required reason, bounds/grid and cap rejection; saved changes and audits.
- Live one-second countdown, actual twenty-second server refresh, old paginated entries retained after a new rotation; disabling removes schedule, enabling restarts at lower bound.
- Method cap rejection; saved and cleared wallet overrides; cashback attachment, creation and confirmed deletion.
- Tronado invalid address rejection, valid replacement and no secret echo.
- NOWPayments secret replacement, boolean toggling, URL batch update and derived callbacks.
- Mixed nested ALL/ANY group created via controls, evaluated against a real user, all three leaf results displayed, serious warning confirmed before save, then toggled and deleted.
- No horizontal overflow on the nested editor or SafeMode at phone widths. Both light and dark surfaces visually inspected.

Two earlier script assertions ran before asynchronous route refresh completed; settled UI and explicit wait-based continuation passed. No application defect was associated with those timing failures.

Final visual artifacts: `admin-finance-safe-dark360.png`, `admin-finance-safe-light390.png`, `admin-finance-card-final.png`, `admin-finance-builder-header.png`, `admin-finance-builder-nested.png`, `admin-finance-tester-final.png`, `admin-finance-nowpayments-final.png`, `admin-finance-payments-final.png`.

## Route and API inventory

Routes: `payments`, `bankcards`, `bankcard`, `safe-mode`, `payment-method`, `method-wallet`, `cashback`, `payment-settings`, `nowpayments`, `payment-conditions`, `payment-condition`.

Public functions: `listCards`, `createCard`, `updateCard`, `toggleCard`, `toggleCardWallet`, `deleteCard`; `getSafeMode`, `saveSafeMode`, `getSafeModeHistory`; `listPaymentMethods`, `updatePaymentMethod`, `setMethodWallet`, `getMethodWalletCashback`, `toggleMethodWalletCashback`; `listCashback`, `createCashback`, `updateCashback`, `toggleCashback`, `deleteCashback`; `getPaymentSettings`, `setTronado`; `getNowpayments`, `updateNowpayments`; `listPaymentConditions`, `getPaymentConditionsMeta`, `getPaymentCondition`, `createPaymentCondition`, `updatePaymentCondition`, `togglePaymentCondition`, `deletePaymentCondition`, `testPaymentCondition`.

Setup-only synchronous helpers are imported directly by operations: `financeMethods`, `financeSetupPayments`, `applySetupCard`, `applyTronado`, `applyPaymentMethod`. Public presentation constants: `BANK_PREFIXES`, `NOWPAYMENTS_FIELDS`.
