From 5990144005d9d1c7f9aeef41e76c81a26820df72 Mon Sep 17 00:00:00 2001 From: Matthew Northcott Date: Tue, 28 Mar 2023 12:05:03 +1300 Subject: [PATCH] Allow Stripe configuration via environment variables --- backend/right_tree/api/views.py | 6 +++++- backend/right_tree/settings.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/right_tree/api/views.py b/backend/right_tree/api/views.py index 8b0a7b1..5d0fa52 100644 --- a/backend/right_tree/api/views.py +++ b/backend/right_tree/api/views.py @@ -3,6 +3,7 @@ import stripe from datetime import timedelta +from django.conf import settings from django.http import HttpResponse, HttpResponseNotAllowed, HttpResponseNotFound, HttpResponseBadRequest, FileResponse from django.shortcuts import get_object_or_404, redirect from django.urls import reverse @@ -222,12 +223,15 @@ def activate_key(request): def purchase_key(request): """Generate a prospective key and redirect to the Stripe payment portal""" + + stripe.api_key = settings.STRIPE_API_KEY + key = ActivationKey.key_default() redirect_url = request.build_absolute_uri(reverse(activate_key)) + f"?key={key}" stripe_session = stripe.checkout.Session.create( line_items=[ { - "price": "price_1Mh1I6GLlkkooLVio8W3TGkR", + "price": settings.STRIPE_PRICE_ID, "quantity": 1, }, ], diff --git a/backend/right_tree/settings.py b/backend/right_tree/settings.py index a1f4ff8..cf96f59 100644 --- a/backend/right_tree/settings.py +++ b/backend/right_tree/settings.py @@ -164,4 +164,5 @@ CELERY_TIMEZONE = TIME_ZONE CELERY_BROKER_URL = REDIS_CELERY_URL # Stripe payment processing -stripe.api_key = os.environ['STRIPE_API_KEY'] +STRIPE_API_KEY = os.environ['STRIPE_API_KEY'] +STRIPE_PRICE_ID = os.environ['STRIPE_PRICE_ID'] -- 2.45.2