Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

9 downloads

Install on DigitalOcean Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Daniel Quellhorst Changelog for this batch. 65ef78d 3 hours, 31 minutes ago History
dbbasic-package.json · 11.6 KB · 137 lines
1{
2 "id": "app-billing",
3 "name": "Billing",
4 "version": "0.11.0",
5 "description": "Prepaid wallets and the ledger that IS their balance. The predecessor kept a mutable Wallet.balance column beside a Transaction table -- two truths that drift, and when they drift the customer is right and you cannot prove otherwise; here wallets.balance_minor is a ROLLUP over append-only wallet_entries, so the entries are the balance and nothing may write the number (docs/logic-decisions.md #3). Amounts are integer minor units (object_money.py), so a wallet holds dollars or satoshis or a gift-card unit without special cases. hook_wallet_entries gates debits by summing the ENTRIES rather than trusting the rollup -- a gate must be authoritative, and it documents the known check-then-append race honestly rather than pretending a reserve/capture system exists. system_wallet_replenish tops up from a saved card off-session, with the safeguard the predecessor also carried and most systems skip: a MONTHLY CAP, because autopay plus one runaway metering bug is a four-figure surprise, and a cap of zero (the default) means auto top-up is simply off. Declines -- especially the authentication-required kind an off-session charge cannot satisfy -- are reported for a human to act on, never retried in a loop that gets a processor account flagged. Plans, subscriptions and the period biller are the next slice; this one is the money container they will draw on. 0.2.0 adds the recurring half: billing_plans is a price book that VERSIONS FORWARD (an invoice must forever show the price it was billed under, so a change is a new row, never a rewrite of history customers already paid against), subscriptions carry billing_mode explicitly (wallet | subscription | hybrid -- guessing the mode from whether a plan has a base price breaks the moment someone sells a zero-base plan with a real contract), and system_billing_runner closes periods into invoices. Double-billing is the failure customers never forgive, so the runner is idempotent by provenance rather than by a dedup table: a marker on the invoice means a re-run after a crash raises nothing. The status ladder climbs BOTH ways -- paying restores service, because a ladder that only descends leaves a paying customer cut off -- and cancel-at-period-end runs service to the end of the paid period rather than billing someone for time they cannot use. 0.3.0 completes the metering half: usage_events (append, caller-supplied event_id deduped by hook -- retries are metering's number one corruption source and a timed-out client must not be billed twice), system_usage_rollup folding them into usage_summaries, and rating at period close via object_billing. Rating reads SUMMARIES, never raw events: allowances and tiers are properties of a period's total, so per-event rating charges the first calls at retail and never applies the included quantity -- and the bucket boundary means metering can start batching later without touching one line of pricing. Usage lines say what was used, what the plan included and what the overage cost, so a customer can CHECK a bill rather than only dispute it. A metric with usage but no price is charged nothing and REPORTED, because silently billing for something the plan never named is worse than the revenue, while silently dropping it hides a pricing gap. Events stamp our own cost, so margin per customer per metric is a fold rather than a spreadsheet. 0.5.0 says out loud what this container already was: A GIFT CARD IS A WALLET, and store credit is the same thing issued by a refund or a dispute rather than bought. Both are prepaid money somebody can spend here, both need a movement log rather than a mutable number, and both need a gate that refuses to let anybody spend what is not there -- which is exactly this collection and hook_wallet_entries. Building a gift_cards table with its own balance column beside them would be reconstructing the predecessor's drift bug in a corner nobody watches, for money that arrives as a bearer instrument and is therefore the least forgiving place to be wrong. So the slice is two fields and no new machinery: wallets.kind (balance | gift_card | store_credit) and wallets.code, the bearer token a card is redeemed by, unique when present and compared upper-cased. Uniqueness lives in hook_wallets because schemas here carry no uniqueness constraint, and it fails CLOSED on an unreadable list: a refused card is reissued in ten seconds, a duplicated one is discovered when somebody's balance is gone. system_gift_card_issue is the fulfilment half -- buying a card is an ORDINARY PRODUCT SALE (products.is_gift_card marks the catalogue row) whose fulfilment credits a wallet instead of putting something in a box, one wallet per LINE because three cards on one order are three presents for three people, waiting for the invoice to be SETTLED because a card is money, and idempotent by a generated_from marker per order line because a replayed payment that issued a second card is the shop giving away money. Redemption is nobody's new code: action_checkout debits the wallet through the EXISTING hook_wallet_entries gate, asked in process because trusted server-side writes bypass hooks by design, so a card cannot overdraw and a preview writes nothing. action_resolve_dispute already wrote store credit into this same ledger; the only thing v2 adds to that path is a name for what it was doing. 0.9.5: a row a registered user writes could point at anybody's record, because the rules asked only that the new row be the writer's own. Every pointer a non-admin can write now declares relation.requires (subscriptions.customer_id read, subscriptions.plan_id read, subscriptions.wallet_id update, subscriptions.entity_id update, usage_events.subscription_id update, wallets.denomination_id read, wallets.entity_id update), so over the API a row points only at a record its writer may see, or, where it moves money, stock or state of what it points at, may update; a record they may not see is answered like a missing one (docs/permissions-model.md, 'Pointing at a record you may not act on'). 0.9.6: system_gift_card_issue takes as the order an invoice settles only one owned by the invoice's owner: an order of somebody else's pointed at the shop's invoice had its own gift card lines issued, funded by the shop's customer's payment. 0.10.0: a subscription's terms are staff's and the biller's. The subscriber owns the row, and the registered create/read/update/delete grant let them PUT past_due or suspended -> active without paying, swap plan_id for a cheaper plan, push current_period_end (or trial_ends_on) years out so the biller never closes a period, switch billing_mode, or delete the agreement. subscriptions.json v3 declares field permissions {edit: role:manager, role:admin; default: read} on customer_id, plan_id, billing_mode, wallet_id, status, the period and trial dates, external_ref and entity_id; a subscriber reads their subscription and may change cancel_at_period_end, customer_name, customer_email and notes. role:manager creates, reads and updates every subscription; the owner fallback is off for delete; the old grant is retracted. 0.10.1: a wallet holder sets their own auto top-up and nothing about the money. The registered update grant on wallets let the holder PUT stripe_customer_id and payment_method_ref to another customer's saved card (system_wallet_replenish charges it off-session into this wallet), restate the balance in another denomination, or turn a balance or store-credit wallet into a bearer gift card with kind and code. wallets.json v6 makes kind, code, denomination_id, stripe_customer_id, payment_method_ref and entity_id field permissions {edit: role:manager, role:admin; default: read}; the holder keeps auto_replenish_* and is_active. 0.11.0: decision 4 (owner, 2026-11-30): the base fee is billed in advance and usage in arrears. A period that has begun with its base fee unbilled is billed at once (number ...-ADV); the invoice that closes a period carries its usage and the next period's base fee, or only the usage when the subscription cancels at that period's end. Base-fee lines carry service_start/service_end, and on accrual books the biller releases revenue billed in advance from Deferred Revenue month by month. system_usage_rollup buckets usage by when it occurred (finding M11), and leaves late usage for a period already invoiced unrated and reported. action_subscription_credit_unused (staff) ends a subscription now with a pro-rata credit note for the unused days.",
6 "compatibility": {
7 "dbbasic_object_server": ">=0.1.0"
8 },
9 "dependencies": [
10 "app-finance",
11 "app-payments",
12 "app-invoices"
13 ],
14 "objects": [
15 {
16 "id": "action_subscription_credit_unused",
17 "path": "objects/action/subscription_credit_unused.py"
18 },
19 {
20 "id": "hook_wallet_entries",
21 "path": "objects/hook/wallet_entries.py"
22 },
23 {
24 "id": "system_wallet_replenish",
25 "path": "objects/system/wallet_replenish.py"
26 },
27 {
28 "id": "system_billing_runner",
29 "path": "objects/system/billing_runner.py"
30 },
31 {
32 "id": "system_usage_rollup",
33 "path": "objects/system/usage_rollup.py"
34 },
35 {
36 "id": "system_gift_card_issue",
37 "path": "objects/system/gift_card_issue.py"
38 },
39 {
40 "id": "system_wallet_books",
41 "path": "objects/system/wallet_books.py"
42 },
43 {
44 "id": "site_customer_funds",
45 "path": "objects/site/customer_funds.py"
46 }
47 ],
48 "schemas": [
49 {
50 "collection": "wallets",
51 "path": "schemas/wallets.json"
52 },
53 {
54 "collection": "wallet_entries",
55 "path": "schemas/wallet_entries.json"
56 },
57 {
58 "collection": "billing_plans",
59 "path": "schemas/billing_plans.json"
60 },
61 {
62 "collection": "subscriptions",
63 "path": "schemas/subscriptions.json"
64 },
65 {
66 "collection": "usage_events",
67 "path": "schemas/usage_events.json"
68 },
69 {
70 "collection": "usage_summaries",
71 "path": "schemas/usage_summaries.json"
72 }
73 ],
74 "permissions": [
75 {
76 "path": "permissions/rules.json"
77 }
78 ],
79 "seed": [
80 {
81 "collection": "wallets",
82 "path": "seed/wallets.tsv"
83 },
84 {
85 "collection": "wallet_entries",
86 "path": "seed/wallet_entries.tsv"
87 },
88 {
89 "collection": "billing_plans",
90 "path": "seed/billing_plans.tsv"
91 },
92 {
93 "collection": "subscriptions",
94 "path": "seed/subscriptions.tsv"
95 },
96 {
97 "collection": "usage_events",
98 "path": "seed/usage_events.tsv"
99 },
100 {
101 "collection": "usage_summaries",
102 "path": "seed/usage_summaries.tsv"
103 }
104 ],
105 "migrations": [],
106 "schedules": [
107 {
108 "id": "billing_usage_rollup_daily",
109 "object_id": "system_usage_rollup",
110 "schedule": "10 7 * * *",
111 "description": "Fold usage events into period summaries. Runs BEFORE the biller so a period that closes today is rated against usage that has already been folded."
112 },
113 {
114 "id": "billing_runner_daily",
115 "object_id": "system_billing_runner",
116 "schedule": "25 7 * * *",
117 "description": "Close periods that ended, raise one invoice each, and walk the unpaid ladder. Idempotent by provenance, so a missed day is caught up rather than double-billed."
118 },
119 {
120 "id": "wallet_replenish_daily",
121 "object_id": "system_wallet_replenish",
122 "schedule": "40 7 * * *",
123 "description": "Top up wallets that fell below their threshold, within the monthly cap."
124 }
125 ],
126 "nav": [
127 {
128 "id": "customer_funds",
129 "label": "Customer Funds",
130 "path": "/customer-funds",
131 "blurb": "What customers are owed, checked against what the books say we owe",
132 "surface": "member",
133 "group": "Money",
134 "order": 345
135 }
136 ]
137}