parent
218bae2877
commit
5868a97230
9 changed files with 126 additions and 18 deletions
@ -0,0 +1,21 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
# Generated by Django 1.11.6 on 2017-11-15 10:53 |
||||||
|
from __future__ import unicode_literals |
||||||
|
|
||||||
|
from django.db import migrations, models |
||||||
|
import django.db.models.deletion |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('finance', '0012_auto_20171110_1302'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.AlterField( |
||||||
|
model_name='invoice', |
||||||
|
name='yandex_pay', |
||||||
|
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='yandex_money.Payment'), |
||||||
|
), |
||||||
|
] |
||||||
@ -1,22 +1,75 @@ |
|||||||
from django.core.mail import send_mail |
from django.core.mail import EmailMessage |
||||||
from django.db.models.signals import pre_save |
from django.db.models.signals import pre_save, post_save |
||||||
from django.dispatch import receiver |
from django.dispatch import receiver |
||||||
|
from yandex_money.models import Payment |
||||||
|
|
||||||
from finance.models import Invoice |
from finance.models import Invoice |
||||||
|
from access.models import Progress |
||||||
|
|
||||||
|
|
||||||
@receiver(pre_save, sender=Invoice) |
@receiver(pre_save, sender=Invoice) |
||||||
def delete_dependencies(instance, **kwargs): |
def delete_dependencies(instance, **kwargs): |
||||||
"""Отправка сообщения после сохранения платежа""" |
"""Отправка сообщения после сохранения платежа""" |
||||||
if instance.yandex_pay and instance.method == 'Y' and instance.status == 'P': |
if instance.yandex_pay and instance.method == 'Y' and instance.status == 'P': |
||||||
body = { |
EmailMessage( |
||||||
"subject": 'Вам выставлен новый счёт', |
'Вам выставлен новый счёт', |
||||||
"message": '''Вам выставлен счёт, для оплаты перейдите по ссылке |
'''Вам выставлен счёт, для оплаты перейдите по ссылке |
||||||
https://go.skillbox.ru/api/v1/finance/payment/%s/''' % instance.yandex_pay.id, |
https://go.skillbox.ru/api/v1/finance/payment/%s/''' % instance.yandex_pay.id, |
||||||
"from_email": 'robo@skillbox.ru', |
'robo@skillbox.ru', |
||||||
"recipient_list": [instance.yandex_pay.cps_email], |
[instance.yandex_pay.cps_email], |
||||||
} |
[instance.bill.opener.email], |
||||||
|
reply_to=[instance.bill.opener.email], |
||||||
|
) |
||||||
|
|
||||||
|
if instance.status == 'F': |
||||||
|
if instance.is_open: |
||||||
|
Progress.objects.create( |
||||||
|
course=instance.bill.course, |
||||||
|
user=instance.bill.user, |
||||||
|
active_obj=instance.bill.course.get_first(['tutorial', 'task',]) |
||||||
|
) |
||||||
|
EmailMessage( |
||||||
|
'Ваш платёж прошёл успешно', |
||||||
|
'''Вам открыт доступ к курсу "%s", вы можете перейти по ссылке и |
||||||
|
ознакомиться с материабламиhttps://go.skillbox.ru/course/%s/''' |
||||||
|
% (instance.bill.course.title, instance.bill.course.slug), |
||||||
|
'robo@skillbox.ru', |
||||||
|
[instance.yandex_pay.cps_email], |
||||||
|
[instance.bill.opener.email], |
||||||
|
reply_to=[instance.bill.opener.email], |
||||||
|
) |
||||||
|
else: |
||||||
|
EmailMessage( |
||||||
|
'Ваш платёж прошёл успешно', |
||||||
|
'''Курс "%s" был забронирован''' % instance.bill.course.title, |
||||||
|
'robo@skillbox.ru', |
||||||
|
[instance.yandex_pay.cps_email], |
||||||
|
[instance.bill.opener.email], |
||||||
|
reply_to=[instance.bill.opener.email], |
||||||
|
) |
||||||
|
|
||||||
send_mail( |
if instance.status == 'C': |
||||||
**body |
EmailMessage( |
||||||
|
'Ошибка платежа!' |
||||||
|
"""Внимание не прошёл платёж пользавателю %s, |
||||||
|
по курсу "%s" ID платежа: %s. Если не получается |
||||||
|
решить проблему самостоятельно, ответьте на это письмо, |
||||||
|
постарайтесь подробно описать последовательность действий, |
||||||
|
которую превела к ошибке""" |
||||||
|
% (instance.bill.user.get_full_name(), instance.bill.course.title, instance.id), |
||||||
|
'robo@skillbox.ru', |
||||||
|
[instance.bill.opener.email], |
||||||
|
reply_to=["andrey.korolev@skillbox.ru"] |
||||||
) |
) |
||||||
|
|
||||||
|
|
||||||
|
@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() |
||||||
|
|||||||
@ -0,0 +1,20 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
# Generated by Django 1.11.6 on 2017-11-14 16:52 |
||||||
|
from __future__ import unicode_literals |
||||||
|
|
||||||
|
from django.db import migrations, models |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('journals', '0010_auto_20171110_1646'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.AlterField( |
||||||
|
model_name='journal', |
||||||
|
name='date', |
||||||
|
field=models.DateTimeField(auto_now_add=True), |
||||||
|
), |
||||||
|
] |
||||||
Loading…
Reference in new issue