diff --git a/app/settings.py b/app/settings.py index c89b4b4..dda8222 100644 --- a/app/settings.py +++ b/app/settings.py @@ -72,6 +72,7 @@ TEMPLATES = [ "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", + "core.util.django_settings_export.settings_export", ], }, }, diff --git a/core/models.py b/core/models.py index 4fc3bf9..a78614f 100644 --- a/core/models.py +++ b/core/models.py @@ -1,6 +1,7 @@ import logging import stripe +from django.conf import settings from django.contrib.auth.models import AbstractUser from django.db import models @@ -35,25 +36,29 @@ class User(AbstractUser): """ Override the save function to create a Stripe customer. """ - if not self.stripe_id: # stripe ID not stored - self.stripe_id = get_or_create(self.email, self.first_name, self.last_name) - - to_update = {} - if self.email != self._original.email: - to_update["email"] = self.email - if self.first_name != self._original.first_name: - to_update["first_name"] = self.first_name - if self.last_name != self._original.last_name: - to_update["last_name"] = self.last_name - - update_customer_fields(self.stripe_id, **to_update) + if settings.STRIPE_ENABLED: + if not self.stripe_id: # stripe ID not stored + self.stripe_id = get_or_create( + self.email, self.first_name, self.last_name + ) + + to_update = {} + if self.email != self._original.email: + to_update["email"] = self.email + if self.first_name != self._original.first_name: + to_update["first_name"] = self.first_name + if self.last_name != self._original.last_name: + to_update["last_name"] = self.last_name + + update_customer_fields(self.stripe_id, **to_update) super().save(*args, **kwargs) def delete(self, *args, **kwargs): - if self.stripe_id: - stripe.Customer.delete(self.stripe_id) - logger.info(f"Deleted Stripe customer {self.stripe_id}") + if settings.STRIPE_ENABLED: + if self.stripe_id: + stripe.Customer.delete(self.stripe_id) + logger.info(f"Deleted Stripe customer {self.stripe_id}") super().delete(*args, **kwargs) def has_plan(self, plan): diff --git a/core/templates/base.html b/core/templates/base.html index ad1acf9..7843324 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -201,10 +201,12 @@ Home - {% if user.is_authenticated %} - - Billing - + {% if settings.STRIPE_ENABLED %} + {% if user.is_authenticated %} + + Billing + + {% endif %} {% endif %} {% if user.is_superuser %}