add coinifyapiinvoice property to order model

This commit is contained in:
Thomas Steen Rasmussen 2017-06-20 09:02:13 +02:00
parent e839396d40
commit 4d9663123a
2 changed files with 16 additions and 11 deletions

View file

@ -226,6 +226,21 @@ class Order(CreatedUpdatedModel):
self.open = None self.open = None
self.save() self.save()
@property
def coinifyapiinvoice(self):
if not self.coinify_api_invoices.exists():
return False
coinifyinvoice = None
for tempinvoice in self.coinify_api_invoices.all():
# we already have a coinifyinvoice for this order, check if it expired
if not tempinvoice.expired:
# this invoice is not expired, we are good to go
return tempinvoice
# nope
return False
class ProductCategory(CreatedUpdatedModel, UUIDModel): class ProductCategory(CreatedUpdatedModel, UUIDModel):
class Meta: class Meta:

View file

@ -535,18 +535,8 @@ 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()
# check if we already have a coinifyinvoice for this order
if order.coinify_api_invoices.exists():
coinifyinvoice = None
for tempinvoice in order.coinify_api_invoices.all():
# we already have a coinifyinvoice for this order, check if it expired
if not tempinvoice.expired:
# this invoice is not expired, we are good to go
coinifyinvoice = tempinvoice
break
# create a new coinify invoice if needed # create a new coinify invoice if needed
if not coinifyinvoice: if not order.coinifyapiinvoice:
coinifyinvoice = create_coinify_invoice(order, request) coinifyinvoice = create_coinify_invoice(order, request)
if not coinifyinvoice: if not coinifyinvoice:
messages.error(request, "There was a problem with the payment provider. Please try again later") messages.error(request, "There was a problem with the payment provider. Please try again later")