X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/9fa9848eda1f2f714d0c65eee0ffc6b65e1de4cc..ecd1f5bc214a8ba61b65d4d00a7e7d09a8c8fa3a:/src/club/payu/models.py diff --git a/src/club/payu/models.py b/src/club/payu/models.py index 5764f8842..10dd60aaf 100644 --- a/src/club/payu/models.py +++ b/src/club/payu/models.py @@ -36,7 +36,10 @@ 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) class Meta: @@ -89,7 +92,7 @@ class Order(models.Model): "merchantPosId": self.pos_id, "currencyCode": self.get_pos().currency_code, "totalAmount": str(int(self.get_amount() * 100)), - "extOrderId": "wolne-lektury-rcz-%d" % self.pk, + "extOrderId": "wolne-lektury-%d" % self.pk, "buyer": self.get_buyer() or {}, "continueUrl": self.get_continue_url(), @@ -127,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())