upgrade
[wolnelektury.git] / src / club / payu / models.py
index 6ed329d..10dd60a 100644 (file)
@@ -36,7 +36,10 @@ class Order(models.Model):
         ('COMPLETED', _('Completed')),
         ('CANCELED', _('Canceled')),
         ('REJECTED', _('Rejected')),
         ('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:
     completed_at = models.DateTimeField(null=True, blank=True)
 
     class Meta:
@@ -127,11 +130,17 @@ class Order(models.Model):
             # else?
 
         if 'orderId' not in response:
             # 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())
 
 
         return response.get('redirectUri', self.schedule.get_thanks_url())