Dev.to WebDev 🛠 Dev 👁 0 📖 1 min read

3 Payment Gateway Mistakes I Avoided Building a Gift Delivery App

I recently shipped Giftino, a send-a-gift app for Lahore, Pakistan. Every order is prepaid (card or Raast), because cash on delivery does not work when the person receiving the gift is not the person who ordered it. Tha

I recently shipped Giftino, a send-a-gift app for Lahore, Pakistan. Every order is prepaid (card or Raast), because cash on delivery does not work when the person receiving the gift is not the person who ordered it.

That made the payment flow the most important part of the backend. Here are three mistakes I made sure to avoid.

1. Trusting the client to say "payment succeeded"

The app returns from the gateway's hosted checkout to a success screen. It is tempting to mark the order paid right there. Don't. The redirect can be faked, dropped, or replayed.

What I do instead: the order stays pending_payment until the server receives and verifies the gateway's webhook (signature check plus an amount and currency match). The success screen just polls the order status.

2. Non-idempotent order creation

On slow mobile networks users tap "Pay" twice. Without protection you get two orders and possibly two charges.

What I do instead: the client sends an idempotency key with checkout. The server returns the existing pending order for a repeated key instead of creating a new one. Webhook handling is idempotent too, so a repeated "paid" event is a no-op.

3. No expiry for abandoned payments

People open checkout and walk away. If pending orders live forever, coupon codes and limited stock get locked up.

What I do instead: pending orders expire after a fixed window via a scheduled job, which releases coupons and stock. If a late webhook arrives for an expired order, it is flagged for manual review instead of silently ignored.

Wrap-up

None of this is novel, but it is easy to skip when you are rushing to launch. If you are building commerce in Pakistan or anywhere with mixed payment rails, get these three right before anything else.

Giftino is live on the web and Android if you want to see the flow end to end.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.