Skip to content
All Projects
Backend

Multi-Gateway Payment Integration

Built a unified payment abstraction for M-Pesa, Stripe, and PayPal that reduced processing latency by 60% while ensuring idempotent transactions and automatic recovery from failures.

Overview

A unified payment gateway integration using the adapter pattern. Supports M-Pesa, Stripe, and PayPal with idempotent processing, automatic retries, and dead-letter queues for failed transactions.

Tech Stack

PythonFastAPIRabbitMQPostgreSQLRedisDocker

Architecture

Client
Web + Mobile
Payment Service
FastAPI unified API
Gateway Adapters
M-Pesa, Stripe, PayPal
RabbitMQ
Async task queue
PostgreSQL
Transaction records
Dead Letter Queue
Failed transactions

Topics

python
fastapi
payments
mpesa
stripe
paypal

Engineering Challenges

Integrating three payment gateways with different APIs, error handling, and webhook patterns while maintaining idempotency and handling transient failures.

Lessons Learned

The adapter pattern is the right choice for multiple integrations. Idempotency is not optional for payment systems. Dead-letter queues are essential for permanent failure handling.

Related Case Studies