X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/3b0dd45f80df3512dabe75506e635a0f6e3a87e3..a37fe43b4e66df55d0491ae6defae31a07a645be:/src/club/payu/models.py?ds=sidebyside 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())