delete expired coinifyapiinvoice objects
This commit is contained in:
parent
2042313780
commit
91f5c4b5f9
|
@ -281,7 +281,6 @@ class CoinifyAPIInvoice(CreatedUpdatedModel):
|
||||||
return "coinifyinvoice for order #%s" % self.order.id
|
return "coinifyinvoice for order #%s" % self.order.id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CoinifyAPICallback(CreatedUpdatedModel):
|
class CoinifyAPICallback(CreatedUpdatedModel):
|
||||||
headers = JSONField()
|
headers = JSONField()
|
||||||
payload = JSONField()
|
payload = JSONField()
|
||||||
|
|
|
@ -17,6 +17,7 @@ from django.views.generic.base import RedirectView
|
||||||
from django.views.generic.detail import SingleObjectMixin
|
from django.views.generic.detail import SingleObjectMixin
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
from django.utils.dateparse import parse_datetime
|
||||||
|
|
||||||
from camps.models import Camp
|
from camps.models import Camp
|
||||||
from shop.models import (
|
from shop.models import (
|
||||||
|
@ -382,6 +383,14 @@ class CoinifyRedirectView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUn
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
order = self.get_object()
|
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'):
|
if not hasattr(order, 'coinifyapiinvoice'):
|
||||||
# Initiate coinify API
|
# Initiate coinify API
|
||||||
coinifyapi = CoinifyAPI(
|
coinifyapi = CoinifyAPI(
|
||||||
|
|
Loading…
Reference in a new issue