Once you issue cards to your users, sellers or AI agents, the same money is written down in two places: in the card program itself, and in your own ledger, where you track what each user may still spend and what the program costs you. The two drift apart in small, boring ways. A webhook arrives twice. A refund comes back a week later to a card you have already cancelled. A purchase in euros is charged in dollars. None of this is hard to handle, but it is much cheaper to handle it in the design than in a month-end spreadsheet.
This guide walks through how money moves in a Guara card program and one way to keep your ledger matched to it.
The money model: four kinds of movement
Everything starts from one prepaid partner balance, funded in USDT over TRC-20 or ERC-20. From there, money moves in only a few ways, and each one is a transaction type you will see in the API:
- Issue fee (
issue_fee) — taken from your balance when a card is issued. - Transfer (
transfer) — positive when you move money from the balance to a card withPOST /v1/partner/cards/{id}/transfer, negative when a card is cancelled and whatever is left on it goes back to the balance. - Purchase (
purchase) — spends the card's money.amount_centsis what the merchant charged; the product's purchase fee is not included there and comes separately infee_cents. - Refund (
refund) — returns the purchase amount. The purchase fee is not returned.
Two rules follow from this, and both are worth writing into your ledger logic on day one:
- A purchase costs the card
amount_cents + fee_cents. If you mirror each card's balance in your own database, subtract both, or your number will slowly run ahead of the real one. - A refund is smaller than the purchase it reverses, by exactly the fee. If you give a refund back to the end user in full, the difference comes out of your margin. That can be the right call, but make it a decision, not a surprise.
All amounts are integers in minor units — 1999 is $19.99 — and all times are ISO 8601 in UTC. Cards are USD cards that work in any currency: a purchase in another currency is converted and charged in USD. Book the dollar amount from the transaction, not the price the user saw on the merchant's page; only the first one ties out.
Statuses: what is final and what is not
A transaction is pending, posted or declined, and each deserves different treatment:
- posted is what you book. It is final money movement for that transaction.
- pending is not final yet. Show it to the user if you like, but do not treat it as settled in your accounts.
- declined moves no money, but keep it. Each declined purchase carries a
decline_reason—insufficient_funds,do_not_honor,expired_card,suspected_fraudormerchant_blocked. That is exactly what your support team needs when a user writes "my card did not work", and a run ofinsufficient_fundson one card usually means your top-up logic is behind.
A posted purchase can be refunded once. If the card was cancelled in the meantime, the refund goes to your partner balance instead of the card. So a refund can point at a card that is no longer in your active list. Give that case a place in your ledger: credit the partner side, then decide whether and how the user gets the money.
Map every card to a user when you issue it
Reconciliation is much easier if every card has an owner in your system from the first second. When you issue a card with POST /v1/partner/cards, you pass your own external_user_id and an optional label — for example the vendor, the team or the agent the card belongs to. Save the card id from the response next to your user id straight away, even if the card comes back as pending; the card.issued webhook tells you when it is ready.
Issuing and funding take an Idempotency-Key header, and this matters for the ledger as much as for the API. Create the key before the call and store it with the ledger row you are about to write. If your service crashes or the request times out, the retry uses the same key, and the API returns the first answer (with Idempotent-Replayed: true) instead of issuing a second card or funding the card twice. The same key with a different body is rejected with 422 idempotency_key_reused, and a retry while the first request is still running gets 409 idempotency_in_progress — wait and try again.
Two feeds: webhooks now, the API as the record
Most teams update the ledger from webhooks. The events that move money or change what a card can do are transaction.posted, transaction.declined, transaction.refunded, card.funded and card.cancelled. Every delivery is signed with X-GuaraPay-Signature: compute HMAC-SHA256 of <t>.<raw body> with your signing secret, compare in constant time and reject old timestamps. Verify before you write anything.
Webhooks are delivered at least once, not exactly once. If your endpoint is down, times out or answers with anything other than 2xx, the same event — same id, same body — is sent again after 30 seconds, 2 minutes, 10 minutes, 30 minutes, 2 hours and 6 hours. In practice that means:
- Store the event
idunder a unique constraint and write the ledger entry in the same database transaction. A second delivery hits the constraint, changes nothing and still answers 2xx. - Answer 2xx only after the write has committed. Anything else is treated as a failure and will come back.
- Do not assume order. A retried event can arrive after a newer one, so let each event carry its own effect instead of relying on what came before.
A handler along these lines is enough:
def on_event(evt): # after the signature check
with db.transaction():
if not db.insert_ignore("events", id=evt["id"]):
return 200 # seen before: nothing to do
apply_to_ledger(evt["type"], evt["data"])
return 200
After seven attempts — about nine hours of failures — a delivery is marked failed and stays in the endpoint's delivery log. That is why the webhook feed should not be your only source. The second feed is GET /v1/partner/transactions with a key that has the transactions:read scope. Lists return the newest first and take page and per_page (up to 100). A daily job is enough for most programs:
- Walk the pages from the newest transaction back until you pass the start of the window you are checking.
- For every transaction, look it up in your ledger by its id.
- Book what is missing, and flag anything whose status or amount differs from what you recorded.
- If the API answers 429, wait the number of seconds in
Retry-Afterand continue. The rate limit is shared by all keys of a partner, so run this job at a quiet hour rather than next to your issuing traffic.
Checking the totals
Matching transaction by transaction catches missing events. Matching totals catches mistakes in your own logic. Two checks are worth running regularly.
Per card. Money on a card is the transfers in, minus purchases (amount plus fee), plus refunds, minus the transfer back when the card is cancelled. For a cancelled card, that sum should be zero. If it is not, one of the four movements is missing or booked with the wrong sign.
For the partner balance. GET /v1/partner/balance returns the current balance. Over any period, its change should be explained by your USDT top-ups, minus issue fees, minus transfers to cards, plus transfers back from cancelled cards, plus refunds that landed on the balance because their card was already cancelled. A gap here usually points at a top-up you booked before the network confirmed it — money arrives on the balance only after confirmation.
Rehearse it in the sandbox
The sandbox has its own keys (gp_test_…), test money and a simulator, and every simulated event reaches your webhooks — which makes it a good place to test the ledger, not just the API calls. A useful run:
POST /v1/sandbox/simulate/topupto add test money to the balance.- Issue a card and transfer money to it.
POST /v1/sandbox/simulate/purchase, thenPOST /v1/sandbox/simulate/refundfor the same purchase. Check that the refund in your ledger is short of the purchase by the fee.POST /v1/sandbox/simulate/declineonce for each decline reason your support tooling shows.- Cancel the card and check that its sum is zero and the rest is back on the balance.
- In a test, feed the same event to your handler twice and check that the second call changes nothing.
If all six steps leave your ledger and the transactions list in agreement, the live program will start from a clean base. If you want to talk through a ledger design for your volume, request access — the team replies within one business day.