parent
f6de736878
commit
d7c1f136c4
9 changed files with 157 additions and 133 deletions
@ -0,0 +1,20 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
# Generated by Django 1.11.6 on 2017-12-25 11:42 |
||||||
|
from __future__ import unicode_literals |
||||||
|
|
||||||
|
from django.db import migrations, models |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('finance', '0001_initial'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.AlterField( |
||||||
|
model_name='invoice', |
||||||
|
name='price', |
||||||
|
field=models.IntegerField(blank=True, editable=False, null=True, verbose_name='Сумма'), |
||||||
|
), |
||||||
|
] |
||||||
@ -1,79 +1,79 @@ |
|||||||
from django.core.mail import EmailMessage |
# from django.core.mail import EmailMessage |
||||||
from django.db.models.signals import pre_save, post_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 yandex_money.models import Payment |
||||||
|
# |
||||||
from finance.models import Invoice |
# from finance.models import Invoice |
||||||
from access.models.other import Progress |
# from access.models.other import Progress |
||||||
from course_service.maps.api import OutApiRoute |
# from course_service.maps.api import OutApiRoute |
||||||
|
# |
||||||
api = OutApiRoute |
# api = OutApiRoute |
||||||
|
# |
||||||
|
# |
||||||
@receiver(pre_save, sender=Invoice) |
# @receiver(pre_save, sender=Invoice) |
||||||
def invoice_signal(instance, **kwargs): |
# def invoice_signal(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': |
||||||
msg = EmailMessage( |
# msg = EmailMessage( |
||||||
'Вам выставлен новый счёт', |
# 'Вам выставлен новый счёт', |
||||||
'''Вам выставлен счёт, для оплаты перейдите по ссылке |
# '''Вам выставлен счёт, для оплаты перейдите по ссылке |
||||||
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, |
||||||
'robo@skillbox.ru', |
# 'robo@skillbox.ru', |
||||||
[instance.yandex_pay.cps_email], |
# [instance.yandex_pay.cps_email], |
||||||
[instance.bill.opener.email], |
# [instance.bill.opener.email], |
||||||
reply_to=[instance.bill.opener.email], |
# reply_to=[instance.bill.opener.email], |
||||||
) |
# ) |
||||||
msg.send() |
# msg.send() |
||||||
|
# |
||||||
if instance.status == 'F': |
# if instance.status == 'F': |
||||||
if instance.is_open: |
# if instance.is_open: |
||||||
Progress.objects.get_or_create( |
# Progress.objects.get_or_create( |
||||||
route=instance.bill.route, |
# route=instance.bill.route, |
||||||
user=instance.bill.user, |
# user=instance.bill.user, |
||||||
) |
# ) |
||||||
msg = EmailMessage( |
# msg = EmailMessage( |
||||||
'Ваш платёж прошёл успешно', |
# 'Ваш платёж прошёл успешно', |
||||||
'''Вам открыт доступ к курсу "%s", вы можете перейти по ссылке и |
# '''Вам открыт доступ к курсу "%s", вы можете перейти по ссылке и |
||||||
ознакомиться с материалами https://go.skillbox.ru/course/%s''' |
# ознакомиться с материалами https://go.skillbox.ru/course/%s''' |
||||||
% (api.get_route(instance.bill.route).name, api.get_route(instance.bill.route).course.slug), |
# % (api.get_route(instance.bill.route).name, api.get_route(instance.bill.route).course.slug), |
||||||
'robo@skillbox.ru', |
# 'robo@skillbox.ru', |
||||||
[instance.bill.user.email], |
# [instance.bill.user.email], |
||||||
cc=[instance.bill.opener.email], |
# cc=[instance.bill.opener.email], |
||||||
reply_to=[instance.bill.opener.email], |
# reply_to=[instance.bill.opener.email], |
||||||
) |
# ) |
||||||
else: |
# else: |
||||||
msg = EmailMessage( |
# msg = EmailMessage( |
||||||
'Ваш платёж прошёл успешно', |
# 'Ваш платёж прошёл успешно', |
||||||
'''Курс "%s" был забронирован''' % instance.bill.course.title, |
# '''Курс "%s" был забронирован''' % instance.bill.course.title, |
||||||
'robo@skillbox.ru', |
# 'robo@skillbox.ru', |
||||||
[instance.yandex_pay.cps_email], |
# [instance.yandex_pay.cps_email], |
||||||
cc=[instance.bill.opener.email], |
# cc=[instance.bill.opener.email], |
||||||
reply_to=[instance.bill.opener.email], |
# reply_to=[instance.bill.opener.email], |
||||||
) |
# ) |
||||||
msg.send() |
# msg.send() |
||||||
|
# |
||||||
if instance.status == 'C': |
# if instance.status == 'C': |
||||||
msg = EmailMessage( |
# msg = EmailMessage( |
||||||
'Ошибка платежа!' |
# 'Ошибка платежа!' |
||||||
"""Внимание не прошёл платёж пользавателю %s, |
# """Внимание не прошёл платёж пользавателю %s, |
||||||
по курсу "%s" ID платежа: %s. Если не получается |
# по курсу "%s" ID платежа: %s. Если не получается |
||||||
решить проблему самостоятельно, ответьте на это письмо, |
# решить проблему самостоятельно, ответьте на это письмо, |
||||||
постарайтесь подробно описать последовательность действий, |
# постарайтесь подробно описать последовательность действий, |
||||||
которая привела к ошибке""" |
# которая привела к ошибке""" |
||||||
% (instance.bill.user.get_full_name(), api.get_route(instance.bill.route).course.title, instance.id), |
# % (instance.bill.user.get_full_name(), api.get_route(instance.bill.route).course.title, instance.id), |
||||||
instance.bill.opener.email, |
# instance.bill.opener.email, |
||||||
reply_to=["it@skillbox.ru"] |
# reply_to=["it@skillbox.ru"] |
||||||
) |
# ) |
||||||
msg.send() |
# msg.send() |
||||||
|
# |
||||||
|
# |
||||||
@receiver(post_save, sender=Payment) |
# @receiver(post_save, sender=Payment) |
||||||
def access_pay(instance, **kwargs): |
# def access_pay(instance, **kwargs): |
||||||
if instance.status == 'success': |
# if instance.status == 'success': |
||||||
instance.invoice.status = "F" |
# instance.invoice.status = "F" |
||||||
instance.invoice.real_price = instance.shop_amount |
# instance.invoice.real_price = instance.shop_amount |
||||||
instance.invoice.save() |
# instance.invoice.save() |
||||||
|
# |
||||||
if instance.status == 'fail': |
# if instance.status == 'fail': |
||||||
instance.invoice.status = "C" |
# instance.invoice.status = "C" |
||||||
instance.invoice.save() |
# instance.invoice.save() |
||||||
|
|||||||
Loading…
Reference in new issue