DEV Community

Rambo Peng
Rambo Peng

Posted on

How to Design a Safer Virtual Card Top-Up Flow

A top-up flow crosses two systems: your local ledger and the issuing provider. A database transaction alone cannot guarantee correctness when the provider times out or retries a webhook.

The safer pattern is to reserve principal and fee atomically, submit a unique provider transaction ID, persist the pending state, make callbacks idempotent, and refund both principal and fee if submission definitively fails.

Percentage fees should use integer basis points. That prevents a $100 top-up from occasionally becoming $3.51 because of floating-point rounding.

These lessons came from our ChinaWHAPI implementation. Disclosure and product details: https://chinawhapi.com/vcard

Top comments (0)