From 9716339d642d2784590d3df26aa7d8161c6c9f57 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Thu, 21 Apr 2022 01:09:44 +0200 Subject: [PATCH] Fix for expired tokens. --- src/club/migrations/0039_auto_20220421_0109.py | 18 ++++++++++++++++++ src/club/models.py | 2 +- src/club/payu/models.py | 16 ++++++++++++---- 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 src/club/migrations/0039_auto_20220421_0109.py diff --git a/src/club/migrations/0039_auto_20220421_0109.py b/src/club/migrations/0039_auto_20220421_0109.py new file mode 100644 index 000000000..2436a77da --- /dev/null +++ b/src/club/migrations/0039_auto_20220421_0109.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.27 on 2022-04-20 23:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('club', '0038_payuorder_created_at'), + ] + + operations = [ + migrations.AlterField( + model_name='payuorder', + name='status', + field=models.CharField(blank=True, choices=[('PENDING', 'Pending'), ('WAITING_FOR_CONFIRMATION', 'Waiting for confirmation'), ('COMPLETED', 'Completed'), ('CANCELED', 'Canceled'), ('REJECTED', 'Rejected'), ('ERR-INVALID_TOKEN', 'Invalid token')], max_length=128), + ), + ] diff --git a/src/club/models.py b/src/club/models.py index 0d75ec465..c5057a7ba 100644 --- a/src/club/models.py +++ b/src/club/models.py @@ -316,7 +316,7 @@ class PayUOrder(payu_models.Order): if self.status == 'COMPLETED': self.schedule.set_payed() - elif self.status == 'CANCELED': + elif self.status == 'CANCELED' or self.status.startswith('ERR-'): if self.is_recurring() and self.schedule.expires_at: self.schedule.send_email_failed_recurring() diff --git a/src/club/payu/models.py b/src/club/payu/models.py index 6305e2ed5..10dd60aaf 100644 --- a/src/club/payu/models.py +++ b/src/club/payu/models.py @@ -36,6 +36,8 @@ class Order(models.Model): ('COMPLETED', _('Completed')), ('CANCELED', _('Canceled')), ('REJECTED', _('Rejected')), + + ('ERR-INVALID_TOKEN', _('Invalid token')), ]) created_at = models.DateTimeField(null=True, blank=True, auto_now_add=True) completed_at = models.DateTimeField(null=True, blank=True) @@ -128,11 +130,17 @@ class Order(models.Model): # else? if 'orderId' not in response: - raise ValueError("Expecting dict with `orderId` key, got: %s" % response) - self.order_id = response['orderId'] - self.save() + code = response.get('status', {}).get('codeLiteral', '') + if code: + self.status = 'ERR-' + str(code) + self.save() + self.status_updated() + else: + raise ValueError("Expecting dict with `orderId` key, got: %s" % response) + else: + self.order_id = response['orderId'] + self.save() - return response.get('redirectUri', self.schedule.get_thanks_url()) -- 2.20.1