Designing Payment and Billing Systems

1. Designing Payment Gateway Integration

ElementDetail
ProvidersStripe, Adyen, Braintree, Checkout.com
Hosted fields / ElementsAvoid touching card data (PCI scope)
3DS / SCAEU mandatory
Idempotency-KeyRequired header
Webhook for resultsAsync outcome

2. Designing Subscription Management

ElementDetail
Plan / price catalogTiered pricing
Lifecycletrial → active → past_due → canceled
ProrationMid-cycle upgrades
TrialFree or paid trial
Pause / cancelSelf-serve

3. Designing Recurring Billing

AspectDetail
CycleMonthly / annual / custom
Anchor dateSubscription start determines cycle
DunningRetry failed payments on schedule
Smart retriesProvider intelligence (Stripe)
Card update notificationsAccount Updater service

4. Designing Invoice Generation

ElementDetail
NumberingMonotonic, gap-free per jurisdiction
Line itemsPlan + usage + adjustments
TaxAvalara, Stripe Tax, TaxJar
PDFGenerated; stored in object store
LocalizationCurrency, language

5. Designing Payment Retry Strategy

StrategyDetail
ScheduleDay 1, 3, 5, 7
Smart retrySkip if soft decline expected to recur
Email remindersUpdate payment method link
Grace periodService active during dunning
Hard declineCancel subscription

6. Designing Payment Webhook Handling

PracticeDetail
Verify signatureStripe-Signature etc.
Return 2xx fastProcess async
IdempotentDedupe by event id
Replay safeProvider retries delivery
Order independenceEvents may arrive out-of-order

7. Designing Refund Processing

AspectDetail
Full / partialTrack type
Reason codeFor analytics + compliance
Reverse fulfillmentRevoke service / inventory
Approval flowThreshold-based admin approval
Disputes / chargebacksEvidence submission flow

8. Designing Usage-Based Billing

ElementDetail
Metering eventsIdempotent capture
AggregationDaily rollup per metric
Tiered / volume / graduatedPricing models
ToolsStripe Metered, Metronome, Orb
Real-time metersFor UI display

9. Designing Payment Security

PracticeDetail
PCI scope reductionTokenization, hosted fields
No PAN storageToken only
3DS for high-riskLiability shift
Velocity checksCard / IP / email
CVV not storedEven hashed

10. Designing Multi-Currency Support

ElementDetail
Store currencyAlways with amount
Minor unitsInteger cents; avoid float
FX rateLocked at transaction time
Settlement currencyProvider converts
Display vs chargeMay differ

11. Designing Payment Reconciliation

StepDetail
Daily payout reportFrom provider
Match transactionsInternal vs gateway
Unreconciled queueInvestigate
Fees breakdownPer transaction
Accounting exportQuickBooks / NetSuite

12. Designing Fraud Detection

ToolDetail
Stripe Radar / Adyen RevenueProtectBuilt-in ML
Sift / Signifyd / ForterSpecialized
Velocity rulesSame card N times / hour
Device fingerprintDetect botnets
3DS step-upFor risky transactions
Allow / block listsPer email / BIN / country