Skip to main content

Lean Stripe-first payments toolkit for FastAPI with Tortoise ORM

Project description

Vanty Payments

Tests PyPI Python

Stripe-first payments toolkit for FastAPI with Tortoise ORM. Checkout, subscriptions, invoices, billing portal, webhooks, and full Stripe object sync in a single pip install.

Installation

pip install vanty-payments
# or
uv pip install vanty-payments

Quick start

from contextlib import asynccontextmanager

from fastapi import FastAPI

from vanty_payments import PaymentsKitSettings, mount_payments_router

settings = PaymentsKitSettings(
    database_url="sqlite://./vanty-payments.db",
    stripe_test_secret_key="sk_test_example",
    stripe_webhook_secret="whsec_example",
)

app = FastAPI()
kit = mount_payments_router(app, settings=settings)


@asynccontextmanager
async def lifespan(_: FastAPI):
    await kit.init_orm(generate_schemas=True)
    try:
        yield
    finally:
        await kit.close_orm()


app.router.lifespan_context = lifespan

Run with uvicorn main:app --reload and visit /docs for the interactive API explorer.

Features

  • Checkout sessions with Stripe-hosted and embedded flows
  • Subscription management with plan changes, cancellation, and reactivation
  • Invoice management with PDF links and payment status tracking
  • Billing portal sessions for customer self-service
  • Payment method management (cards, bank accounts)
  • Webhook ingestion with signature verification and idempotent processing
  • Manual sync to pull Stripe state into local models on demand
  • Full Stripe object parity covering customers, products, prices, coupons, promotion codes, discounts, charges, refunds, disputes, and more
  • Admin management endpoints for super-admin billing operations
  • Identity integration with optional vanty-auth or custom identity resolvers

Architecture

PaymentsKit is a composition root that wires all services. Access services directly:

kit = mount_payments_router(app, settings=settings)

# Direct service access
await kit.checkout_service.create_session(customer_id=cid, price_id=pid)
await kit.subscription_service.list_subscriptions(customer_id=cid)
await kit.sync_service.sync_customer(stripe_customer_id="cus_xxx")

Available services on PaymentsKit:

Service Purpose
customer_service Customer bootstrap and management
checkout_service Checkout session creation
subscription_service Subscription reads and management
invoice_service Invoice listing and retrieval
payment_method_service Payment method listing
portal_service Billing portal session creation
webhook_service Webhook signature verification and dispatch
sync_service Manual Stripe-to-local sync for all object types
admin_service Super-admin billing operations

Configuration

All settings are read from environment variables with the PAYMENTS_KIT_ prefix, or passed directly to PaymentsKitSettings.

Setting Default Description
database_url sqlite://./vanty-payments.db Tortoise ORM database URL
stripe_test_secret_key Stripe test mode secret key
stripe_live_secret_key Stripe live mode secret key
stripe_webhook_secret Webhook endpoint signing secret
stripe_mode test test or live
default_currency usd Default currency for new prices

Set via environment: PAYMENTS_KIT_STRIPE_TEST_SECRET_KEY=sk_test_... PAYMENTS_KIT_DATABASE_URL=postgres://...

API surface

Public routes (/payments)

Method Path Description
POST /customers/bootstrap Create or retrieve a Stripe customer
GET /catalog/products List available products
GET /catalog/prices List prices for a product
POST /checkout/sessions Create a checkout session
GET /subscriptions List subscriptions
GET /subscriptions/{id} Get subscription details
POST /subscriptions/{id}/cancel Cancel a subscription
POST /portal/sessions Create a billing portal session
GET /invoices List invoices
GET /invoices/{id} Get invoice details
GET /payment-methods List payment methods
POST /webhooks/stripe Stripe webhook endpoint
POST /sync Trigger manual sync

Admin routes (/admin/payments)

Super-admin endpoints for platform-wide billing management. Mount separately:

app.include_router(kit.admin_router, prefix="/admin/payments")

Host app identity integration

The package works standalone, but a host app can supply a request-level identity adapter through app.state.payments_identity_resolver:

async def resolve_identity(request: Request) -> IdentityContext:
    return IdentityContext(
        user_reference=request.state.user_id,
        organization_reference=request.state.org_id,
    )

app.state.payments_identity_resolver = resolve_identity

Routes then use those references automatically when request payloads omit them.

Project layout

src/vanty_payments/       Package source
docs/                     Documentation
examples/reference-api/   Reference FastAPI application
tests/                    pytest suite (unit + integration)

Development

git clone https://github.com/advantch/vanty-payments.git
cd vanty-payments
uv sync --dev

# Lint
uv run ruff check

# Test
uv run pytest -q

# Run reference API
cd examples/reference-api && uv run uvicorn main:app --reload

Use uv run pytest --no-cov tests/path/to/test.py for targeted debugging without the coverage gate.

Releasing

Releases are automated via GitHub Actions. To publish a new version:

  1. Update the version in pyproject.toml:

    version = "0.2.0"
    
  2. Commit and tag:

    git add pyproject.toml
    git commit -m "release: v0.2.0"
    git tag v0.2.0
    git push origin main --tags
    
  3. The release.yml workflow will automatically:

    • Build the package
    • Create a GitHub Release with auto-generated notes
    • Publish to PyPI via trusted publishing (OIDC)

PyPI trusted publishing setup

To enable automated publishing, configure a trusted publisher on PyPI:

  1. Go to pypi.org/manage/account/publishing
  2. Add a new pending publisher (or update an existing project):
    • PyPI project name: vanty-payments
    • Owner: advantch
    • Repository: vanty-payments
    • Workflow name: release.yml
    • Environment name: release

No API tokens are needed once trusted publishing is configured.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vanty_payments-0.1.0.tar.gz (83.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vanty_payments-0.1.0-py3-none-any.whl (48.6 kB view details)

Uploaded Python 3

File details

Details for the file vanty_payments-0.1.0.tar.gz.

File metadata

  • Download URL: vanty_payments-0.1.0.tar.gz
  • Upload date:
  • Size: 83.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for vanty_payments-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fe76803c4207d01550fec766e408d94aa525310a2bb14a927963ce49c0a0028c
MD5 cb978f493d5939c65bafa5fbc1febdf3
BLAKE2b-256 ad162a1dc2409e5cbc5d2b530d75e220c909a23eb475a85985a39f88e1615445

See more details on using hashes here.

Provenance

The following attestation bundles were made for vanty_payments-0.1.0.tar.gz:

Publisher: release.yml on advantch/vanty-payments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vanty_payments-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: vanty_payments-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 48.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for vanty_payments-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 24dcdaa34dc76ebb743a9c902f17db2ba8e8de83b07c498274667247b2dc3f40
MD5 087fc5dfc4a31f205be58c110277e712
BLAKE2b-256 cddda101db6b3034b3f6b01b2746f0c607d0ed7edf823ac1015c9882be9de9b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for vanty_payments-0.1.0-py3-none-any.whl:

Publisher: release.yml on advantch/vanty-payments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page