Skip to content

URD: Payment & Transaction

ModuleCORE-08Versionv0.4
StatusIn-progressDate2026-05-30

1. Purpose

Define the user-facing requirements for collecting payments and recording the resulting money. The module connects a merchant's payment providers to BANA, surfaces live payment status, and books every completed payment, purchase, and stock movement into a double-entry finance ledger so owners can see balances and reconcile their books.

2. Scope

IncludedExcluded
Per-merchant payment provider credentials (VNPAY QR MMS, PhonePOS)Direct gateway integration code (developer concern)
Real-time payment status (webhook + WebSocket)Checkout / split-payment UX (Orders module)
Outbound webhook subscriptions per merchantCard-data / token storage
Finance accounts / wallets + control accountsMulti-currency conversion
Double-entry vouchers (RECEIPT / PAYMENT / TRANSFER / ADJUSTMENT)Tax invoice issuance (Tax & Invoice module)
Auto-posting from sale, purchase, and inventory eventsStructured provider refunds (Planned)
Category hierarchy (seeded + custom)Per-shift cash reconciliation (Planned)

3. Definitions

TermDefinition
Payment providerAn external service (e.g. VNPAY) that processes a customer's payment
WebhookAn outbound notification BANA sends to a subscriber when a payment changes state
Account / WalletA place money sits: cash, bank, QR collection, mobile POS, or an internal control account
VoucherA balanced bookkeeping entry of one type (RECEIPT, PAYMENT, TRANSFER, ADJUSTMENT)
Transaction (ledger line)One DEBIT or CREDIT line within a voucher, affecting one account's balance
CategoryAn income or expense label classifying where money came from or went
Auto-postingA voucher created automatically by the system in reaction to a business event

4. Conceptual Model

Conceptual only — full schema lives in the payment and finance developer domain models.

5. Functional Requirements

One table per functional area. <AREA> codes match the test-case IDs. Priority = MoSCoW (Must / Should / Could / Won't).

5.1 Payment Lifecycle (PAY)

IDPRequirement
URD-PAY-001MThe system receives payment results from the provider and updates the payment's status
URD-PAY-002MOn a successful payment, the system notifies subscribers (e.g. the sale that settles the order)
URD-PAY-003MPayment status is broadcast live to the cashier (pending → paid / failed / expired)
URD-PAY-004MThe same payment result is applied only once, even if delivered multiple times (idempotent)
URD-PAY-005SAn owner can subscribe webhook endpoints by event type, with retries on delivery failure
URD-PAY-006WStructured refund back through the original provider (Planned — see §7)

5.2 Provider Credentials (PRV)

IDPRequirement
URD-PRV-001MAn owner can connect a payment provider (VNPAY QR MMS, PhonePOS) per merchant
URD-PRV-002MProvider credentials are stored encrypted and never shown in full
URD-PRV-003SCredentials are scoped per merchant so one merchant cannot use another's

5.3 Accounts & Wallets (WAL)

IDPRequirement
URD-WAL-001MAn owner can create accounts of type CASH, BANK, QR code, or mobile POS
URD-WAL-002MThe system maintains internal control accounts (e.g. inventory, COGS) automatically
URD-WAL-003MEach account tracks an opening balance and a running current balance
URD-WAL-004MA default account per merchant receives auto-posted sale income
URD-WAL-005SNon-owner roles see only the accounts of merchants they are granted access to

5.4 Vouchers & Ledger (VCH)

IDPRequirement
URD-VCH-001MEvery voucher is balanced: total DEBIT equals total CREDIT
URD-VCH-002MVoucher types are RECEIPT, PAYMENT, TRANSFER, ADJUSTMENT
URD-VCH-003MA completed sale payment auto-posts a RECEIPT voucher to the default account
URD-VCH-004MReceiving a purchase order auto-posts a PAYMENT voucher
URD-VCH-005MA stock issue/adjustment auto-posts the matching ledger voucher
URD-VCH-006MEach voucher records its source event so the same event posts only once (idempotent)
URD-VCH-007MVouchers are numbered per merchant and type (e.g. PT / PC / PCK / PKT)
URD-VCH-008SAn owner can create a manual voucher (draft → issue)
URD-VCH-009SAn owner can void a voucher via a balanced reversal (no hard delete)
URD-VCH-010CTransfer between two accounts is recorded as a zero-sum voucher

5.5 Categories (CAT)

IDPRequirement
URD-CAT-001M14 system categories are seeded and cannot be removed
URD-CAT-002MCategories are typed as INCOME or EXPENSE
URD-CAT-003SAn owner can add merchant-specific custom categories, including a parent hierarchy

6. Acceptance Criteria

AC-PAY-01: Payment status updates
GivenWhenThen
A pending paymentThe provider reports successStatus becomes paid, subscribers are notified, cashier sees the update live
A pending paymentThe provider reports failure / expiryStatus becomes failed / expired; the order stays open
An already-applied resultThe same result is redeliveredIt is ignored; no duplicate effect
AC-VCH-01: Auto-posting from events
GivenWhenThen
A successful sale paymentThe event is processedA balanced RECEIPT voucher posts to the default account
A received purchase orderThe event is processedA balanced PAYMENT voucher posts
The same source eventIt is delivered againNo second voucher is created (idempotent)
AC-VCH-02: Manual voucher and void
GivenWhenThen
An ownerCreates and issues a manual voucherA balanced voucher appears in the ledger with a sequence number
An issued voucherThe owner voids itA balanced reversal voucher is posted; the original is preserved
AC-WAL-01: Accounts and balances
GivenWhenThen
An ownerCreates an account with an opening balanceThe account shows that opening balance as current
A posted voucherIt debits/credits an accountThe account's running balance updates accordingly

7. Constraints & Non-Goals

Constraints

IDConstraint
C-01Every voucher must be balanced (DEBIT total = CREDIT total)
C-02The 14 seeded categories cannot be removed
C-03Provider credentials are encrypted at rest and masked in responses
C-04Each business event posts at most one voucher (idempotent via source event id)
C-05Records use soft-delete / reversal — no hard delete of financial history
C-06One default account per merchant for auto-posted sale income

Non-Goals

  • SoftPOS / NFC tap-to-pay flow
  • Additional e-wallet providers (Momo, ZaloPay)
  • Structured refund / reversal of external provider charges
  • Multi-currency conversion and cross-currency reconciliation
  • Per-shift cash reconciliation dashboard

8. Version History

DateAuthorDescriptionVer
2026-02-26P. Do — Product OwnerInitial user storiesv0.1
2026-04-16P. Do — Product OwnerFinance wallets, transactions, categoriesv0.3
2026-05-30MigrationRestructured to module convention; aligned areas (PAY/PRV/WAL/VCH/CAT) to two-package reality; refund + reconciliation marked Plannedv0.4

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.