From 91f5c4b5f95e84d052db37b19ba9a92e8c46101b Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Tue, 31 May 2016 22:57:55 +0200 Subject: [PATCH] delete expired coinifyapiinvoice objects --- shop/models.py | 1 - shop/views.py | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/shop/models.py b/shop/models.py index b3b0cf36..1671cf61 100644 --- a/shop/models.py +++ b/shop/models.py @@ -281,7 +281,6 @@ class CoinifyAPIInvoice(CreatedUpdatedModel): return "coinifyinvoice for order #%s" % self.order.id - class CoinifyAPICallback(CreatedUpdatedModel): headers = JSONField() payload = JSONField() diff --git a/shop/views.py b/shop/views.py index 6cc9d568..8ccafacf 100644 --- a/shop/views.py +++ b/shop/views.py @@ -17,6 +17,7 @@ from django.views.generic.base import RedirectView from django.views.generic.detail import SingleObjectMixin from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_exempt +from django.utils.dateparse import parse_datetime from camps.models import Camp from shop.models import ( @@ -382,6 +383,14 @@ class CoinifyRedirectView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUn def dispatch(self, request, *args, **kwargs): order = self.get_object() + if hasattr(order, 'coinifyapiinvoice'): + # we already have a coinifyinvoice for this order, + # check if it expired + if parse_datetime(order.coinifyapiinvoice.invoicejson['expire_time']) < timezone.now(): + # this coinifyinvoice expired, delete it + order.coinifyapiinvoice.delete() + + # create a new coinify invoice if needed if not hasattr(order, 'coinifyapiinvoice'): # Initiate coinify API coinifyapi = CoinifyAPI(