Skip to content

Debit cards, ATMs and payments - #21

Merged
KoertLichtendonk merged 2 commits into
mainfrom
dev
Nov 25, 2026
Merged

KoertLichtendonk merged 2 commits into
mainfrom
dev

Conversation

@KoertLichtendonk

@KoertLichtendonk KoertLichtendonk commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Merges everything on dev into main (2 commits). Merging publishes a new OpenRP.Framework NuGet version.

Changes

  • Debit cards: ordered at the teller with an optional name and a PIN; renamed, re-PINned, blocked, unblocked or replaced there. Three wrong PINs block a card.
  • ATMs: placed kmb_atm1 map objects (model 2942) work as ATMs through /atm: balance, withdrawals up to 1,000 per card in 24 hours, and deposits that are credited 2 hours later.
  • Payments: ICheckoutService gives features one way to take a cash or card payment into a bank account. /testpayment tries it out; no feature uses it yet.
  • Inventories: IInventoryItemNameProvider lets features give items their own names and extra information.

Database

Hosts need a migration after updating:

Change
New tables BankCards and BankPendingDeposits
New nullable columns BankTransactions.BankCardId and BankTransactions.Description
New seed data: the Debit card item (68)

No NuGet packages were added or changed.

- Banking: debit cards ordered at the teller, with an optional name and a 4-digit PIN hashed with BCrypt; rename, change PIN, block, unblock or replace; 3 wrong PINs block the card; removing someone's access blocks their cards
- ATMs: every placed kmb_atm1 map object (model 2942) is an ATM; /atm shows the balance, withdraws cash (at most 1,000 per card in 24 hours) and deposits cash that reaches the account 2 hours later; an account can't close while a deposit is on its way
- Payments: ICheckoutService lets features take a cash or card payment into a bank account; /testpayment for testers and admins
- Inventories: IInventoryItemNameProvider lets a feature name its items, so a card shows its bank, account and digits; Use on a card opens the ATM or the card's details
- Docs: cards and ATMs, payments, banking, database, commands

Database: new tables BankCards and BankPendingDeposits, new BankTransactions columns BankCardId and Description, and a seeded Debit card item (68). Hosts need a migration.
}

/// <summary>
/// The limit check and the debit in one transaction, so two withdrawals at once can't both pass the limit.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix (or a question): this comment promises more than the code does when several servers share one database.

The SUM in GetWithdrawnInPeriod is a normal read. In MySQL/MariaDB (InnoDB), a normal read inside a transaction does not lock anything. So two servers that withdraw with the same card at the same moment can both read "900 used", both pass the check, and both debit 100. The card then ends at 1,100. The UPDATE on BankAccounts only waits for the balance; it doesn't run the limit check again.

On one server this can't happen, because everything runs one after the other on the main thread. That's why I'm not calling it blocking.

A small fix is to lock the card row first, so the second withdrawal waits until the first one commits:

// Takes a row lock on the card, so a second withdrawal with this card waits here.
db.BankCards.Where(row => row.Id == card.Card.Id)
    .ExecuteUpdate(setters => setters.SetProperty(row => row.WrongPinAttempts, row => row.WrongPinAttempts));
if (GetWithdrawnInPeriod(db, card.Card.Id) + amount > BankingRules.AtmWithdrawalLimit)

If you'd rather leave it, please change the comment to say it's only safe on one server, and add that to the known limitations in docs/features/banking/cards-and-atms.md.

using System.Linq;
using System.Text;
using System.Threading.Tasks;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix: this file changed from CRLF to LF line endings, so GitHub shows all 352 lines as rewritten. The real change is about 35 lines (the name providers). This blank line in the using block is also new.

It makes the diff hard to review and git blame loses the history of the whole file. AGENTS.md says not to reformat code the task doesn't need.

Fix: put the file's original line endings back (for example open it in an editor that keeps CRLF, or run unix2dos on it) and remove this blank line, so only the provider changes are left in the diff.

@claude

claude Bot commented Nov 25, 2026

Copy link
Copy Markdown

Review

Verdict: Needs changes
This adds debit cards (PIN, block, replace), ATMs on placed kmb_atm1 objects with a withdrawal limit and delayed deposits, and ICheckoutService for cash or card payments into a bank account. It's careful work: dialogs use ShowIgnoringDisconnect, the player is checked after each await, BCrypt work on Task.Run doesn't touch the game world, money moves only through BankLedger inside transactions, and deposits are claimed so two servers can't credit them twice. I found nothing blocking, only the small points below.

Should fix

  • AtmService.TryDebitWithinLimit: the comment says two withdrawals can't both pass the limit. That's true on one server, but not when two servers share the database, because the SUM doesn't lock anything. Lock the card row first, or describe it as a known limitation. (inline)
  • InventoryDialogService.cs: the whole file went from CRLF to LF line endings, so about 35 changed lines show up as 352. Please put the original line endings back. (inline)
  • Small: AtmSession.GetCardId() is a public component method without a /// <summary>.

Docs: up to date. There are new pages for cards and ATMs and for Payments, a line in docs/README.md, /atm and /testpayment in commands.md, both new tables in database.md, the new teller permission, and the "No ATMs, cards" limitation is removed. The new links work.
Database: changes: new tables BankCards and BankPendingDeposits, new nullable columns BankTransactions.BankCardId and Description, and seed item 68 added with HasDefaultData. The description says hosts need a migration. No NuGet packages were added (BCrypt was already used).
Tested in game: not described. Please say what you tried, for example on OpenRP.Boilerplate: ordering a card, a wrong PIN three times, an ATM withdrawal and deposit, and /testpayment with cash and with a card.

- ATMs: lock the card row before the withdrawal limit check, so two withdrawals with one card, even on two servers, can't both pass the limit
- Inventories: InventoryDialogService.cs keeps its CRLF line endings and loses the extra blank line, so only the item name changes are left
- AtmSession.GetCardId() gets a summary
- Docs: cards and ATMs
@claude

claude Bot commented Nov 25, 2026

Copy link
Copy Markdown

Review

Verdict: Ready to merge
This adds debit cards, ATMs on placed kmb_atm1 objects with a daily withdrawal limit and delayed deposits, and ICheckoutService for cash or card payments. I reviewed the whole pull request again, including the new commit "Apply the review comments on #21". All three earlier points are fixed and I found nothing new.

Earlier points, now fixed:

  • ATM limit with several servers: TryDebitWithinLimit now locks the card row with a no-op ExecuteUpdate before it adds up the withdrawals. On InnoDB the UPDATE takes the row lock, and it runs before the first plain read, so the SUM sees any withdrawal another server committed. It goes through the same IDbContextTransaction as the debit. The docs say this too.
  • Line endings in InventoryDialogService.cs: CRLF is back. Compared with main, the diff is now just the 37 lines for the name providers.
  • AtmSession.GetCardId(): now has a /// <summary>.

dotnet build passes. The CS8604 warning in BankDialogService.cs (onEntered(response.InputText)) was already on main.

Docs: up to date
Database: changes: new tables BankCards and BankPendingDeposits, new nullable columns BankTransactions.BankCardId and Description, and seed item 68 added with HasDefaultData (hosts need a migration, as the description says). No NuGet packages were added.
Tested in game: not described. Before merging, please try it on a host such as OpenRP.Boilerplate: two quick withdrawals with one card near the limit, a wrong PIN three times, an ATM deposit being credited, and /testpayment with cash and with a card.

@KoertLichtendonk
KoertLichtendonk merged commit 60b0273 into main Nov 25, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant