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

0 downloads

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.

danq9 signup: the person chooses the password and name on the confirm page 83c7aa6 2 weeks, 5 days ago History
wallets.json · 6.3 KB · 52 lines
1{
2 "name": "wallets",
3 "title": "Wallets",
4 "version": 2,
5 "hooks": {"before_write": "hook_wallets"},
6 "description": "Prepaid balance for pay-as-you-go usage. The design decision that matters is in one field: balance_minor is a ROLLUP over wallet_entries, never a stored number anyone writes. 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 the entries ARE the balance; the number on this record is a materialized view of them that the engine recomputes on every entry write (docs/logic-decisions.md #3: money moves, it does not mutate). Amounts are integers of the denomination's smallest unit (object_money.py), so a wallet can hold dollars, satoshis, or a gift-card unit without special cases. Card rails charge a fixed fee per transaction, which is why prepaid exists at all: sub-dollar charges are individually nonviable, so the provider sees occasional top-ups and the micro-debits stay internal. Auto-replenishment carries a MONTHLY CAP for a reason worth naming -- autopay plus one runaway metering bug is how a customer wakes up to a four-figure surprise; the cap turns that into a bounded annoyance someone notices. v2 says out loud what this container already was: A GIFT CARD IS A WALLET, and so is store credit. Both are prepaid money the customer can spend here, both need a movement log rather than a mutable number, and both need a gate that refuses to let somebody spend what is not there -- which is precisely what this collection and hook_wallet_entries already are. Inventing a gift_cards table with its own balance column and its own spend check would be building the predecessor's drift bug a second time, in a corner nobody watches, for money that arrives as a bearer instrument. So v2 adds exactly two fields and no new machinery: `kind` says which of the three this wallet is, and `code` is the bearer token a gift card is redeemed by. The distinction between them is WHO CAN SPEND IT: a balance and store credit belong to owner_id and are spent by that person, while a gift card belongs to whoever holds the code -- which is the whole point of a gift card and the reason redemption keys on the code rather than on an account the recipient does not have.",
7 "fields": [
8 {"name": "id"},
9 {"name": "owner_id", "type": "text", "required": true, "label": "Owner",
10 "help": "One wallet per owner per denomination. For a GIFT CARD this is the shop, not the recipient: a gift card is a bearer instrument redeemed by its code, and a guest who was handed one has no account to own it with."},
11 {"name": "kind", "type": "enum", "default": "balance", "label": "Kind",
12 "enum": ["balance", "gift_card", "store_credit"],
13 "help": "balance: the ordinary prepaid wallet a customer tops up to pay for usage. gift_card: money somebody bought for somebody else, spent by whoever holds `code`. store_credit: money the shop gave back -- a refund taken as credit, or a dispute resolved that way (action_resolve_dispute writes into exactly this collection). All three are the same container with the same ledger and the same gate; the field says which conversation you are in, not which rules apply."},
14 {"name": "code", "type": "text", "label": "Code",
15 "validation": {"max_length": 40},
16 "help": "The bearer token a gift card is redeemed by, blank for an ordinary wallet. UNIQUE WHEN PRESENT and compared upper-cased -- hook_wallets enforces both, because schemas here carry no uniqueness constraint and two cards sharing a code would let one person spend the other's money with no way to tell which balance was meant. Given to a store_credit wallet as well when the shop wants it redeemable at a guest checkout, which is the only way credit reaches somebody who has no account."},
17 {"name": "denomination_id", "label": "Denomination",
18 "relation": {"collection": "denominations", "display_field": "code"},
19 "help": "What this wallet holds. Blank means the server default (USD)."},
20 {"name": "balance_minor", "type": "computed", "label": "Balance",
21 "rollup": {"collection": "wallet_entries", "fk_field": "wallet_id",
22 "op": "sum", "field": "amount_minor"},
23 "help": "Derived, never written: the sum of every entry, credits positive and debits negative. If this and the entries ever disagreed, the entries would be right -- which is why nothing may set it."},
24 {"name": "auto_replenish_enabled", "type": "boolean", "default": "false",
25 "label": "Auto Top-up"},
26 {"name": "auto_replenish_threshold_minor", "type": "integer", "default": "0",
27 "label": "Top up below",
28 "help": "When the balance falls below this, charge the saved card."},
29 {"name": "auto_replenish_amount_minor", "type": "integer", "default": "0",
30 "label": "Top-up amount"},
31 {"name": "auto_replenish_monthly_cap_minor", "type": "integer", "default": "0",
32 "label": "Monthly cap",
33 "help": "The most that may be auto-charged in a calendar month. Zero means auto top-up is effectively off: a cap of nothing is the safe default, because an uncapped autopay plus a metering bug is a four-figure surprise."},
34 {"name": "stripe_customer_id", "type": "text", "label": "Stripe Customer",
35 "help": "Set when a card is saved. The card itself never touches this server -- only the provider's reference to it."},
36 {"name": "payment_method_ref", "type": "text", "label": "Saved Card",
37 "help": "The provider's payment-method id used for off-session top-ups. An identifier, not an instrument."},
38 {"name": "is_active", "type": "boolean", "default": "true", "label": "Active"},
39 {"name": "entity_id", "type": "text", "label": "Entity",
40 "relation": {"collection": "entities", "display_field": "name"}},
41 {"name": "created_at", "type": "datetime", "read_only": true, "label": "Created"}
42 ],
43 "forms": {"default": {"fields": ["kind", "code", "denomination_id",
44 "auto_replenish_enabled",
45 "auto_replenish_threshold_minor",
46 "auto_replenish_amount_minor",
47 "auto_replenish_monthly_cap_minor", "is_active"]}},
48 "views": {"list_mode": "table",
49 "list_fields": ["owner_id", "kind", "balance_minor",
50 "auto_replenish_enabled", "is_active"],
51 "filter_fields": ["kind"]}
52}