Refactor secret / local settings handling

This commit is contained in:
Nico Schottelius 2020-05-02 00:16:29 +02:00
commit 2cda6441f4
5 changed files with 60 additions and 60 deletions

View file

@ -4,7 +4,7 @@ from django.contrib.auth import get_user_model
from django.core.validators import MinValueValidator
from django.utils.translation import gettext_lazy as _
from django.utils import timezone
from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import ObjectDoesNotExist, ValidationError
import uuid
import logging
@ -811,7 +811,7 @@ class Order(models.Model):
# TODO: enforce ending_date - starting_date to be larger than recurring_period.
creation_date = models.DateTimeField(auto_now_add=True)
starting_date = models.DateTimeField()
starting_date = models.DateTimeField(default=timezone.now)
ending_date = models.DateTimeField(blank=True,
null=True)
@ -918,6 +918,17 @@ class Product(UncloudModel):
# _state.adding is switched to false after super(...) call.
being_created = self._state.adding
# First time saving - create an order
if not self.order:
billing_address = BillingAddress.get_preferred_address_for(self.owner)
if not billing_address:
raise ValidationError("Cannot create order without a billing address")
self.order = Order(owner=self.owner,
billing_address=billing_address)
super(Product, self).save(*args, **kwargs)
# Make sure we only create records on creation.

View file

@ -3,9 +3,9 @@ import stripe.error
import logging
from django.core.exceptions import ObjectDoesNotExist
import uncloud_pay.models
from django.conf import settings
import uncloud.secrets
import uncloud_pay.models
# Static stripe configuration used below.
CURRENCY = 'chf'
@ -14,7 +14,7 @@ CURRENCY = 'chf'
# https://stripe.com/docs/payments/save-and-reuse
# For internal use only.
stripe.api_key = uncloud.secrets.STRIPE_KEY
stripe.api_key = settings.STRIPE_KEY
# Helper (decorator) used to catch errors raised by stripe logic.
# Catch errors that should not be displayed to the end user, raise again.
@ -64,7 +64,7 @@ def handle_stripe_error(f):
# Actual Stripe logic.
def public_api_key():
return uncloud.secrets.STRIPE_PUBLIC_KEY
return settings.STRIPE_PUBLIC_KEY
def get_customer_id_for(user):
try: