Use this skill when the user wants to replay a day of gift card activity (loads and spends from the tills) against starting card balances and a per-card limit, producing end-of-day balances per card and a list of declined events. Matches requests like 'apply today's gift card events', 'reconcile gift card balances', or 'which gift card loads/spends were declined', with input.json holding limitCents, cards and events. Not for general payments, refunds, or card issuing.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Gift Card Ledger?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/gabrielmoreira-gift-card-ledger-e08903a8)
---
name: gift-card-ledger
description: "Use this skill when the user wants to replay a day of gift card activity (loads and spends from the tills) against starting card balances and a per-card limit, producing end-of-day balances per card and a list of declined events. Matches requests like 'apply today's gift card events', 'reconcile gift card balances', or 'which gift card loads/spends were declined', with input.json holding limitCents, cards and events. Not for general payments, refunds, or card issuing."
---
# Gift card ledger replay
Replay `events` in order against `cards`, then write `card-balances.csv` and `declined.json` beside `input.json`. You cannot run code; do the arithmetic yourself, carefully, in integer cents.
## Inputs
Read `input.json` in the working folder:
- `limitCents`: max balance a card may hold (integer cents).
- `cards`: array of `{card, balanceCents}`; every issued card, start-of-day balance.
- `events`: array of `{seq, card, type, cents}` in till order. `card` is an 8-digit string, `type` is `"load"` or `"spend"`, `cents` is a positive integer.
If `input.json` is missing or unparseable, stop and tell the user. Do not invent data.
## Steps
1. Build a working table: card string -> balance in cents, from `cards`. Treat card numbers as strings (keep leading zeros). Do not add cards.
2. Walk `events` strictly in listed order (never sort by `seq`; seq is only an identifier). For each event, with `b` = current balance of that card:
- Card not in the table: DECLINE, no change.
- `load`: if `b + cents <= limitCents` then `b = b + cents`; else DECLINE (add nothing; do not top up to limit). Landing exactly on the limit is accepted.
- `spend`: if `cents <= b` then `b = b - cents`; else DECLINE (take nothing; do not zero the card). Spending exactly `b` is accepted, leaving 0.
- Any other `type`, or a non-positive / non-integer `cents`: DECLINE, no change, and mention it in your reply.
- Append `seq` to the declined list when declined. Later events see updated balances, and declined events never change anything.
- Duplicate card entries in `cards`: use the first, mention it in the reply.
3. Write `card-balances.csv`:
- First line `card,balance`, then one row per entry in `cards`, sorted by card number ascending (all 8 digits, so string order equals numeric order; compare digit by digit).
- balance = cents / 100 with exactly two decimals, no currency sign, no thousands separators. Formula: dollars = floor(c/100), remainder = c mod 100 padded to 2 digits, written `dollars.remainder`. Examples: 0 -> `0.00`, 5 -> `0.05`, 12500 -> `125.00`, 50000 -> `500.00`.
- Card is written as given (8 digits, leading zeros kept), newline-terminated lines, no quotes.
4. Write `declined.json`: a JSON array of declined `seq` numbers (numbers, not strings) in the order applied, e.g. `[3,7,12]`; `[]` if none.
5. Re-read both files and check: row count equals `cards` length, sorted, two decimals everywhere, no balance exceeds `limitCents` or is negative (a start balance already above the limit is left as is unless changed by events).
## Worked example
limitCents 50000; card `00000001` starts 48000.
- seq 1 load 2000 -> 50000, accepted (exactly the limit).
- seq 2 load 1 -> 50001 > limit, declined.
- seq 3 spend 60000 -> exceeds balance, declined.
- seq 4 load 100 on `99999999` (not in cards) -> declined.
`card-balances.csv`:
```
card,balance
00000001,500.00
```
`declined.json`: `[2,3,4]`
## Limits
No commands or scripts are needed or provided; all work is reading and writing the two output files. Overwrite existing outputs of the same name.