Payment System
Architecture
Section titled “Architecture”Checkout Service ↓Payment Gateway (trait) ├── Stripe Gateway ├── Airwallex Gateway └── Mock Gateway ↓Payment Intent → Client confirms → Server verifiesGateway trait
Section titled “Gateway trait”All payment gateways implement the PaymentGateway trait:
#[async_trait]pub trait PaymentGateway: Send + Sync { fn id(&self) -> &str; fn name(&self) -> &str; async fn create_payment(&self, request: CreatePaymentRequest) -> Result<PaymentSession>; async fn confirm_payment(&self, payment_id: &str) -> Result<Payment>; async fn capture_payment(&self, payment_id: &str, amount: Option<Decimal>) -> Result<Payment>; async fn refund_payment(&self, payment_id: &str, amount: Option<Decimal>, reason: &str) -> Result<Refund>; async fn get_payment(&self, payment_id: &str) -> Result<Payment>;}Payment flow
Section titled “Payment flow”POST /checkout/complete→create_payment()→ returnsclient_secret- Client-side: mount payment element with
client_secret - User enters card details and confirms
POST /checkout/confirm→get_payment()→ verify status- If succeeded → finalize order
Stripe
Section titled “Stripe”- Uses Stripe Payment Intents API
- Client-side: Stripe Elements
- Supports: cards, Apple Pay, Google Pay, 3D Secure
Airwallex
Section titled “Airwallex”- Uses Airwallex Payment Intents API
- Client-side: Airwallex Drop-in
- Supports: cards, WeChat Pay, Alipay, 3D Secure
- Amount in major currency units (not cents)
Mock gateway
Section titled “Mock gateway”For testing. Always returns success. Useful for development and CI.
Configuration
Section titled “Configuration”[payment]default_gateway = "stripe"
[payment.stripe]enabled = truesecret_key = "sk_..."publishable_key = "pk_..."
[payment.airwallex]enabled = trueclient_id = "..."api_key = "..."