Process a payment transaction for a customer order. This endpoint validates the order state, checks the reservation if provided, simulates the payment processing, and publishes events to Kafka for downstream services.
The payment service uses a simulated payment gateway for demonstration purposes. In production, this would integrate with real payment processors like Stripe, PayPal, or other payment gateways.
When a payment is submitted, the service follows this workflow:
Idempotency check - Verifies if a successful payment already exists for the order
Order validation - Confirms the order exists, belongs to the customer, and has the correct amount
Reservation validation - Re-validates the seat reservation if a reservationId is provided
Payment record creation - Creates a payment record with pending status
Payment simulation - Simulates the payment gateway processing
Event publishing - Publishes either payment-succeeded or payment-failed event to Kafka
This endpoint is idempotent. Multiple requests with the same orderId will return the existing successful payment if one exists, preventing duplicate charges.
Optional seat reservation identifier. If provided, the service will re-validate that the reservation is still active and belongs to the customer before processing payment.
The fulfillment service consumes this event to automatically generate tickets and send them to customers. This asynchronous workflow ensures payment confirmation is immediate while ticket generation happens in the background.
Always validate the order amount on the server side before calling this endpoint. Never trust client-supplied amounts without verification.
Implement retry logic for transient failures (5xx errors), but do not retry 4xx errors as they indicate client-side issues that won’t be resolved by retrying.
In a production environment, the IPaymentSimulatorService interface (source code: services/payment/src/Application/Ports/IPaymentSimulatorService.cs) would be replaced with actual payment gateway integrations such as:
Stripe - For credit card processing
PayPal - For PayPal and credit card processing
Square - For point-of-sale and online payments
Adyen - For global payment processing
The service architecture supports multiple payment gateways through the port/adapter pattern, making it easy to add or switch payment providers.