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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddbf1961f4de019e9f8277a5330760b8da9cf0dce7e3114b049c7705d3d9d6a5
|
|
| MD5 |
3a2aa7b134165ac8986a87d845e4b69f
|
|
| BLAKE2b-256 |
4fbf81f174304ec701fd59b3aca165a142aa4249cd2d6314632beaabbc8ecd3f
|
Provenance
The following attestation bundles were made for django_checkouts-1.0.1.tar.gz:
Publisher:
release.yml on davisilvarafacho/django-checkouts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_checkouts-1.0.1.tar.gz -
Subject digest:
ddbf1961f4de019e9f8277a5330760b8da9cf0dce7e3114b049c7705d3d9d6a5 - Sigstore transparency entry: 2731737550
- Sigstore integration time:
-
Permalink:
davisilvarafacho/django-checkouts@4721a7648da15b1efe7212181e2e2adb1cbb0a5b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/davisilvarafacho
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4721a7648da15b1efe7212181e2e2adb1cbb0a5b -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_checkouts-1.0.1-py3-none-any.whl.
File metadata
- Download URL: django_checkouts-1.0.1-py3-none-any.whl
- Upload date:
- Size: 57.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ab58fab905a794b1876dca44602b9e5ccce7bb68d8e1944dc3a49028cc797b8
|
|
| MD5 |
39afba3b5fe239e219b72b466b6be818
|
|
| BLAKE2b-256 |
06d8fe4a2b05f6cde9e2e2771ab40acecdfe0e8b687b0b6b3f2cb45f937c7640
|
Provenance
The following attestation bundles were made for django_checkouts-1.0.1-py3-none-any.whl:
Publisher:
release.yml on davisilvarafacho/django-checkouts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_checkouts-1.0.1-py3-none-any.whl -
Subject digest:
3ab58fab905a794b1876dca44602b9e5ccce7bb68d8e1944dc3a49028cc797b8 - Sigstore transparency entry: 2731738185
- Sigstore integration time:
-
Permalink:
davisilvarafacho/django-checkouts@4721a7648da15b1efe7212181e2e2adb1cbb0a5b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/davisilvarafacho
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4721a7648da15b1efe7212181e2e2adb1cbb0a5b -
Trigger Event:
push
-
Statement type: