lingo: track transaction status, handle cancellations (#6999)
This commit is contained in:
parent
81dc29d045
commit
9c29693dcd
|
@ -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,
|
||||
),
|
||||
]
|
|
@ -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
|
||||
|
|
|
@ -4,11 +4,15 @@
|
|||
<ul>
|
||||
{% for transaction in transactions %}
|
||||
<li>{{ transaction.start_date|date:"d E o H:i"|lower }}
|
||||
{% if transaction.is_paid %}
|
||||
<ul>
|
||||
{% for item in transaction.items.all %}
|
||||
<li>{{ item.subject }}: {{ item.amount }} €</label> (<a href="{{ item.source_url}}">voir</a>)</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{{ transaction.get_status_label }}
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue