|
|
|
@ -4,7 +4,7 @@ import json |
|
|
|
import logging |
|
|
|
import logging |
|
|
|
|
|
|
|
|
|
|
|
from datetime import timedelta |
|
|
|
from datetime import timedelta |
|
|
|
from urllib.parse import urlsplit |
|
|
|
from urllib.parse import urljoin |
|
|
|
|
|
|
|
|
|
|
|
import datetime |
|
|
|
import datetime |
|
|
|
|
|
|
|
|
|
|
|
@ -41,6 +41,7 @@ class BuyMixin(object): |
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
roistat_visit = request.COOKIES.get('roistat_visit', None) |
|
|
|
roistat_visit = request.COOKIES.get('roistat_visit', None) |
|
|
|
use_bonuses = request.GET.get('use_bonuses') |
|
|
|
use_bonuses = request.GET.get('use_bonuses') |
|
|
|
|
|
|
|
payment_id = request.GET.get('payment_id') |
|
|
|
product_name = '' |
|
|
|
product_name = '' |
|
|
|
context = self.get_context_data(**kwargs) |
|
|
|
context = self.get_context_data(**kwargs) |
|
|
|
payment = None |
|
|
|
payment = None |
|
|
|
@ -48,10 +49,13 @@ class BuyMixin(object): |
|
|
|
if self.product_type == 'gift_certificate': |
|
|
|
if self.product_type == 'gift_certificate': |
|
|
|
gift_certificate = get_object_or_404(GiftCertificate, pk=kwargs.get('pk')) |
|
|
|
gift_certificate = get_object_or_404(GiftCertificate, pk=kwargs.get('pk')) |
|
|
|
|
|
|
|
|
|
|
|
payment = GiftCertificatePayment.objects.create( |
|
|
|
if payment_id: |
|
|
|
user=request.user, |
|
|
|
payment = GiftCertificatePayment.objects.get(pk=payment_id) |
|
|
|
gift_certificate=gift_certificate, |
|
|
|
else: |
|
|
|
roistat_visit=roistat_visit, ) |
|
|
|
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]) |
|
|
|
success_url = reverse('gift-certificate-payment-success', args=[payment.id]) |
|
|
|
product_name = 'Подарочный сертификат' |
|
|
|
product_name = 'Подарочный сертификат' |
|
|
|
@ -82,7 +86,6 @@ class BuyMixin(object): |
|
|
|
if self.product_type == 'school': |
|
|
|
if self.product_type == 'school': |
|
|
|
date_start = request.GET.get('date_start') |
|
|
|
date_start = request.GET.get('date_start') |
|
|
|
duration = request.GET.get('duration') |
|
|
|
duration = request.GET.get('duration') |
|
|
|
payment_id = request.GET.get('payment_id') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package = get_object_or_404(Package, duration=duration) |
|
|
|
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() |
|
|
|
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: |
|
|
|
if prev_payment and prev_payment.date_end > date_start: |
|
|
|
date_start = prev_payment.date_end + timedelta(1) |
|
|
|
date_start = prev_payment.date_end + timedelta(1) |
|
|
|
if payment_id: |
|
|
|
if payment_id: |
|
|
|
payment = get_object_or_404(SchoolPayment, id=payment_id) |
|
|
|
payment = SchoolPayment.objects.get(pk=payment_id) |
|
|
|
else: |
|
|
|
else: |
|
|
|
amount_data = SchoolPayment.calc_amount(package=package, user=request.user, date_start=date_start) |
|
|
|
amount_data = SchoolPayment.calc_amount(package=package, user=request.user, date_start=date_start) |
|
|
|
payment = SchoolPayment.objects.create( |
|
|
|
payment = SchoolPayment.objects.create( |
|
|
|
@ -103,11 +106,6 @@ class BuyMixin(object): |
|
|
|
date_end=amount_data.get('date_end'), |
|
|
|
date_end=amount_data.get('date_end'), |
|
|
|
package=package, |
|
|
|
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) |
|
|
|
success_url = '%s?duration=%s' % (reverse('payment-success'), duration) |
|
|
|
product_name = 'Подписка' |
|
|
|
product_name = 'Подписка' |
|
|
|
context['school'] = True |
|
|
|
context['school'] = True |
|
|
|
@ -116,28 +114,33 @@ class BuyMixin(object): |
|
|
|
date_start = request.GET.get('date_start') |
|
|
|
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_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) |
|
|
|
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, |
|
|
|
user=request.user, |
|
|
|
date_start__lte=date_start, |
|
|
|
date_start__lte=date_start, |
|
|
|
date_end__gte=date_start, |
|
|
|
date_end__gte=date_start, |
|
|
|
status__in=[ |
|
|
|
|
|
|
|
Pingback.PINGBACK_TYPE_REGULAR, |
|
|
|
|
|
|
|
Pingback.PINGBACK_TYPE_GOODWILL, |
|
|
|
|
|
|
|
Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
).exists() |
|
|
|
).exists() |
|
|
|
if prev_payment: |
|
|
|
if prev_payment: |
|
|
|
return HttpResponse(status=403) |
|
|
|
return HttpResponse(status=403) |
|
|
|
payment = DrawingCampPayment.objects.create( |
|
|
|
if payment_id: |
|
|
|
user=request.user, |
|
|
|
payment = DrawingCampPayment.objects.get(pk=payment_id) |
|
|
|
roistat_visit=roistat_visit, |
|
|
|
else: |
|
|
|
date_start=date_start, |
|
|
|
payment = DrawingCampPayment.objects.create( |
|
|
|
date_end=date_end, |
|
|
|
user=request.user, |
|
|
|
) |
|
|
|
roistat_visit=roistat_visit, |
|
|
|
|
|
|
|
date_start=date_start, |
|
|
|
|
|
|
|
date_end=date_end, |
|
|
|
|
|
|
|
) |
|
|
|
success_url = reverse('camp-payment-success') |
|
|
|
success_url = reverse('camp-payment-success') |
|
|
|
product_name = 'Подписка' |
|
|
|
product_name = 'Подписка' |
|
|
|
context['camp'] = True |
|
|
|
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 use_bonuses and request.user.bonus: |
|
|
|
if request.user.bonus >= payment.amount: |
|
|
|
if request.user.bonus >= payment.amount: |
|
|
|
bonus = UserBonus.objects.create(amount=-payment.amount, user=request.user, payment=payment) |
|
|
|
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: |
|
|
|
if request.user_agent.is_mobile: |
|
|
|
attrs['width'] = '100%' |
|
|
|
attrs['width'] = '100%' |
|
|
|
attrs['height'] = '600' |
|
|
|
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) |
|
|
|
return self.render_to_response(context) |
|
|
|
|
|
|
|
|
|
|
|
def after_buy(self, payment): |
|
|
|
def after_buy(self, payment): |
|
|
|
product_type_name = None |
|
|
|
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 = { |
|
|
|
properties = { |
|
|
|
'payment_id': payment.id, |
|
|
|
'payment_id': payment.id, |
|
|
|
'amount': payment.amount, |
|
|
|
'amount': payment.amount, |
|
|
|
@ -202,7 +206,12 @@ class BuyMixin(object): |
|
|
|
'created_at': payment.created_at, |
|
|
|
'created_at': payment.created_at, |
|
|
|
'update_at': payment.update_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 = { |
|
|
|
properties = { |
|
|
|
'payment_id': payment.id, |
|
|
|
'payment_id': payment.id, |
|
|
|
'amount': payment.amount, |
|
|
|
'amount': payment.amount, |
|
|
|
@ -214,7 +223,10 @@ class BuyMixin(object): |
|
|
|
'created_at': payment.created_at, |
|
|
|
'created_at': payment.created_at, |
|
|
|
'update_at': payment.update_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 = { |
|
|
|
properties = { |
|
|
|
'payment_id': payment.id, |
|
|
|
'payment_id': payment.id, |
|
|
|
'amount': payment.amount, |
|
|
|
'amount': payment.amount, |
|
|
|
@ -224,7 +236,10 @@ class BuyMixin(object): |
|
|
|
'created_at': payment.created_at, |
|
|
|
'created_at': payment.created_at, |
|
|
|
'update_at': payment.update_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 = { |
|
|
|
properties = { |
|
|
|
'payment_id': payment.id, |
|
|
|
'payment_id': payment.id, |
|
|
|
'amount': payment.amount, |
|
|
|
'amount': payment.amount, |
|
|
|
@ -233,6 +248,8 @@ class BuyMixin(object): |
|
|
|
'created_at': payment.created_at, |
|
|
|
'created_at': payment.created_at, |
|
|
|
'update_at': payment.update_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( |
|
|
|
product_payment_to_mixpanel.delay( |
|
|
|
payment.user.id, |
|
|
|
payment.user.id, |
|
|
|
@ -252,18 +269,6 @@ class BuyMixin(object): |
|
|
|
payment.roistat_visit, |
|
|
|
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) |
|
|
|
author_balance = getattr(payment, 'author_balance', None) |
|
|
|
if author_balance and author_balance.type == AuthorBalance.IN: |
|
|
|
if author_balance and author_balance.type == AuthorBalance.IN: |
|
|
|
if payment.is_deliverable(): |
|
|
|
if payment.is_deliverable(): |
|
|
|
|