From cc874cdbb87bf8d2c50a409ae62c8436c4d993ab Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Tue, 20 Jun 2017 00:13:37 +0200 Subject: [PATCH] loop over invoices to check if they expired --- src/shop/views.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/shop/views.py b/src/shop/views.py index 4e9a9cb7..19092ec4 100644 --- a/src/shop/views.py +++ b/src/shop/views.py @@ -536,15 +536,16 @@ class CoinifyRedirectView(LoginRequiredMixin, EnsureUserOwnsOrderMixin, EnsureUn order = self.get_object() # check if we already have a coinifyinvoice for this order - if hasattr(order, 'coinifyapiinvoice'): - # we already have a coinifyinvoice for this order, check if it expired - if order.coinifyapiinvoice.expired: - # this coinifyinvoice expired, we need a new one - logger.warning("coinifyinvoice id %s expired" % order.coinifyapiinvoice.invoicejson['id']) - order.coinifyapiinvoice = None + 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 coinifyinvoice.expired: + coinifyinvoice = tempinvoice + break # create a new coinify invoice if needed - if not hasattr(order, 'coinifyapiinvoice'): + if not coinifyinvoice: coinifyinvoice = create_coinify_invoice(order, request) if not coinifyinvoice: messages.error(request, "There was a problem with the payment provider. Please try again later")