PayWave is a RESTful API designed to process payments, offering complete payment handling functionality with support for multiple payment gateways. It integrates Stripe and PayPal to provide a robust multi-gateway solution, ensuring reliability through a fallback mechanism and optimized performance via Redis caching and event-driven architecture. The system is containerized with Docker and orchestrated using Kubernetes for scalability and resilience under heavy load.
- Complete Payment Handling: Full support for processing, updating, and managing payments through multiple payment gateways.
- Multi-Gateway Support: Integration with Stripe and PayPal, ensuring flexibility and reliability in payment processing.
- Scalability and Resilience: Built using containerized architecture (Docker and Kubernetes) to guarantee scalability and high availability, even under heavy load.
- Optimized Performance: Utilizes Redis to cache frequent payment data, reducing latency and improving system responsiveness.
- Fallback Mechanism: A robust fallback system ensures that if one payment gateway fails, the transaction is automatically retried with another gateway.
- PHP (Symfony Framework): The main platform for implementing the API, ensuring flexibility and ease of integration with multiple services.
- Stripe and PayPal: Integrated as the primary payment gateways for processing transactions.
- Redis: In-memory caching system used to reduce load on payment gateways, improving response times and overall performance.
- RabbitMQ: Message broker used to implement event-driven architecture, ensuring asynchronous and resilient payment processing.
- Docker: Containerizes the application, ensuring consistency across development, testing, and production environments.
- Kubernetes: Manages container orchestration, scaling, and high availability of the payment API.
- JWT (JSON Web Tokens): Used for user authentication and authorization to secure sensitive operations like payment modifications.
PayWave's architecture is designed with scalability and fault tolerance in mind, ensuring that payments are processed efficiently across multiple gateways. The system integrates a fallback mechanism to automatically retry failed transactions using alternate gateways.
- Payment Management: Handles the processing, updating, and management of payments.
- Gateway Integration: Interfaces with Stripe and PayPal to process transactions.
- Retry and Fallback Logic: Implements automatic retries and gateway fallback in case of failures to ensure payment continuity.
- The client sends a
POST /paymentsrequest with payment details. - The request is received by the
PaymentController, triggering theProcessPaymentuse case. - The payment is processed by the primary gateway (Stripe or PayPal).
- If the payment fails, the fallback logic switches to the alternate gateway for processing.
- Redis updates the cache with the payment status to optimize subsequent queries.
- The client sends a
GET /payments/:idrequest to check the payment status. - The
PaymentControllerretrieves the payment status from the Redis cache. - If the data is not cached, the status is fetched from the database and then cached for future requests.
- The client sends a
PUT /payments/:idrequest to update payment information. - The
PaymentControllertriggers theUpdatePaymentuse case to modify the payment details. - The updated information is sent to the selected gateway, and the Redis cache is invalidated.
- If a payment fails, the system initiates a retry mechanism with exponential backoff.
- After several retries, the system falls back to the alternate payment gateway.
- If all retries fail, the payment is marked as failed, and the status is updated in both the cache and the database.
PayWave is containerized using Docker, facilitating easy development, deployment, and scaling across environments. Docker Compose is used for local development, orchestrating the API and its dependencies like Redis and RabbitMQ.
In production, Kubernetes manages PayWave’s API, allowing for automatic scaling and ensuring high availability of the services. Kubernetes configurations include:
- Deployment: Defines the number of API replicas and their distribution within the cluster.
- Service: Provides a stable interface to access the API containers.
- Ingress: Manages external access to the API and routes requests to the appropriate services.
git clone https://github.com/yourusername/paywave.git
cd paywaveCreate a .env file based on the provided env.example file:
cp .env.example .envEdit the .env file and add your own configurations for Redis, RabbitMQ, and Payment Gateway credentials:
# Example .env configuration
REDIS_ADDRESS=your_localhost
RABBITMQ_URL=amqp:your_localhost
STRIPE_API_KEY=your-stripe-api-key
PAYPAL_CLIENT_ID=your-paypal-client-id
PAYPAL_CLIENT_SECRET=your-paypal-client-secretInstall dependencies:
composer installStart the services (Redis, RabbitMQ, etc.) using Docker Compose:
docker-compose up --buildRun the application:
php bin/console server:run