FastAPI framework adapter for getpaid-core payment processing ecosystem.
- Standardized API: Unified REST endpoints for creating and managing payments across different backends.
- OpenAPI Integration: Automatically generated interactive documentation for all payment endpoints.
- Dependency Injection: Seamlessly integrates with FastAPI's dependency injection system.
- Backend Agnostic: Supports all
getpaidprocessors (PayU, Paynow, Bitpay, Przelewy24, etc.). - Async First: Fully asynchronous implementation for high performance.
- Pluggable Persistence: Support for SQLAlchemy (built-in) or custom repositories.
- Semantic Updates: Reliable payment status management via explicit payment events and provider metadata.
pip install fastapi-getpaidTo use with SQLAlchemy:
pip install "fastapi-getpaid[sqlalchemy]"Define your backends and general settings using GetpaidConfig:
from fastapi_getpaid import GetpaidConfig
config = GetpaidConfig(
default_backend="dummy",
success_url="https://example.com/payment/success",
failure_url="https://example.com/payment/failure",
backends={
"dummy": {
"module": "getpaid_core.backends.dummy",
"gateway": "https://example.com/paywall",
},
# Add real backends here
}
)The wrapper needs to know how to resolve your domain's order IDs:
from fastapi_getpaid import OrderResolver
class MyOrderResolver(OrderResolver):
async def resolve(self, order_id: str):
# Fetch order from your database
return await my_db.get_order(order_id)from fastapi import FastAPI
from fastapi_getpaid import create_payment_router
from fastapi_getpaid.contrib.sqlalchemy.repository import SQLAlchemyPaymentRepository
app = FastAPI()
# Setup repository (SQLAlchemy example)
repository = SQLAlchemyPaymentRepository(session_factory)
# Create and include the router
payment_router = create_payment_router(
config=config,
repository=repository,
order_resolver=MyOrderResolver(),
)
app.include_router(payment_router, prefix="/api/payments", tags=["payments"])Once mounted, fastapi-getpaid automatically adds documented endpoints to your FastAPI app. Visit /docs or /redoc to see the full API specification, including:
POST /api/payments/: Initiate a new payment.GET /api/payments/{payment_id}: Check payment status.POST /api/payments/callback/{payment_id}: Standardized callback handler.
A comprehensive example showing multiple backends (Dummy, PayU, Paynow), SQLAlchemy integration, and a fake payment gateway simulator is available in the example/ directory.
To run it:
cd example
pip install -r requirements.txt
uvicorn app:app --reloadfastapi-getpaid is part of the getpaid ecosystem:
- Core: getpaid-core
- Other Wrappers: django-getpaid, litestar-getpaid
- Supported Processors:
This project is licensed under the MIT License - see the LICENSE file for details.