Payments
How money is taken and given back. A deliberately small context that owns the vocabulary of settling a charge — nothing in it knows what was bought, which is why the parking-garage model can reference its PaymentMethod instead of keeping a second copy of the same list.
Glossary
Merchant— Whoever took the money and can give it back. Issues aRefund; a role, not modeled as an entity.Payer— Whoever hands over the money for aPayment— a person at a terminal, or a standing arrangement charged automatically. A role, not modeled as an entity.
Enums
PaymentMethod
How a Payment was tendered.
| Value | Definition |
|---|---|
card | A payment card, tapped or inserted at a terminal. |
cash | Notes or coins, accepted by a machine or by a person. |
account | Charged to a standing arrangement and settled later, so the Payer is billed rather than paying at the moment of the Payment. |
Entities
Payment
One completed transfer of money for one charge: an amount, the method it was tendered with, and the moment it succeeded. A Payment records a transfer that settled — a declined card produces no Payment — and its amount never changes afterwards; money given back is a Refund.
Relationships
Refund— 1:n — owned — Money returned from thisPayment. There may be several partial ones, and none at all is the ordinary case.
Attributes
| Name | Type | Description |
|---|---|---|
amount | integer | What was taken, in the smallest currency unit. |
method | PaymentMethod | |
settledAt | timestamp | When the transfer succeeded. |
refundedTotal | integer | Derived: The sum of the amounts of this Payment's Refunds. |
Actions
take— actorPayer; preserves payment-amount-positive — Tender the amount and, on success, record thePayment.
Invariants
- payment-amount-positive — A
Payment's amount is greater than zero. - payment-method-fixed — A
Payment's method is fixed once it has settled; paying a different way is a newPayment.
Refund
Money returned from one Payment, in whole or in part. A Refund belongs to exactly one Payment and is always given back by the method that Payment used, so it carries no method of its own.
Attributes
| Name | Type | Description |
|---|---|---|
amount | integer | What was returned, in the smallest currency unit. |
issuedAt | timestamp |
Actions
issue— actorMerchant; preserves refund-within-payment, refund-after-settlement
Invariants
- refund-within-payment — The amounts of a
Payment'sRefunds never total more than thatPayment's amount. - refund-after-settlement — A
Refundis issued at or after itsPaymentsettled.
Relationships
Scenarios
A charge is settled by card
Actors: Payer, Payment
Steps
- A
Payeris asked for an amount and taps a card at the terminal. - The card is accepted, so a
Paymentrecords the amount, the methodcard, and the moment it settled. - Asked later to pay the same charge by cash instead, the system declines: the settled
Payment's method does not change.
Invariants touched
- payment-amount-positive — A
Payment's amount is greater than zero. - payment-method-fixed — A
Payment's method is fixed once it has settled; paying a different way is a newPayment.
Part of a charge is given back
Actors: Merchant, Payment, Refund
Steps
- A settled
Paymentof 500 exists, with nothing returned from it yet. - The
Merchantissues aRefundof 200 against it; thePayment's refunded total becomes 200. - A second
Refundof 400 is attempted; the system refuses it, because the two together would exceed thePayment.
Invariants touched
- refund-within-payment — The amounts of a
Payment'sRefunds never total more than thatPayment's amount. - refund-after-settlement — A
Refundis issued at or after itsPaymentsettled.