Allow Stripe configuration via environment variables #95

Merged
mattn merged 1 commit from matt/stripe-env into main 2023-03-28 13:00:00 +13:00
2 changed files with 7 additions and 2 deletions

View file

@ -3,6 +3,7 @@ import stripe
from datetime import timedelta from datetime import timedelta
from django.conf import settings
from django.http import HttpResponse, HttpResponseNotAllowed, HttpResponseNotFound, HttpResponseBadRequest, FileResponse from django.http import HttpResponse, HttpResponseNotAllowed, HttpResponseNotFound, HttpResponseBadRequest, FileResponse
from django.shortcuts import get_object_or_404, redirect from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse from django.urls import reverse
@ -222,12 +223,15 @@ def activate_key(request):
def purchase_key(request): def purchase_key(request):
"""Generate a prospective key and redirect to the Stripe payment portal""" """Generate a prospective key and redirect to the Stripe payment portal"""
stripe.api_key = settings.STRIPE_API_KEY
key = ActivationKey.key_default() key = ActivationKey.key_default()
redirect_url = request.build_absolute_uri(reverse(activate_key)) + f"?key={key}" redirect_url = request.build_absolute_uri(reverse(activate_key)) + f"?key={key}"
stripe_session = stripe.checkout.Session.create( stripe_session = stripe.checkout.Session.create(
line_items=[ line_items=[
{ {
"price": "price_1Mh1I6GLlkkooLVio8W3TGkR", "price": settings.STRIPE_PRICE_ID,
"quantity": 1, "quantity": 1,
}, },
], ],

View file

@ -164,4 +164,5 @@ CELERY_TIMEZONE = TIME_ZONE
CELERY_BROKER_URL = REDIS_CELERY_URL CELERY_BROKER_URL = REDIS_CELERY_URL
# Stripe payment processing # 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']