diff --git a/combo/apps/lingo/migrations/0006_transaction_status.py b/combo/apps/lingo/migrations/0006_transaction_status.py new file mode 100644 index 00000000..4d81b6c0 --- /dev/null +++ b/combo/apps/lingo/migrations/0006_transaction_status.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('lingo', '0005_auto_20150307_1242'), + ] + + operations = [ + migrations.AddField( + model_name='transaction', + name='status', + field=models.IntegerField(null=True), + preserve_default=True, + ), + ] diff --git a/combo/apps/lingo/models.py b/combo/apps/lingo/models.py index b1a4a017..ab32247a 100644 --- a/combo/apps/lingo/models.py +++ b/combo/apps/lingo/models.py @@ -94,6 +94,17 @@ class Transaction(models.Model): bank_data = JSONField(blank=True) order_id = models.CharField(max_length=200) user = models.ForeignKey(settings.AUTH_USER_MODEL) + status = models.IntegerField(null=True) + + def is_paid(self): + return self.status == eopayment.PAID + + def get_status_label(self): + return { + 0: _('Running'), + eopayment.PAID: _('Paid'), + eopayment.CANCELLED: _('Cancelled'), + }.get(self.status) or _('Unknown') @register_cell_class diff --git a/combo/apps/lingo/templates/lingo/combo/recent_transactions.html b/combo/apps/lingo/templates/lingo/combo/recent_transactions.html index c5ea12ef..bb44ebeb 100644 --- a/combo/apps/lingo/templates/lingo/combo/recent_transactions.html +++ b/combo/apps/lingo/templates/lingo/combo/recent_transactions.html @@ -4,11 +4,15 @@ diff --git a/combo/apps/lingo/views.py b/combo/apps/lingo/views.py index 452a47bd..4cc799a5 100644 --- a/combo/apps/lingo/views.py +++ b/combo/apps/lingo/views.py @@ -93,6 +93,7 @@ class PayView(View): transaction.user = request.user transaction.save() transaction.items = items + transaction.status = 0 transaction.save() total_amount = sum([x.amount for x in items]) @@ -126,12 +127,19 @@ class CallbackView(View): regie = Regie.objects.get(id=kwargs.get('regie_pk')) payment = eopayment.Payment(regie.service, regie.service_options) payment_response = payment.response(request.environ['QUERY_STRING']) - assert payment_response.signed is True - assert payment_response.result == eopayment.PAID + if not payment_response.result == eopayment.CANCELLED: + # cancellation are not signed... + assert payment_response.signed is True + transaction = Transaction.objects.get(order_id=payment_response.order_id) + transaction.status = payment_response.result transaction.bank_data = payment_response.bank_data transaction.end_date = timezone.now() transaction.save() + + if payment_response.result != eopayment.PAID: + return HttpResponseRedirect('/') + for item in transaction.items.all(): item.payment_date = transaction.end_date item.save()