# Payments Integration taste of a backend engineer who never wants to double-charge a customer
- Start with the provider's hosted checkout or payment element instead of building card forms yourself; it keeps you out of most PCI scope. Confidence: 0.90
- Never let raw card numbers touch your servers or logs; work only with provider tokens, payment method ids and customer ids. Confidence: 1.00
- Store money as integer minor units (cents) plus an ISO currency code; never use floats for amounts. Confidence: 1.00
- Send an idempotency key on every create or capture request, derived from your own order or attempt id, so retries cannot charge twice. Confidence: 0.95
- Treat signed webhooks as the source of truth for payment state; the browser redirect after checkout is only a hint to show a pending screen. Confidence: 0.95
- Verify every webhook signature against the raw request body before parsing it, and reject events with stale timestamps. Confidence: 1.00
- Make webhook handlers idempotent by recording processed event ids, because providers deliver at least once and out of order. Confidence: 0.90
- Acknowledge webhooks quickly with a 2xx and push the real work onto a background job queue. Confidence: 0.85
- Model orders and payments as explicit state machines (pending, requires_action, succeeded, failed, refunded) and reject impossible transitions. Confidence: 0.85
- Keep your own payments table that maps provider ids to internal order and customer ids; never rely on searching the provider by metadata. Confidence: 0.85
- Put your internal order id in provider metadata too, so support can jump from a dashboard charge to your admin page. Confidence: 0.75
- Calculate prices, discounts and tax on the server from your own catalog; never trust an amount sent by the client. Confidence: 1.00
- Handle 3D Secure and other customer actions with the provider's SDK flow instead of assuming every payment succeeds immediately. Confidence: 0.85
- Use the provider's test mode, test cards and test clocks in CI to cover declines, disputes and subscription renewals. Confidence: 0.80
- Let the provider own subscription billing cycles, proration and dunning unless you have a very strong reason to build it. Confidence: 0.80
- Grant and revoke access from subscription status events, and give a short grace period on failed renewals before locking accounts. Confidence: 0.75
- Run a daily reconciliation job that compares provider balance transactions and payouts with your ledger and alerts on any mismatch. Confidence: 0.85
- Issue refunds through one internal service that records who refunded, why and how much, with partial refunds as first-class records. Confidence: 0.80
- Keep API keys in a secrets manager, use restricted keys per service and rotate them on a schedule. Confidence: 0.90
- Log provider request ids and event ids on every call so disputes and support tickets can be traced end to end. Confidence: 0.80
- Show clear, localized error messages for declines without exposing raw decline codes that help card testers. Confidence: 0.70
- Rate-limit checkout and payment-method endpoints and add bot protection to stop card-testing attacks. Confidence: 0.85
- Wrap the provider behind a thin internal interface, but do not pretend multiple providers are interchangeable until you actually run two. Confidence: 0.65
Comments & Questions (0)
No comments yet
Be the first to comment!