From 49be43ee70d97240ebefa52f752f0f2424c23e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 15 Nov 2017 10:42:01 +0400 Subject: [PATCH] lingo: handle ACCEPTED payments as being paid (#19934) --- combo/apps/lingo/manager_views.py | 6 ++++-- combo/apps/lingo/models.py | 6 ++++-- combo/apps/lingo/views.py | 9 +++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/combo/apps/lingo/manager_views.py b/combo/apps/lingo/manager_views.py index 88e5656..43fcdcb 100644 --- a/combo/apps/lingo/manager_views.py +++ b/combo/apps/lingo/manager_views.py @@ -56,14 +56,16 @@ class TransactionListView(ListView): paginate_by = 10 def get_queryset(self): - return Transaction.objects.filter(status=eopayment.PAID).order_by('-start_date') + return Transaction.objects.filter( + status__in=(eopayment.PAID, eopayment.ACCEPTED)).order_by('-start_date') def download_transactions_csv(request): response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="transactions.csv"' writer = csv.writer(response) - transactions = Transaction.objects.filter(status=eopayment.PAID).order_by('-start_date') + transactions = Transaction.objects.filter( + status__in=(eopayment.PAID, eopayment.ACCEPTED)).order_by('-start_date') for transaction in transactions: row = [transaction.order_id, transaction.bank_transaction_id, diff --git a/combo/apps/lingo/models.py b/combo/apps/lingo/models.py index b8b75a5..3d9f6d0 100644 --- a/combo/apps/lingo/models.py +++ b/combo/apps/lingo/models.py @@ -236,7 +236,8 @@ class BasketItem(models.Model): url = self.source_url + 'jump/trigger/%s' % status message = {'result': 'ok'} if status == 'paid': - transaction = self.transaction_set.filter(status=eopayment.PAID)[0] + transaction = self.transaction_set.filter( + status__in=(eopayment.ACCEPTED, eopayment.PAID))[0] message['transaction_id'] = transaction.id message['order_id'] = transaction.order_id message['bank_transaction_id'] = transaction.bank_transaction_id @@ -322,12 +323,13 @@ class Transaction(models.Model): return _('Anonymous User') def is_paid(self): - return self.status == eopayment.PAID + return self.status in (eopayment.PAID, eopayment.ACCEPTED) def get_status_label(self): return { 0: _('Running'), eopayment.PAID: _('Paid'), + eopayment.ACCEPTED: _('Paid'), eopayment.CANCELLED: _('Cancelled'), EXPIRED: _('Expired') }.get(self.status) or _('Unknown') diff --git a/combo/apps/lingo/views.py b/combo/apps/lingo/views.py index b934bc5..9a5a97c 100644 --- a/combo/apps/lingo/views.py +++ b/combo/apps/lingo/views.py @@ -415,6 +415,11 @@ class CallbackView(View): logger.info(u'received known payment response with id %s', smart_text(payment_response.order_id), extra=extra_info) + if transaction.status and transaction.status != payment_response.result: + logger.warning(u'received payment notification on existing transaction ' + '(status: %s, new status: %s)' % ( + transaction.status, payment_response.result)) + transaction.status = payment_response.result transaction.bank_transaction_id = payment_response.transaction_id transaction.bank_data = payment_response.bank_data @@ -425,7 +430,7 @@ class CallbackView(View): if not transaction.regie == regie: return HttpResponseBadRequest('Invalid payment regie') - if payment_response.result != eopayment.PAID: + if payment_response.result not in (eopayment.PAID, eopayment.ACCEPTED): return HttpResponse() transaction.items.update(payment_date=transaction.end_date) @@ -476,7 +481,7 @@ class ReturnView(View): 'failed to provide a correct answer.')) return HttpResponseRedirect(get_basket_url()) - if payment_response.result == eopayment.PAID: + if payment_response.result in (eopayment.PAID, eopayment.ACCEPTED): messages.info(request, regie.get_text_on_success()) transaction = Transaction.objects.get(order_id=payment_response.order_id) -- 2.15.0