Skip to content

SMESCH1/fastapi-payments-api

Repository files navigation

FastAPI Payments API

FastAPI Python Tests CI Deploy License

Minimal but production-shaped REST API for online payments. Built to demonstrate clean software engineering practices: explicit state machines, unit + integration tests, CI/CD, and automated deploys.

🇬🇧 English below · 🇪🇸 Versión en español primero.

🌐 Live demo: https://testing-examen-soft-eng.onrender.com/docs (Swagger UI)


🇪🇸 Qué es esto

Una API REST mínima para procesar pagos en línea, con dos métodos: PayPal y tarjeta de crédito. Cada uno tiene su propio set de reglas de negocio y validaciones. El objetivo del proyecto no es el dominio (pagos) sino mostrar buenas prácticas de software engineering:

  • State machine explícita para los estados del pago (REGISTRADO → PAGADO / FALLIDO → REGISTRADO)
  • Tests unitarios e integración con unittest (sin dependencias extra)
  • CI con GitHub Actions — corre tests en cada PR
  • CD a Render automático al merge en production
  • ✅ Documentación API auto-generada (Swagger + ReDoc)
  • ✅ Trade-offs documentados (almacenamiento, concurrencia, validaciones)

Stack

FastAPI · Pydantic · unittest · GitHub Actions · Render · Python 3.11

Reglas de negocio

  • Tarjeta de crédito: monto < $10.000 y máximo 1 pago en REGISTRADO a la vez.
  • PayPal: monto < $5.000.

Cómo correr local

pip install -r requirements.txt
fastapi dev main.py
# Swagger: http://127.0.0.1:8000/docs

Cómo correr los tests

# Opción 1: script
python3 test_local.py

# Opción 2: unittest directo
python3 -m unittest test_main -v

Endpoints

Método Path Acción
GET /payments Listar todos los pagos
POST /payments/{id} Registrar un nuevo pago
POST /payments/{id}/update Actualizar (solo si está REGISTRADO)
POST /payments/{id}/pay Procesar pago (corre validaciones)
POST /payments/{id}/revert Revertir pago FALLIDO a REGISTRADO

Autor

Sebastián Mesch Henriques@SMESCH1


🇬🇧 What this is

A minimal REST API for online payments supporting two methods: PayPal and credit card. Each has its own business rules and validations. The goal is not the payments domain itself — it's to showcase clean software engineering practices:

  • Explicit state machine for payment status (REGISTRADO → PAGADO / FALLIDO → REGISTRADO)
  • Unit + integration tests with stdlib unittest
  • CI via GitHub Actions — runs tests on every PR
  • CD to Render on merge to production
  • ✅ Auto-generated API docs (Swagger + ReDoc)
  • ✅ Documented trade-offs (storage, concurrency, validations)

Stack

FastAPI · Pydantic · unittest · GitHub Actions · Render · Python 3.11

Business rules

  • Credit card: amount < $10.000 and a maximum of 1 payment in REGISTRADO status at any time.
  • PayPal: amount < $5.000.

State machine

┌─────────────┐    process     ┌──────────┐
│ REGISTRADO  │ ──────────────►│  PAGADO  │
└─────────────┘                └──────────┘
       ▲                              
       │ revert                       
       │                              
       │    ┌─────────────┐           
       └────│  FALLIDO    │ ◄─── validation failed
            └─────────────┘

Local dev

pip install -r requirements.txt
fastapi dev main.py
# Swagger: http://127.0.0.1:8000/docs

Tests

python3 -m unittest test_main -v

Production

Author

Sebastián Mesch Henriques@SMESCH1

License

MIT — see LICENSE.

About

REST payments API with FastAPI, unit/integration tests, CI/CD to Render

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors