From 9c777e3d9d4d1456fa64fdb0474ddcff4ca70927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Sun, 22 Jan 2023 10:04:52 +0100 Subject: [PATCH] WIP Stripe integration. --- env | 3 +++ requirements/base.in | 1 + requirements/base.txt | 11 ++++++++++- requirements/dev.txt | 19 +++++++++++++++---- requirements/test.txt | 15 ++++++++++++++- src/project/settings.py | 9 +++++++++ src/project/urls.py | 1 + 7 files changed, 53 insertions(+), 6 deletions(-) diff --git a/env b/env index 86933bf..cebab5a 100644 --- a/env +++ b/env @@ -5,3 +5,6 @@ POSTGRES_PORT=5432 DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres DEBUG=True DJANGO_ENV=development +STRIPE_LIVE_SECRET_KEY=getfromstripeaccount +STRIPE_TEST_SECRET_KEY=getfromstripeaccount +STRIPE_WEBHOOK_SECRET=getfromstripeaccount diff --git a/requirements/base.in b/requirements/base.in index a1667aa..7c9ceae 100644 --- a/requirements/base.in +++ b/requirements/base.in @@ -6,3 +6,4 @@ environs[django]==9.3 uvicorn==0.13 whitenoise==5.2 django-zen-queries==2.1.0 +dj-stripe==2.7.3 diff --git a/requirements/base.txt b/requirements/base.txt index 052d79a..e512930 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # pip-compile --output-file=requirements/base.txt requirements/base.in @@ -22,13 +22,17 @@ dj-database-url==1.0.0 # via environs dj-email-url==1.0.6 # via environs +dj-stripe==2.7.3 + # via -r requirements/base.in django==4.1.5 # via # -r requirements/base.in # dj-database-url + # dj-stripe # django-allauth # django-money # django-zen-queries + # jsonfield django-allauth==0.46 # via -r requirements/base.in django-cache-url==3.4.2 @@ -43,6 +47,8 @@ h11==0.14.0 # via uvicorn idna==3.4 # via requests +jsonfield==3.1.0 + # via dj-stripe marshmallow==3.19.0 # via environs oauthlib==3.2.2 @@ -67,10 +73,13 @@ requests==2.28.1 # via # django-allauth # requests-oauthlib + # stripe requests-oauthlib==1.3.1 # via django-allauth sqlparse==0.4.3 # via django +stripe==4.2.0 + # via dj-stripe urllib3==1.26.12 # via requests uvicorn==0.13 diff --git a/requirements/dev.txt b/requirements/dev.txt index e3f707e..963aff5 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # pip-compile --output-file=requirements/dev.txt requirements/dev.in @@ -48,10 +48,13 @@ dj-email-url==1.0.6 # via # -r requirements/test.txt # environs +dj-stripe==2.7.3 + # via -r requirements/test.txt django==4.1.5 # via # -r requirements/test.txt # dj-database-url + # dj-stripe # django-allauth # django-browser-reload # django-debug-toolbar @@ -60,6 +63,7 @@ django==4.1.5 # django-stubs # django-stubs-ext # django-zen-queries + # jsonfield django-allauth==0.46 # via -r requirements/test.txt django-browser-reload==1.6.0 @@ -96,6 +100,10 @@ ipython==8.6.0 # via -r requirements/dev.in jedi==0.18.1 # via ipython +jsonfield==3.1.0 + # via + # -r requirements/test.txt + # dj-stripe lxml==4.9.1 # via # -r requirements/test.txt @@ -165,6 +173,7 @@ requests==2.28.1 # -r requirements/test.txt # django-allauth # requests-oauthlib + # stripe requests-oauthlib==1.3.1 # via # -r requirements/test.txt @@ -178,12 +187,14 @@ sqlparse==0.4.3 # django-debug-toolbar stack-data==0.6.1 # via ipython +stripe==4.2.0 + # via + # -r requirements/test.txt + # dj-stripe tblib==1.7.0 # via -r requirements/test.txt tomli==2.0.1 - # via - # django-stubs - # mypy + # via django-stubs traitlets==5.5.0 # via # ipython diff --git a/requirements/test.txt b/requirements/test.txt index 7a21b7b..16010ce 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # pip-compile --output-file=requirements/test.txt requirements/test.in @@ -42,13 +42,17 @@ dj-email-url==1.0.6 # via # -r requirements/base.txt # environs +dj-stripe==2.7.3 + # via -r requirements/base.txt django==4.1.5 # via # -r requirements/base.txt # dj-database-url + # dj-stripe # django-allauth # django-money # django-zen-queries + # jsonfield django-allauth==0.46 # via -r requirements/base.txt django-cache-url==3.4.2 @@ -69,6 +73,10 @@ idna==3.4 # via # -r requirements/base.txt # requests +jsonfield==3.1.0 + # via + # -r requirements/base.txt + # dj-stripe lxml==4.9.1 # via unittest-xml-reporting marshmallow==3.19.0 @@ -114,6 +122,7 @@ requests==2.28.1 # -r requirements/base.txt # django-allauth # requests-oauthlib + # stripe requests-oauthlib==1.3.1 # via # -r requirements/base.txt @@ -122,6 +131,10 @@ sqlparse==0.4.3 # via # -r requirements/base.txt # django +stripe==4.2.0 + # via + # -r requirements/base.txt + # dj-stripe tblib==1.7.0 # via -r requirements/test.in unittest-xml-reporting==3.2.0 diff --git a/src/project/settings.py b/src/project/settings.py index f04d367..7542d1b 100644 --- a/src/project/settings.py +++ b/src/project/settings.py @@ -40,6 +40,7 @@ DJANGO_APPS = [ THIRD_PARTY_APPS = [ "allauth", "allauth.account", + "djstripe", ] LOCAL_APPS = [ @@ -162,3 +163,11 @@ if DEBUG: DEBUG_TOOLBAR_CONFIG = { "SHOW_TOOLBAR_CALLBACK": lambda _x: DEBUG, } + +# Stripe configuration +STRIPE_LIVE_SECRET_KEY = env.str("STRIPE_LIVE_SECRET_KEY") +STRIPE_TEST_SECRET_KEY = env.str("STRIPE_TEST_SECRET_KEY") +STRIPE_LIVE_MODE = False +DJSTRIPE_WEBHOOK_SECRET = env.str("STRIPE_WEBHOOK_SECRET") +DJSTRIPE_USE_NATIVE_JSONFIELD = True +DJSTRIPE_FOREIGN_KEY_TO_FIELD = "id" diff --git a/src/project/urls.py b/src/project/urls.py index f7d189b..8e3da99 100644 --- a/src/project/urls.py +++ b/src/project/urls.py @@ -22,6 +22,7 @@ urlpatterns = [ name="admin-members-detail", ), path("accounts/", include("allauth.urls")), + path("stripe/", include("djstripe.urls", namespace="djstripe")), path("_admin/", admin.site.urls), ]