Prevent concurrent checkout requests for the same user from overdrawing their wallet balance.
Customers on slow mobile networks are tapping "Pay Now" twice and getting charged twice, even though we check their balance before deducting. Fix processPayment so concurrent calls for the same user cannot overdraw their balance.
processPayment at the same millisecond: both read user.balance before either one reaches user.balance -= amount across the await boundary.await points, not across them. Either reserve the funds synchronously before await (and refund in catch), or serialize calls per user.id with an in-memory promise lock/queue (always releasing in finally).Ready to run test suite
Edit the code above and press Cmd/Ctrl + Enter or click Run Tests.