Repository navigation
Keep every cheque for a sale, so one that is not the customer's cannot hold it - #49
Open
todortodorovic wants to merge 1 commit into
Open
todortodorovic wants to merge 1 commit into
todortodorovic wants to merge 1 commit into
Conversation
…t hold it Anyone who has seen the QR can post a cheque for it, and a cheque says nothing about who sent it. The terminal took the first cheque that matched and dropped everything that arrived while its claim ran, so a cheque whose coins the host refuses cost the customer's cheque its turn for good. A cheque whose coins never come kept the host waiting for up to an hour, with no way for the merchant to leave the sale. The statement handling moves to lib/payments/coinage/cheque-intake.ts: - A cheque above the cheque limit is an amount mismatch. normalizeAmount used to throw there, out of the statement handler, which on TrUAPI ended the subscription. - Every matching cheque is kept, by its coins, and they are claimed one at a time. A registration stays live at the host whatever the terminal does, so two that may both credit are never run for one sale. Each cheque tracks its registrations the host accepted (claimCoins now reports which one it follows) and clears one only on the host's last word about that registration. While any may still credit, the other cheques wait and only Retry runs it again. A full book never evicts such a cheque. - On SourceBusy, claimCoins follows the registration the host last accepted for these coins. - A failed cheque re-posted runs again on its own at most twice. One sale makes at most 12 registrations on its own; after that, only Retry registers, and Retry stays offered while cheques wait. When the book is full, failed cheques make room. - Skipped statements are logged a few per reason, and the rest are counted across pages. A stranger's values are quoted, stripped of control characters and cut short, so junk can neither forge log lines nor push the claim's lines out of Report Issue. - Pending-claim writes run one after another. - The statement subscription is re-armed after a host drop even while a claim runs. A claim that has waited 40 s for its coins (longer than one 30 s host detection pass) lets the merchant cancel. A sale that ends before its claim settles, cancelled or left, hands its pending claim to lib/payments/coinage/claim-handoff.ts. That follows it in the background in this session, so a claim that lands is recorded now, not at the next launch. Pending claims are resumed by following all of a record's registrations at once, so one that waits for coins that never come cannot hold up one that credited. The QR screen: - The QR never comes back once a cheque arrived. The QR, its test attribute and NFC follow one flag. - The claim host is set up before the QR goes out. - Retry shows only when there is a cheque to claim again. - "retry N" counts the claims of the cheque being claimed. - A failed claim is recorded in telemetry once per sale. /terminal?amount= is charged through startPayment like the keypad, with the connectivity pre-flight: - An amount above the limit lands on the keypad with the limit warning. - If the pre-flight fails, the amount goes on the keypad, and Charge on it charges the URL's exact amount, sub-cent tip included. - A tip larger than the sale is dropped. - A different sale drops the URL's tip and items. A pre-flight that returns after Cancel or a newer Charge no longer arms its QR.
|
pr49-terminal.paseo · logs |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Anyone who has seen the QR can post a cheque for it, and a cheque says nothing about who sent it. Both security audits found several ways a stranger's cheque could take over or freeze a sale:
normalizeAmountthrew out of the statement handler. On TrUAPI that ended the subscription and started a re-subscribe loop (audit 2, Medium).detectingfor up to an hour. There was no Cancel while claiming./terminal?amount=skipped the coin limit and the pre-flight.What
Cheque intake (new
lib/payments/coinage/cheque-intake.ts, used byuse-coinage-payment.ts):claimCoinsnow reports which registration it follows (onFollow), so each cheque tracks its accepted registrations.SourceBusy, the claim follows the registration the host last accepted for those coins.Leaving a sale with a live claim:
claim-handoff.ts. That follows it in the background in this session, so a claim that lands is recorded now, not at the next launch.resumePendingClaimsfollows all of a record's registrations at once, so one that never settles cannot hold up one that credited.QR screen (
app/(shell)/terminal/page.tsx):data-qr-valueand NFC follow one flag./terminal?amount=goes throughstartPaymentlike the keypad, with the limit and the pre-flight:Not covered
These need sender authentication in the protocol:
main.Also left for the claim-lifecycle PR: Cancel after a non-final claim error still drops the sale. Its claim is now followed in the background, though.
Testing
tests/cheque-intake.test.ts, plus additions tocoinage-claimandpending-claims. 240 unit tests pass;tscand lint are clean.e2e/payments/coins-cheque-intake.spec.ts, plus an over-limit case incoins-cheque-filter. All 140 e2e tests pass. They cover:?amount=over the limit and through the pre-flight.