Stripe Models for Django.
dj-stripe implements all of the Stripe models, for Django. Set up your webhook and start receiving model updates. You will then have a copy of all the Stripe models available in Django models, no API traffic required!
The full documentation is available here: https://dj-stripe.readthedocs.io/
- Subscriptions
- Individual charges
- Stripe Sources
- Stripe v2 and v3 support
- Supports SCA regulations, Checkout Sessions, and Payment Intents
- Tested with Stripe API 2019-09-09 (see https://dj-stripe.readthedocs.io/en/latest/api_versions.html )
- Django >= 2.2
- Python >= 3.6
- Supports Stripe exclusively. See "Similar Libraries" below for other solutions.
- PostgreSQL engine (recommended): >= 9.4
- MySQL engine: MariaDB >= 10.2 or MySQL >= 5.7
Install dj-stripe:
pip install dj-stripe
Add djstripe
to your INSTALLED_APPS
:
INSTALLED_APPS =(
...
"djstripe",
...
)
Add to urls.py:
path("stripe/", include("djstripe.urls", namespace="djstripe")),
Tell Stripe about the webhook (Stripe webhook docs can be found
here) using the full URL of your
endpoint from the urls.py step above (e.g.
https://example.com/stripe/webhook
).
Add your Stripe keys and set the operating mode:
STRIPE_LIVE_PUBLIC_KEY = os.environ.get("STRIPE_LIVE_PUBLIC_KEY", "<your publishable key>")
STRIPE_LIVE_SECRET_KEY = os.environ.get("STRIPE_LIVE_SECRET_KEY", "<your secret key>")
STRIPE_TEST_PUBLIC_KEY = os.environ.get("STRIPE_TEST_PUBLIC_KEY", "<your publishable key>")
STRIPE_TEST_SECRET_KEY = os.environ.get("STRIPE_TEST_SECRET_KEY", "<your secret key>")
STRIPE_LIVE_MODE = False # Change to True in production
DJSTRIPE_WEBHOOK_SECRET = "whsec_xxx" # Get it from the section in the Stripe dashboard where you added the webhook endpoint
Add some payment plans via the Stripe.com dashboard.
Run the commands:
python manage.py migrate
python manage.py djstripe_init_customers
python manage.py djstripe_sync_plans_from_stripe
See https://dj-stripe.readthedocs.io/en/latest/stripe_elements_js.html for notes about usage of the Stripe Elements frontend JS library.
Assuming the tests are run against PostgreSQL:
createdb djstripe
pip install tox
tox
You can now become a sponsor to dj-stripe with GitHub Sponsors.
We've been bringing dj-stripe to the world for over 7 years and are excited to be able to start dedicating some real resources to the project.
Your sponsorship helps us keep a team of maintainers actively working to improve dj-stripe and ensure it stays up-to-date with the latest Stripe changes. If you're using dj-stripe in a commercial capacity and have the ability to start a sponsorship, we'd greatly appreciate the contribution.
All contributions through GitHub sponsors flow into our Open Collective, which holds our funds and keeps an open ledger on how donations are spent.