commit
197a9a78e4
4 changed files with 86 additions and 86 deletions
@ -1,81 +1,81 @@ |
||||
from django.core.mail import EmailMessage |
||||
from django.db.models.signals import pre_save, post_save |
||||
from django.dispatch import receiver |
||||
from yandex_money.models import Payment |
||||
from django.conf import settings |
||||
|
||||
from finance.models import Invoice |
||||
from courses.models import Course |
||||
from progress.models import Progress |
||||
|
||||
|
||||
@receiver(pre_save, sender=Invoice) |
||||
def invoice_signal(instance, **kwargs): |
||||
"""Отправка сообщения после сохранения платежа""" |
||||
|
||||
course = Course.objects.get(token=instance.bill.course_token) |
||||
|
||||
if instance.yandex_pay and instance.method == 'Y' and instance.status == 'P': |
||||
msg = EmailMessage( |
||||
'Вам выставлен новый счёт', |
||||
'''Вам выставлен счёт, для оплаты перейдите по ссылке |
||||
%s/api/v1/finance/payment/%s/''' % (settings.DOMAIN, instance.yandex_pay.id,), |
||||
'robo@skillbox.ru', |
||||
[instance.yandex_pay.cps_email], |
||||
[instance.bill.opener.email], |
||||
reply_to=[instance.bill.opener.email], |
||||
) |
||||
msg.send() |
||||
|
||||
if instance.status == 'F': |
||||
if instance.is_open: |
||||
Progress.objects.get_or_create( |
||||
course_token=instance.bill.course_token, |
||||
user=instance.bill.user, |
||||
) |
||||
msg = EmailMessage( |
||||
'Ваш платёж прошёл успешно', |
||||
'''Вам открыт доступ к курсу "%s", вы можете перейти по ссылке и |
||||
ознакомиться с материалами %s/course/%s''' |
||||
% (course.title, settings.DOMAIN, course.slug), |
||||
'robo@skillbox.ru', |
||||
[instance.bill.user.email], |
||||
cc=[instance.bill.opener.email], |
||||
reply_to=[instance.bill.opener.email], |
||||
) |
||||
else: |
||||
msg = EmailMessage( |
||||
'Ваш платёж прошёл успешно', |
||||
'''Курс "%s" был забронирован''' % instance.bill.course.title, |
||||
'robo@skillbox.ru', |
||||
[instance.yandex_pay.cps_email], |
||||
cc=[instance.bill.opener.email], |
||||
reply_to=[instance.bill.opener.email], |
||||
) |
||||
msg.send() |
||||
|
||||
if instance.status == 'C': |
||||
msg = EmailMessage( |
||||
'Ошибка платежа!' |
||||
"""Внимание не прошёл платёж пользавателю %s, |
||||
по курсу "%s" ID платежа: %s. Если не получается |
||||
решить проблему самостоятельно, ответьте на это письмо, |
||||
постарайтесь подробно описать последовательность действий, |
||||
которая привела к ошибке""" |
||||
% (instance.bill.user.get_full_name(), course.title, instance.id), |
||||
instance.bill.opener.email, |
||||
reply_to=["it@skillbox.ru"] |
||||
) |
||||
msg.send() |
||||
|
||||
|
||||
@receiver(post_save, sender=Payment) |
||||
def access_pay(instance, **kwargs): |
||||
if instance.status == 'success': |
||||
instance.invoice.status = "F" |
||||
instance.invoice.real_price = instance.shop_amount |
||||
instance.invoice.save() |
||||
|
||||
if instance.status == 'fail': |
||||
instance.invoice.status = "C" |
||||
instance.invoice.save() |
||||
# from django.core.mail import EmailMessage |
||||
# from django.db.models.signals import pre_save, post_save |
||||
# from django.dispatch import receiver |
||||
# from yandex_money.models import Payment |
||||
# from django.conf import settings |
||||
# |
||||
# from finance.models import Invoice |
||||
# from courses.models import Course |
||||
# from progress.models import Progress |
||||
# |
||||
# |
||||
# @receiver(pre_save, sender=Invoice) |
||||
# def invoice_signal(instance, **kwargs): |
||||
# """Отправка сообщения после сохранения платежа""" |
||||
# |
||||
# course = Course.objects.get(token=instance.bill.course_token) |
||||
# |
||||
# if instance.yandex_pay and instance.method == 'Y' and instance.status == 'P': |
||||
# msg = EmailMessage( |
||||
# 'Вам выставлен новый счёт', |
||||
# '''Вам выставлен счёт, для оплаты перейдите по ссылке |
||||
# %s/api/v1/finance/payment/%s/''' % (settings.DOMAIN, instance.yandex_pay.id,), |
||||
# 'robo@skillbox.ru', |
||||
# [instance.yandex_pay.cps_email], |
||||
# [instance.bill.opener.email], |
||||
# reply_to=[instance.bill.opener.email], |
||||
# ) |
||||
# msg.send() |
||||
# |
||||
# if instance.status == 'F': |
||||
# if instance.is_open: |
||||
# Progress.objects.get_or_create( |
||||
# course_token=instance.bill.course_token, |
||||
# user=instance.bill.user, |
||||
# ) |
||||
# msg = EmailMessage( |
||||
# 'Ваш платёж прошёл успешно', |
||||
# '''Вам открыт доступ к курсу "%s", вы можете перейти по ссылке и |
||||
# ознакомиться с материалами %s/course/%s''' |
||||
# % (course.title, settings.DOMAIN, course.slug), |
||||
# 'robo@skillbox.ru', |
||||
# [instance.bill.user.email], |
||||
# cc=[instance.bill.opener.email], |
||||
# reply_to=[instance.bill.opener.email], |
||||
# ) |
||||
# else: |
||||
# msg = EmailMessage( |
||||
# 'Ваш платёж прошёл успешно', |
||||
# '''Курс "%s" был забронирован''' % instance.bill.course.title, |
||||
# 'robo@skillbox.ru', |
||||
# [instance.yandex_pay.cps_email], |
||||
# cc=[instance.bill.opener.email], |
||||
# reply_to=[instance.bill.opener.email], |
||||
# ) |
||||
# msg.send() |
||||
# |
||||
# if instance.status == 'C': |
||||
# msg = EmailMessage( |
||||
# 'Ошибка платежа!' |
||||
# """Внимание не прошёл платёж пользавателю %s, |
||||
# по курсу "%s" ID платежа: %s. Если не получается |
||||
# решить проблему самостоятельно, ответьте на это письмо, |
||||
# постарайтесь подробно описать последовательность действий, |
||||
# которая привела к ошибке""" |
||||
# % (instance.bill.user.get_full_name(), course.title, instance.id), |
||||
# instance.bill.opener.email, |
||||
# reply_to=["it@skillbox.ru"] |
||||
# ) |
||||
# msg.send() |
||||
# |
||||
# |
||||
# @receiver(post_save, sender=Payment) |
||||
# def access_pay(instance, **kwargs): |
||||
# if instance.status == 'success': |
||||
# instance.invoice.status = "F" |
||||
# instance.invoice.real_price = instance.shop_amount |
||||
# instance.invoice.save() |
||||
# |
||||
# if instance.status == 'fail': |
||||
# instance.invoice.status = "C" |
||||
# instance.invoice.save() |
||||
|
||||
Loading…
Reference in new issue