Dmitriy Shesterkin 9 years ago
parent a582467b59
commit d8160375a4
  1. 24
      src/customer/models.py

@ -801,26 +801,32 @@ class Payment(models.Model):
payment = super(Payment, self).save(*args, **kwargs) payment = super(Payment, self).save(*args, **kwargs)
return payment return payment
def confirmed_purchase(self, **kwargs):
try: def confirmed_purchase(**kwargs):
self.status = self.SUCCESS try:
self.date = datetime.now().date() payment = Payment.objects.get(
self.save() pk=kwargs['InvId'],
except Payment.DoesNotExist: order_amount=kwargs['OutSum']
log.info(f"payment with id={kwargs['InvId']} not found") )
payment.status = Payment.SUCCESS
payment.date = datetime.now().date()
payment.save()
except Payment.DoesNotExist:
log.info(f"payment with id={kwargs['InvId']} not found")
# Robokassa # Robokassa
@receiver(result_received) @receiver(result_received)
def order_completed(sender, **kwargs): def order_completed(sender, **kwargs):
sender.confirmed_purchase(sender, **kwargs) confirmed_purchase(**kwargs)
# Robokassa for local debugging # Robokassa for local debugging
@receiver(success_page_visited) @receiver(success_page_visited)
def success_page_visited_completed(sender, **kwargs): def success_page_visited_completed(sender, **kwargs):
if settings.DEBUG: if settings.DEBUG:
sender.confirmed_purchase(sender, **kwargs) confirmed_purchase(**kwargs)
@receiver(post_save, sender=Payment) @receiver(post_save, sender=Payment)

Loading…
Cancel
Save