diff --git a/apps/notification/tasks.py b/apps/notification/tasks.py
index 8251b128..b30530f1 100644
--- a/apps/notification/tasks.py
+++ b/apps/notification/tasks.py
@@ -239,7 +239,7 @@ def send_camp_certificates(email=None, dry_run=False, certificate_number=None):
def send_course_access_expire_email(days=None):
if days is None:
days = 30
- payments = CoursePayment.objects.paid().filter(access_expire=now() + timedelta(days - 1), created_at__lte=now() - timedelta(10))
+ payments = CoursePayment.objects.paid().filter(access_expire__lte=now() + timedelta(days - 1), created_at__lte=now() - timedelta(10))
for payment in payments:
cn, created = CourseNotification.objects.get_or_create(course=payment.course, user=payment.user)
if not created and cn.access_expire_last_email and cn.access_expire_last_email.date() >= now().date() - timedelta(days):
diff --git a/apps/notification/templates/notification/email/buy_email.html b/apps/notification/templates/notification/email/buy_email.html
index fb4393df..742379c4 100644
--- a/apps/notification/templates/notification/email/buy_email.html
+++ b/apps/notification/templates/notification/email/buy_email.html
@@ -1,24 +1,25 @@
{% extends "notification/email/_base.html" %}
{% load rupluralize from plural %}
+{% load settings %}
{% block content %}
{% if product_type == 'course' %}
Добрый день, {{ username }}!
Вы приобрели видеокурс «{{ course_title }}». Спасибо за покупку!
Обратите внимание, что доступ к курсу действует {{ access_duration | rupluralize:'день,дня,дней' }}. Этого должно хватить, чтобы пройти его.
- Если вы не успеете, то по окончании этого срока система автоматически предложит вам продлить доступ к курсу за 50% от его стоимости./p>
+ Если вы не успеете, то по окончании этого срока система автоматически предложит вам продлить доступ к курсу за 50% от его стоимости.
Найти курс можно в вашем личном кабинете на платформе.
-
- https://{{ settings.MAIN_HOST }}{{ url }}
+
+ https://{% setting 'MAIN_HOST' %}{{ url }}
Все ваши покупки будут храниться там в рамках срока доступа к курсу.
{% endif %}
{% if product_type == 'school' %}
Добрый день! Спасибо за покупку знаний в «Lil School»!
Где искать уроки?
После оплаты уроки появятся в вашем личном кабинете на платформе.
-
- https://{{ settings.MAIN_HOST }}{% url 'school:school' %}
- В онлайн-школе урок хранится неделю. Ровно до следующего урока.
+
+ https://{% setting 'MAIN_HOST' %}{% url 'school:school' %}
+ В онлайн-школе урок хранится неделю. Ровно до следующего урока. Либо месяц при покупке подписки на год.
{% endif %}
{% if product_type == 'drawing_camp' %}
{% if date_start.month == 7 and date_start.day == 1 and date_end.day == 31 %}
@@ -78,8 +79,8 @@
Обязательно делитесь своими впечатлениями и работами, отмечая их хэштегом #lil_summer. Спасибо, что вы с нами!
{% else %}
- Рисовальный лагерь ждет вас по ссылке
- https://{{ settings.MAIN_HOST }}{% url 'school:drawing-camp' %}
+ Рисовальный лагерь ждет вас по ссылке
+ https://{% setting 'MAIN_HOST' %}{% url 'school:drawing-camp' %}
{% endif %}
{% endif %}
diff --git a/apps/payment/templates/payment/pay.html b/apps/payment/templates/payment/pay.html
index ec26e9ca..b12f7f34 100644
--- a/apps/payment/templates/payment/pay.html
+++ b/apps/payment/templates/payment/pay.html
@@ -12,7 +12,7 @@
{% else %}
Для оплаты части стоимости вы можете использовать бонусы
-
+
Использовать {{ request.user.bonus|rupluralize:'бонус,бонуса,бонусов' }}
{% endif %}
diff --git a/apps/payment/views.py b/apps/payment/views.py
index 54bbfef1..483e3e31 100644
--- a/apps/payment/views.py
+++ b/apps/payment/views.py
@@ -4,7 +4,7 @@ import json
import logging
from datetime import timedelta
-from urllib.parse import urlsplit
+from urllib.parse import urljoin
import datetime
@@ -41,6 +41,7 @@ class BuyMixin(object):
def get(self, request, *args, **kwargs):
roistat_visit = request.COOKIES.get('roistat_visit', None)
use_bonuses = request.GET.get('use_bonuses')
+ payment_id = request.GET.get('payment_id')
product_name = ''
context = self.get_context_data(**kwargs)
payment = None
@@ -48,10 +49,13 @@ class BuyMixin(object):
if self.product_type == 'gift_certificate':
gift_certificate = get_object_or_404(GiftCertificate, pk=kwargs.get('pk'))
- payment = GiftCertificatePayment.objects.create(
- user=request.user,
- gift_certificate=gift_certificate,
- roistat_visit=roistat_visit, )
+ if payment_id:
+ payment = GiftCertificatePayment.objects.get(pk=payment_id)
+ else:
+ payment = GiftCertificatePayment.objects.create(
+ user=request.user,
+ gift_certificate=gift_certificate,
+ roistat_visit=roistat_visit, )
success_url = reverse('gift-certificate-payment-success', args=[payment.id])
product_name = 'Подарочный сертификат'
@@ -82,7 +86,6 @@ class BuyMixin(object):
if self.product_type == 'school':
date_start = request.GET.get('date_start')
duration = request.GET.get('duration')
- payment_id = request.GET.get('payment_id')
package = get_object_or_404(Package, duration=duration)
date_start = date_start and datetime.datetime.strptime(date_start, '%Y-%m-%d').date() or now().date()
@@ -92,7 +95,7 @@ class BuyMixin(object):
if prev_payment and prev_payment.date_end > date_start:
date_start = prev_payment.date_end + timedelta(1)
if payment_id:
- payment = get_object_or_404(SchoolPayment, id=payment_id)
+ payment = SchoolPayment.objects.get(pk=payment_id)
else:
amount_data = SchoolPayment.calc_amount(package=package, user=request.user, date_start=date_start)
payment = SchoolPayment.objects.create(
@@ -103,11 +106,6 @@ class BuyMixin(object):
date_end=amount_data.get('date_end'),
package=package,
)
- if payment_id and payment.bonus and not use_bonuses:
- bonus = payment.bonus
- payment.amount += payment.bonus
- payment.bonus = None
- bonus.delete()
success_url = '%s?duration=%s' % (reverse('payment-success'), duration)
product_name = 'Подписка'
context['school'] = True
@@ -116,28 +114,33 @@ class BuyMixin(object):
date_start = request.GET.get('date_start')
date_start = date_start and datetime.datetime.strptime(date_start, '%Y-%m-%d').date() or now().date()
date_start, date_end = Payment.get_date_range(date_start, months=1, is_camp=True)
- prev_payment = DrawingCampPayment.objects.filter(
+ prev_payment = DrawingCampPayment.objects.paid().filter(
user=request.user,
date_start__lte=date_start,
date_end__gte=date_start,
- status__in=[
- Pingback.PINGBACK_TYPE_REGULAR,
- Pingback.PINGBACK_TYPE_GOODWILL,
- Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED,
- ],
).exists()
if prev_payment:
return HttpResponse(status=403)
- payment = DrawingCampPayment.objects.create(
- user=request.user,
- roistat_visit=roistat_visit,
- date_start=date_start,
- date_end=date_end,
- )
+ if payment_id:
+ payment = DrawingCampPayment.objects.get(pk=payment_id)
+ else:
+ payment = DrawingCampPayment.objects.create(
+ user=request.user,
+ roistat_visit=roistat_visit,
+ date_start=date_start,
+ date_end=date_end,
+ )
success_url = reverse('camp-payment-success')
product_name = 'Подписка'
context['camp'] = True
+ if payment_id and payment.bonus and not use_bonuses:
+ bonus = payment.bonus
+ payment.amount -= payment.bonus.amount
+ payment.bonus = None
+ payment.save()
+ bonus.delete()
+
if use_bonuses and request.user.bonus:
if request.user.bonus >= payment.amount:
bonus = UserBonus.objects.create(amount=-payment.amount, user=request.user, payment=payment)
@@ -179,21 +182,22 @@ class BuyMixin(object):
if request.user_agent.is_mobile:
attrs['width'] = '100%'
attrs['height'] = '600'
- context['widget'] = widget.get_html_code(attrs)
+ query = request.GET.copy()
+ if 'use_bonuses' in query:
+ query.pop('use_bonuses')
+ query['payment_id'] = payment.id
+ context.update({
+ 'widget': widget.get_html_code(attrs),
+ 'payment': payment,
+ 'bonuses_url': '?'.join([request.path, query.urlencode()]),
+ })
return self.render_to_response(context)
def after_buy(self, payment):
product_type_name = None
- if isinstance(payment, CoursePayment):
- product_type_name == 'course'
- elif isinstance(payment, SchoolPayment):
- product_type_name == 'school'
- elif isinstance(payment, DrawingCampPayment):
- product_type_name == 'drawing_camp'
- elif isinstance(payment, GiftCertificatePayment):
- product_type_name == 'gift_certificate'
- if product_type_name == 'course':
+ if isinstance(payment, CoursePayment):
+ product_type_name = 'course'
properties = {
'payment_id': payment.id,
'amount': payment.amount,
@@ -202,7 +206,12 @@ class BuyMixin(object):
'created_at': payment.created_at,
'update_at': payment.update_at,
}
- elif product_type_name == 'school':
+ send_email.delay('Спасибо за покупку!', payment.user.email, 'notification/email/buy_email.html',
+ product_type=product_type_name, url=payment.course.url,
+ username=payment.user.get_full_name(), course_title=payment.course.title,
+ access_duration=payment.access_duration)
+ elif isinstance(payment, SchoolPayment):
+ product_type_name = 'school'
properties = {
'payment_id': payment.id,
'amount': payment.amount,
@@ -214,7 +223,10 @@ class BuyMixin(object):
'created_at': payment.created_at,
'update_at': payment.update_at,
}
- elif product_type_name == 'drawing_camp':
+ send_email.delay('Спасибо за покупку!', payment.user.email, 'notification/email/buy_email.html',
+ product_type=product_type_name, date_start=payment.date_start, date_end=payment.date_end)
+ elif isinstance(payment, DrawingCampPayment):
+ product_type_name = 'drawing_camp'
properties = {
'payment_id': payment.id,
'amount': payment.amount,
@@ -224,7 +236,10 @@ class BuyMixin(object):
'created_at': payment.created_at,
'update_at': payment.update_at,
}
- elif product_type_name == 'gift_certificate':
+ send_email.delay('Спасибо за покупку!', payment.user.email, 'notification/email/buy_email.html',
+ product_type=product_type_name)
+ elif isinstance(payment, GiftCertificatePayment):
+ product_type_name = 'gift_certificate'
properties = {
'payment_id': payment.id,
'amount': payment.amount,
@@ -233,6 +248,8 @@ class BuyMixin(object):
'created_at': payment.created_at,
'update_at': payment.update_at,
}
+ send_email.delay('Спасибо за покупку!', payment.user.email, 'notification/email/buy_email.html',
+ product_type=product_type_name)
product_payment_to_mixpanel.delay(
payment.user.id,
@@ -252,18 +269,6 @@ class BuyMixin(object):
payment.roistat_visit,
)
- if product_type_name == 'course':
- send_email.delay('Спасибо за покупку!', payment.user.email, 'notification/email/buy_email.html',
- product_type=product_type_name, url=payment.course.url,
- username=payment.user.get_full_name(), course_title=payment.course.title,
- access_duration=payment.access_duration)
- elif product_type_name != 'school':
- send_email.delay('Спасибо за покупку!', payment.user.email, 'notification/email/buy_email.html',
- product_type=product_type_name)
- elif product_type_name != 'drawing_camp':
- send_email.delay('Спасибо за покупку!', payment.user.email, 'notification/email/buy_email.html',
- product_type=product_type_name, date_start=payment.date_start, date_end=payment.date_end)
-
author_balance = getattr(payment, 'author_balance', None)
if author_balance and author_balance.type == AuthorBalance.IN:
if payment.is_deliverable():