Skip to main content

Wallet token debit

What the code does​

WalletListener.handleOrderConfirmed calls deductToken, which debits the tenant's tokensPerOrder (default 100 tokens = ₹1.00) with allowNegative: true. The rate used is stored in the ledger row's metadata.tokensPerOrder. If deductions are paused for the wallet, nothing is charged and nothing is recorded.

When it fails​

Errors propagate, so the outbox retries up to 10 times and then marks the event DEAD. Low balance is not a failure: the fee posts and the balance goes below zero. A DEAD event therefore means a real problem (wallet missing, database error), and that order was not charged.

Idempotency​

The ledger key order-token-deduction:{orderId} is unique per tenant, so a retry or a second order.confirmed for the same order (for example ON_HOLD back to CONFIRMED) returns the existing row instead of charging again.

Rate timing​

The fee is read when the debit runs, not when the order was confirmed. A retry that runs after an admin changes tokensPerOrder pays the new rate.

What a token is​

A fixed fraction of the wallet currency (INR: 100 tokens = ₹1). It is a platform fee taken from a prepaid balance, not a Razorpay charge. Razorpay is used only for top-up intents and WhatsApp checkout. See Wallet.

Error handling.