Skip to main content

Checkout hospedado e cobrança recorrente para Django por uma interface única, tipada e orientada a recursos. O gateway Stripe está completo; integrações com Asaas e PagBank ainda não estão implementadas.

A biblioteca não cria models e não persiste checkouts, assinaturas, faturas ou eventos. A aplicação decide seu modelo de dados, transações, filas e regras de negócio.

Instalação

pip install 'django-checkouts[stripe]'

Adicione django_checkouts ao INSTALLED_APPS e configure uma variante:

INSTALLED_APPS = [
    ...,
    "django_checkouts",
]

CHECKOUT_VARIANTS = {
    "stripe": (
        "django_checkouts.gateways.stripe.StripeGateway",
        {
            "api_key": env("STRIPE_API_KEY"),
            "webhook_secret": env("STRIPE_WEBHOOK_SECRET"),
            "sandbox": DEBUG,
        },
    ),
}

Use python manage.py check para validar a configuração sem fazer chamadas externas.

Primeiro checkout

Valores monetários são inteiros na menor unidade da moeda: R$ 49,90 é 4990. Toda mutação exige uma chave de idempotência estável.

from django.shortcuts import redirect

from django_checkouts import Gateway, get_checkout_gateway
from django_checkouts.enums import PaymentMethod
from django_checkouts.types import CheckoutCreate, CheckoutItem, InlinePrice

client = get_checkout_gateway(Gateway.STRIPE)
result = client.checkouts.create(
    CheckoutCreate(
        items=(
            CheckoutItem(
                price=InlinePrice(name="Plano Pro", unit_amount=4990),
                quantity=1,
            ),
        ),
        success_url="https://example.com/obrigado/",
        cancel_url="https://example.com/carrinho/",
        payment_methods=(PaymentMethod.CARD,),
        reference_id="pedido-123",
    ),
    idempotency_key="pedido-123:checkout:v1",
)
return redirect(result.url)

O cliente publica cinco recursos: checkouts, subscriptions, invoices, webhooks e events. Resultados são dataclasses imutáveis e normalizados; o campo raw é somente leitura, oculto do repr e deve ser usado apenas para diagnóstico.

Webhooks e reconciliação

Sempre verifique os bytes originais do corpo:

event = client.webhooks.verify(request.body, request.headers)

Persista a deduplicação na sua aplicação com unicidade em (variant, event_id). Para recuperar eventos perdidos, percorra janelas semiabertas [occurred_since, occurred_before) e deduplique a sobreposição.

Documentação

A documentação completa cobre assinaturas, webhooks, reconciliação, erros, opções Stripe, autoria de gateways e migração da API anterior a 1.0 em docs/.

Desenvolvimento

uv sync --all-extras --all-groups
uv run pytest
uv run mypy django_checkouts
uvx ruff check .
uv run sphinx-build -W -b html docs docs/_build/html
uv build

Licença

BSD-3-Clause. Consulte LICENSE.

Download files

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

Source Distribution

django_checkouts-1.0.1.tar.gz (188.7 kB view details)

Uploaded Source

Built Distribution

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

django_checkouts-1.0.1-py3-none-any.whl (57.3 kB view details)

Uploaded Python 3

File details

Details for the file django_checkouts-1.0.1.tar.gz.

File metadata

  • Download URL: django_checkouts-1.0.1.tar.gz
  • Upload date:
  • Size: 188.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for django_checkouts-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ddbf1961f4de019e9f8277a5330760b8da9cf0dce7e3114b049c7705d3d9d6a5
MD5 3a2aa7b134165ac8986a87d845e4b69f
BLAKE2b-256 4fbf81f174304ec701fd59b3aca165a142aa4249cd2d6314632beaabbc8ecd3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_checkouts-1.0.1.tar.gz:

Publisher: release.yml on davisilvarafacho/django-checkouts

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

File details

Details for the file django_checkouts-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_checkouts-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3ab58fab905a794b1876dca44602b9e5ccce7bb68d8e1944dc3a49028cc797b8
MD5 39afba3b5fe239e219b72b466b6be818
BLAKE2b-256 06d8fe4a2b05f6cde9e2e2771ab40acecdfe0e8b687b0b6b3f2cb45f937c7640

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_checkouts-1.0.1-py3-none-any.whl:

Publisher: release.yml on davisilvarafacho/django-checkouts

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

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page