Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChargeCore

A net-60 business charge card core — the ledger and billing engine behind a modern commercial charge-card program. Authorization lifecycle, double-entry accounting, statement cohorts on 60-day terms, prepayment of current-cycle spend, a repayment-mode policy engine (float / 1.75% early-pay cashback / 1.75x points), and idempotent ACH repayment ingestion that survives post-settlement returns.

python -m pytest tests -q     # 29 tests incl. Hypothesis stateful fuzzing (300 runs x 50 steps)
python demo.py                # spend -> statement -> cashback -> R01 bounce

Zero runtime dependencies. Python 3.11+. pytest + hypothesis for tests.

Why this shape

  • DESIGN.md — ten explicit assumptions (issuer-processor boundary, bank-partner boundary, memo auths, FIFO allocation, async ACH failure) stated before the code, plus chart of accounts and posting rules.
  • Functional core, imperative shell — every business rule (card.py, statements.py, repayment.py, ach.py) is a pure function over immutable data; engine.py is the only place effects happen.
  • Fuzz-tested invariants — a Hypothesis state machine drives random legal operation sequences and asserts six accounting invariants after every step (trial balance, receivable ≡ cohort remainders, open-to-buy identity, replay determinism, in-transit consistency, non-negative rewards).
  • REVIEW.md — two adversarial review rounds, seven findings fixed — including a fuzzer-caught accounting bug (rewards liability driven negative by redeem-then-bounce) and two money-loss reward bugs — plus consciously accepted gaps.

The flow that matters

ACH settlement is provisional. The sequence this system is built around:

  1. Holder pays their $100k statement early → 1.75% cashback granted, credit line released.
  2. Holder spends $50k of the freed line.
  3. The ACH comes back R01 days later.

The engine reverses the cash, reopens the statement cohort (re-aging it), claws back the cashback, and re-consumes the credit line — open-to-buy goes negative, and the trial balance still holds. That flow is a first-class test, not an afterthought.

Layout

chargecore/money.py        integer cents, bps math (round-down)
chargecore/ledger.py       append-only double-entry journal
chargecore/card.py         auth/clearing decisions (pure)
chargecore/statements.py   cohorts, net-60 terms, FIFO allocation, aging (pure)
chargecore/repayment.py    reward policy engine (pure)
chargecore/ach.py          payment-intent state machine, return codes (pure)
chargecore/engine.py       imperative shell: idempotency, credit state, postings
tests/                   scenario tests + Hypothesis property tests

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages