From 940d075759741b2c7bcdee824990f0a60f90c458 Mon Sep 17 00:00:00 2001
From: gzbender
Date: Mon, 12 Aug 2019 23:31:54 +0300
Subject: [PATCH] =?UTF-8?q?=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86?=
=?UTF-8?q?=D0=B0=20=D1=81=20=D1=86=D0=B5=D0=BD=D0=B0=D0=BC=D0=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../notification/email/buy_email.html | 7 ++++-
apps/payment/models.py | 30 +++++++++++++++++++
.../payment/package_payment_success.html | 2 +-
apps/payment/views.py | 22 ++++++++++----
project/templates/lilcity/packages.html | 2 +-
project/urls.py | 6 +++-
project/utils/__init__.py | 4 +++
7 files changed, 64 insertions(+), 9 deletions(-)
diff --git a/apps/notification/templates/notification/email/buy_email.html b/apps/notification/templates/notification/email/buy_email.html
index 4e7c71dd..2e850d38 100644
--- a/apps/notification/templates/notification/email/buy_email.html
+++ b/apps/notification/templates/notification/email/buy_email.html
@@ -72,7 +72,12 @@
https://{% setting 'MAIN_HOST' %}{% url 'school:drawing-camp' %}
{% endif %}
{% endif %}
-Так же вы можете найти ссылку в личном кабинете в разделе «Мои покупки».
+
+ {% if product_type == 'package' %}
+ Вы приобрели подписку с {{ date_start|date:'j-m-y' }} по {{ date_end|date:'j-m-y'}}
+ {% else %}
+ Так же вы можете найти ссылку в личном кабинете в разделе «Мои покупки».
+ {% endif %}
Занимайтесь с удовольствием!
diff --git a/apps/payment/models.py b/apps/payment/models.py
index fdc84020..50b82801 100644
--- a/apps/payment/models.py
+++ b/apps/payment/models.py
@@ -23,6 +23,7 @@ from apps.course.models import Course
from apps.config.models import Config
from apps.school.models import SchoolSchedule
from apps.notification.utils import send_email
+from project.utils import dates_overlap
config = Config.load()
@@ -298,6 +299,35 @@ class Payment(PolymorphicModel):
self.weekdays = amount_data.get('weekdays')
super().save(*args, **kwargs)
if self.is_paid():
+ if isinstance(self, PackagePayment):
+ year_start = date(now().year, 1, 1)
+ year_end = date(now().year, 12, 31)
+ school_start = date(now().year, 9, 1)
+ school_end = date(now().year, 5, 31)
+ camp_start = date(now().year, 6, 1)
+ camp_end = date(now().year, 8, 31)
+ # TODO
+ if dates_overlap(self.date_start, self.date_end, camp_start, camp_end):
+ cp_amount_date = DrawingCampPayment.calc_amount()
+ DrawingCampPayment.objects.create(
+ user=self.user,
+ roistat_visit=self.roistat_visit,
+ date_start=self.date_start,
+ date_end=self.date_end,
+ amount=0,
+ status=self.status,
+ )
+ if dates_overlap(self.date_start, self.date_end, school_start, year_end)\
+ or dates_overlap(self.date_start, self.date_end, year_start, school_end):
+ SchoolPayment.objects.create(
+ user=self.user,
+ weekdays=[1, 2, 3, 4, 5, 6, 7],
+ roistat_visit=self.roistat_visit,
+ date_start=self.date_start,
+ date_end=self.date_end,
+ amount=0,
+ status=self.status,
+ )
if isinstance(self, CoursePayment):
if not getattr(self, 'authorbalance', None):
AuthorBalance.objects.create(
diff --git a/apps/payment/templates/payment/package_payment_success.html b/apps/payment/templates/payment/package_payment_success.html
index 9ad18b96..c4bb469a 100644
--- a/apps/payment/templates/payment/package_payment_success.html
+++ b/apps/payment/templates/payment/package_payment_success.html
@@ -4,7 +4,7 @@
Вы успешно приобрели подписку с {{ package.date_start }} по {{ package.date_end }}!
diff --git a/apps/payment/views.py b/apps/payment/views.py
index 6a542f73..c040aac6 100644
--- a/apps/payment/views.py
+++ b/apps/payment/views.py
@@ -297,6 +297,8 @@ class PaymentwallCallbackView(View):
product_payment_class = DrawingCampPayment
elif product_type_name == 'gift_certificate':
product_payment_class = GiftCertificatePayment
+ elif product_type_name == 'package':
+ product_payment_class = PackagePayment
else:
return HttpResponse(status=403)
@@ -363,6 +365,17 @@ class PaymentwallCallbackView(View):
'created_at': payment.created_at,
'update_at': payment.update_at,
}
+ elif product_type_name == 'package':
+ properties = {
+ 'payment_id': payment.id,
+ 'amount': payment.amount,
+ 'status': payment.status,
+ 'date_start': payment.date_start,
+ 'date_end': payment.date_end,
+ 'created_at': payment.created_at,
+ 'update_at': payment.update_at,
+ }
+
payment.save()
product_payment_to_mixpanel.delay(
@@ -392,6 +405,9 @@ class PaymentwallCallbackView(View):
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 product_type_name != 'package':
+ 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:
@@ -519,7 +535,7 @@ class PackagePaymentBuyView(TemplateView):
'demo': 1,
'test_mode': 1,
'success_url': host + str(
- reverse_lazy('gift-certificate-payment-success', args=[gift_certificate_payment.id])),
+ reverse_lazy('package-payment-success', args=[pp.id])),
'failure_url': host + str(reverse_lazy('payment-error')),
}
)
@@ -530,7 +546,3 @@ class PackagePaymentBuyView(TemplateView):
@method_decorator(login_required, name='dispatch')
class PackagePaymentBuySuccessView(TemplateView):
template_name = 'payment/package_payment_success.html'
-
- def get(self, request, pk=None, *args, **kwargs):
- course = get_object_or_404(Course, pk=pk)
- return self.render_to_response(context={'course': course})
diff --git a/project/templates/lilcity/packages.html b/project/templates/lilcity/packages.html
index ae624776..e668be98 100644
--- a/project/templates/lilcity/packages.html
+++ b/project/templates/lilcity/packages.html
@@ -23,7 +23,7 @@
{% endif %}
-
Включает
+
Включает:
{{ package.options_html|safe }}
diff --git a/project/urls.py b/project/urls.py
index a5fab3da..f82f0254 100644
--- a/project/urls.py
+++ b/project/urls.py
@@ -35,7 +35,8 @@ from apps.payment.views import (
CourseBuySuccessView, CourseBuyView,
PaymentwallCallbackView, SchoolBuySuccessView,
SchoolBuyView, GiftCertificatesView, GiftCertificateBuyView,
- GiftCertificateBuySuccessView, GiftCertificateGetView, DrawingCampBuyView)
+ GiftCertificateBuySuccessView, GiftCertificateGetView, DrawingCampBuyView, PackagePaymentBuySuccessView,
+ PackagePaymentBuyView)
from .views import AboutView, IndexView, SchoolSchedulesView, LinksView, PackagesView
@@ -104,6 +105,9 @@ urlpatterns = [
path('faq', FAQView.as_view(), name='faq'),
path('links', LinksView.as_view(), name='links'),
path('packages', PackagesView.as_view(), name='packages'),
+ path('package//checkout', PackagePaymentBuyView.as_view(), name='package-checkout'),
+ path('payments/package/success', PackagePaymentBuySuccessView.as_view(),
+ name='package-payment-success'),
]
diff --git a/project/utils/__init__.py b/project/utils/__init__.py
index 23234b58..4a4d24c3 100644
--- a/project/utils/__init__.py
+++ b/project/utils/__init__.py
@@ -15,3 +15,7 @@ def date_range(start, end):
def weekdays_in_date_range(start, end):
return Counter([d.isoweekday() for d in date_range(start, end)])
+
+
+def dates_overlap(start, end, start2, end2):
+ return start <= end2 and start2 <= end