Taking a card payment at the counter
Charging a card


An unpaid invoice carries a card form next to the cash form: amount, card
number, expiry, security code. Press Charge card and two things happen in
that order:
1. The provider is asked for the money. If the bank refuses, the reason appears
beside the button — *The card was declined*, *The card has expired*, *The card
does not have enough funds* — and nothing is recorded. The ledger can
never show money that did not arrive.
2. When the charge settles, the payment lands on the invoice the same way a cash
payment does: partial or paid, with the reference `card •••• 4242`.
A card charge cannot be more than the balance owed. Split payments are normal:
charge $40 today, the remaining $29 when the surgery finishes.
What we keep, and what we do not
The typed card number goes over an encrypted connection to the provider and
never touches our database. What is stored is the provider's payment
reference (`pi_…`) on the payment row. That reference is what makes a refund go
back to the same card, and what lets you settle an argument with an owner about
whether their card was charged.
Refunding to a card
Card refunds do not live in the accounting form — money back to a card has to go
back through the provider that holds the charge, so the invoice carries its own
Refund to card button. Leave the amount blank to return everything paid.
- If the client paid in instalments, the refund is split across the card charges
that still have room, most recent first, and each one is booked against the
charge it reverses.
- A card payment recorded from a paper terminal (no provider reference) cannot be
refunded through us; the form says so and you refund it as cash or transfer.
- A partial refund leaves the invoice partial, never silently settled.
Which processor, and who holds the money
AxonVet talks to Stripe through one file (`lib/card-payments.ts`), the only place
card money moves. With no key configured the same code path runs against a
deterministic fake driver, so the ledger behaviour is testable offline; with a
key configured it is Stripe live or test mode. Test card numbers behave as in
Stripe's own tables: `4242 4242 4242 4242` settles, `4000 0000 0000 0002` is
declined, `4000 0000 0000 0069` has expired.
Two decisions are still open and deliberately not buried in the code: whether a
clinic's clients pay through AxonVet's Stripe account or the clinic's own (Stripe
Connect), and moving card entry into an embedded frame so the card fields never
reach our server at all. Until the second lands, a typed card number passes
through our server over TLS — which is a wider PCI reporting obligation than an
embedded field.