dj-stripe
dj-stripe seamlessly integrates Stripe payments with Django applications, providing a robust, database-backed representation of Stripe models. It handles webhooks, subscriptions, and customer management out-of-the-box. The current version is 2.10.3, and it maintains an active development pace with frequent minor and major releases.
Warnings
- breaking Upgrading to dj-stripe 2.10.x requires first upgrading to 2.9.x due to a migration reset. Additionally, many database fields have been removed from models and replaced by `stripe_data` property accessors, requiring code changes.
- breaking Deprecated settings (`DJSTRIPE_WEBHOOK_TOLERANCE`, `DJSTRIPE_WEBHOOK_SECRET`), the `Order` model, `Customer.add_card` method, and direct support for `Source` and `SourceTransaction` models have been removed. The `Source` models are now under `djstripe.models.payment_methods` and are slated for full removal.
- breaking Direct upgrade paths for older dj-stripe versions are restricted. For instance, upgrading to 2.8.0 is not possible from versions older than 2.5.0, and upgrading to 2.7.0 is not possible from versions older than 2.4.0.
- gotcha dj-stripe has a strict `requires_python` range. Starting with 2.8.0, Python 3.7 is no longer supported. The latest versions (2.10.x) require Python >=3.11 and support newer Django versions like 4.1 and 4.2.
- gotcha Webhook endpoint configuration has changed significantly. Starting from 2.7.0, webhook endpoints are primarily configured via the Django administration interface, replacing older methods like `DJSTRIPE_WEBHOOK_SECRET` (which was removed in 2.9.0).
Install
-
pip install dj-stripe
Imports
- Customer
from djstripe.models import Customer
- Subscription
from djstripe.models import Subscription
- WebhookMessage
from djstripe.models import WebhookMessage
- Source
from djstripe.models import Source
from djstripe.models.payment_methods import Source
Quickstart
import os
# settings.py
INSTALLED_APPS = [
# ... other apps
'djstripe',
# ...
]
STRIPE_LIVE_MODE = False # Set to True for production
STRIPE_TEST_SECRET_KEY = os.environ.get('STRIPE_TEST_SECRET_KEY', 'sk_test_YOUR_TEST_SECRET_KEY')
STRIPE_LIVE_SECRET_KEY = os.environ.get('STRIPE_LIVE_SECRET_KEY', 'sk_live_YOUR_LIVE_SECRET_KEY')
STRIPE_TEST_PUBLIC_KEY = os.environ.get('STRIPE_TEST_PUBLIC_KEY', 'pk_test_YOUR_TEST_PUBLIC_KEY')
STRIPE_LIVE_PUBLIC_KEY = os.environ.get('STRIPE_LIVE_PUBLIC_KEY', 'pk_live_YOUR_LIVE_PUBLIC_KEY')
# urls.py
from django.urls import path, include
urlpatterns = [
# ... other paths
path('djstripe/', include('djstripe.urls', namespace="djstripe")),
# ...
]
# Run migrations
# python manage.py migrate