Menu

How I made refunds automatic in a pay-per-use SMS code service
📰

How I made refunds automatic in a pay-per-use SMS code service

DEV Community: node·Simon·about 14 hours ago
#gcuVBKPQ
#devtonodejs#devto#dev#order#refund
Reading 0:00
15s threshold

I built Simuno , a service that sells temporary phone numbers for receiving SMS verification codes. This post is about the one part I found hardest: making the refund automatic, so a customer never has to ask for their money back.

The problem

Codes don't always arrive. The number may already be used on that app, or the app may refuse that number range. On most services like this you then argue with support. I wanted the opposite: if the number expires with no code, the full amount returns to the wallet by itself.

That sounds simple. It isn't, because three things can try to settle the same order at the same moment: a background worker that expires orders, a webhook from the supplier, and the user pressing cancel.

Decision 1: a ledger, not a balance

Every balance change is an entry in an append-only ledger. The cached balance on the user is updated in the same database transaction as the entry and the order status change.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.