+
+########
+# #
+# PayU #
+# #
+########
+
+class PayUOrder(payu_models.Order):
+ schedule = models.ForeignKey(Schedule, on_delete=models.CASCADE)
+
+ def get_amount(self):
+ return self.schedule.amount
+
+ def get_buyer(self):
+ return {
+ "email": self.schedule.email,
+ "language": get_language(),
+ }
+
+ def get_continue_url(self):
+ return "https://{}{}".format(
+ Site.objects.get_current().domain,
+ self.schedule.get_thanks_url())
+
+ def get_description(self):
+ return ugettext('Towarzystwo Wolnych Lektur')
+
+ def is_recurring(self):
+ return self.schedule.get_payment_method().is_recurring
+
+ def get_card_token(self):
+ return self.schedule.payucardtoken_set.order_by('-created_at').first()
+
+ def get_notify_url(self):
+ return "https://{}{}".format(
+ Site.objects.get_current().domain,
+ reverse('club_payu_notify', args=[self.pk]))
+
+ def status_updated(self):
+ if self.status == 'COMPLETED':
+ since = self.schedule.expires_at
+ n = now()
+ if since is None or since < n:
+ since = n
+ new_exp = self.schedule.plan.get_next_installment(since)
+ if self.schedule.payed_at is None:
+ self.schedule.payed_at = n
+ if self.schedule.expires_at is None or self.schedule.expires_at < new_exp:
+ self.schedule.expires_at = new_exp
+ self.schedule.save()
+
+ if not self.schedule.email_sent:
+ self.schedule.send_email()
+
+
+class PayUCardToken(payu_models.CardToken):
+ schedule = models.ForeignKey(Schedule, on_delete=models.CASCADE)
+
+
+class PayUNotification(payu_models.Notification):
+ order = models.ForeignKey(PayUOrder, models.CASCADE, related_name='notification_set')