Skip to main content

Payment Service Deployment

Docker Deployment

Build Image

cd shared/payment
docker build -t payment:latest .

Run Container

docker run -d \
--name payment \
-p 8001:8001 \
-e DATABASE_URL=postgresql://user:pass@postgres:5432/payment_rs \
-e PAYFAST_MERCHANT_ID=your-id \
-e PAYFAST_MERCHANT_KEY=your-key \
payment:latest

Docker Compose

The service is included in infra/compose.yml:

payment:
build: ./shared/payment
ports:
- "8001:8001"
environment:
- DATABASE_URL=postgresql://user:pass@postgres:5432/payment_rs
depends_on:
- postgres

Production Deployment

Build Release Binary

cd shared/payment
cargo build --release

Run Migrations

DATABASE_URL=postgresql://user:pass@postgres:5432/payment_rs \
sqlx migrate run

Run Binary

./target/release/payment

Systemd Service

Create /etc/systemd/system/payment.service:

[Unit]
Description=Payment Service
After=network.target postgresql.service

[Service]
Type=simple
User=payment
WorkingDirectory=/opt/payment
ExecStart=/opt/payment/payment
Restart=always
RestartSec=5
Environment="DATABASE_URL=postgresql://user:pass@localhost:5432/payment_rs"

[Install]
WantedBy=multi-user.target

Health Checks

  • GET /health - Basic health check
  • GET /health/detailed - Detailed health including database

Monitoring

Metrics

Prometheus metrics available at /metrics.

Tracing

OpenTelemetry tracing configured for distributed tracing.

Security Considerations

  • PCI Compliance - Ensure PCI DSS compliance for card data
  • Encryption - Encrypt sensitive data at rest and in transit
  • Access Control - Restrict access to payment endpoints
  • Audit Logging - Log all payment operations for compliance

Database Backup

Regular backups are critical for payment data:

pg_dump -h localhost -U user payment_rs > backup.sql

Scaling

The service can be horizontally scaled. Ensure:

  • All instances connect to the same PostgreSQL database
  • Webhook URLs are accessible from provider networks
  • Database connection pooling is configured