Skip to content

Files

Latest commit

3a0abbe · Jul 19, 2024

History

History
37 lines (24 loc) · 1.75 KB

setup-dj-stripe.md

File metadata and controls

37 lines (24 loc) · 1.75 KB

dj-stripe contains models for all the Stripe objects and can sync them for you

tags: stripe, webhooks, django, dj-stripe

Use case

I realized that Stripe's webhooks don't fire in order, and therefore I was at risk of overwriting valid data with outdated data if I processed them in the order that I received them. I asked Frank for advice and he suggested dj-stripe.

We do have a requirement to use plata if possible, so part of this TIL is seeing if dj-stripe plays well with plata, but a quick glance didn't reveal any obvious red flags.

Initial setup

  • Add dj-stripe to requirements.in and use pip-compile to regenerate my requirements file. Rebuild container.
  • Add djstripe to INSTALLED_APPS
  • Add path("stripe/", include("djstripe.urls", namespace="djstripe")), to urls.py
  • Add these to settings.py:
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
DJSTRIPE_FOREIGN_KEY_TO_FIELD = "id"
  • Start my server.
  • Run ../manage.py migrate
  • Go into the Django Admin and add my test Stripe private API key:
Screenshot 2024-07-18 at 10 13 21 AM

Add my API key and save.

Screenshot 2024-07-18 at 10 14 00 AM
  • In local dev, in my Docker web container, run ./manage.py djstripe_sync_models. See my models populate!