CSE Roadmap

Core tier · about 5 hours · 8 parts

Part 4 of 8 · 2 min read

Ledger and security

Double entry and card data.

Double-entry accounting. Every transaction is written down twice, once in each of two accounts, and the amounts match. One account loses value (a debit) and the other gains it (a credit). The sum of all entries must be zero. If a cent is lost somewhere, someone else is missing a cent, and the error shows up. This gives a full trail and consistency end to end. Ledger rows are only ever added, never edited. A mistake is corrected by a new, opposite entry.

A worked example (made up). A buyer pays $30 for an item, and the platform keeps a $3 fee. The entries: debit the buyer $30; credit the seller $27; credit the platform's fee account $3. The credits, 27 + 3, equal the debit of 30, so the sum is zero.

Card data and the hosted payment page. Storing card data triggers strict rules such as PCI DSS. Most companies avoid it. The PSP offers a hosted payment page, a web widget or mobile page that collects the card details directly. The details never touch the shop's servers.

How it works:

  1. The user clicks checkout. The client sends the order to the payment service.
  2. The payment service registers the payment with the PSP, sending the amount, currency, an expiry and a redirect URL. A unique value (a nonce) in the request ensures a payment is registered only once. The PSP returns a token that stands for the registration.
  3. The service stores the token.
  4. The client shows the PSP page, using the token. The user types the card details there.
  5. The PSP processes the payment and redirects the browser to the redirect URL with the status.
  6. Separately, the PSP calls a webhook on the payment service with the final status. The service updates the order status from it.

The redirect is for the user's screen. The webhook is the reliable signal for your system.

Pay-out. Similar to pay-in, but a third-party pay-out provider moves the money from the shop's bank account to the seller's. It also needs careful bookkeeping and rules.

Double-entry bookkeeping

Double-entry bookkeeping records every transaction as equal debits and credits in two accounts, so all entries always sum to zero.

Example: a $30 sale is a debit of $30 to the buyer and credits of $27 to the seller and $3 to the platform.

Check yourself: 1. Why is the ledger append-only? 2. What is the purpose of the token from the PSP? 3. Why trust the webhook more than the redirect?