|
|
|
|
@ -4,7 +4,7 @@ import json |
|
|
|
|
import logging |
|
|
|
|
|
|
|
|
|
from datetime import timedelta |
|
|
|
|
from urllib.parse import urlsplit |
|
|
|
|
from urllib.parse import urlsplit, urlencode |
|
|
|
|
|
|
|
|
|
import datetime |
|
|
|
|
|
|
|
|
|
@ -37,22 +37,28 @@ class DisallowedPingbackHost(Exception): |
|
|
|
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch') |
|
|
|
|
class CourseBuySuccessView(TemplateView): |
|
|
|
|
template_name = 'payment/course_payment_success.html' |
|
|
|
|
template_name = 'payment/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}) |
|
|
|
|
def get(self, request, payment_id, *args, **kwargs): |
|
|
|
|
payment = CoursePayment.objects.get(pk=payment_id) |
|
|
|
|
course = payment.course |
|
|
|
|
return self.render_to_response(context={'course': course, 'payment': payment}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch') |
|
|
|
|
class SchoolBuySuccessView(TemplateView): |
|
|
|
|
template_name = 'payment/payment_success.html' |
|
|
|
|
|
|
|
|
|
def get(self, request, pk=None, is_camp=False, *args, **kwargs): |
|
|
|
|
def get(self, request, payment_id, is_camp=False, *args, **kwargs): |
|
|
|
|
if is_camp: |
|
|
|
|
payment = DrawingCampPayment.objects.get(pk=payment_id) |
|
|
|
|
else: |
|
|
|
|
payment = SchoolPayment.objects.get(pk=payment_id) |
|
|
|
|
context = { |
|
|
|
|
'duration': request.GET.get('duration'), |
|
|
|
|
'camp': is_camp, |
|
|
|
|
'school': not is_camp |
|
|
|
|
'school': not is_camp, |
|
|
|
|
'payment': payment, |
|
|
|
|
} |
|
|
|
|
return self.render_to_response(context=context) |
|
|
|
|
|
|
|
|
|
@ -93,7 +99,7 @@ class CourseBuyView(TemplateView): |
|
|
|
|
course_payment.bonus = bonus |
|
|
|
|
course_payment.save() |
|
|
|
|
if course_payment.is_paid(): |
|
|
|
|
return redirect(reverse_lazy('course_payment_success', args=[course.id])) |
|
|
|
|
return redirect(reverse_lazy('course_payment_success', args=[course_payment.id])) |
|
|
|
|
product = Product( |
|
|
|
|
f'course_{course_payment.id}', |
|
|
|
|
course_payment.amount, |
|
|
|
|
@ -110,7 +116,7 @@ class CourseBuyView(TemplateView): |
|
|
|
|
'evaluation': 1, |
|
|
|
|
'demo': 1, |
|
|
|
|
'test_mode': 1, |
|
|
|
|
'success_url': host + str(reverse_lazy('course_payment_success', args=[course.id])), |
|
|
|
|
'success_url': host + str(reverse_lazy('course_payment_success', args=[course_payment.id])), |
|
|
|
|
'failure_url': host + str(reverse_lazy('payment-error')), |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
@ -118,7 +124,11 @@ class CourseBuyView(TemplateView): |
|
|
|
|
if request.user_agent.is_mobile: |
|
|
|
|
attrs['width'] = '100%' |
|
|
|
|
attrs['height'] = '600' |
|
|
|
|
return self.render_to_response(context={'widget': widget.get_html_code(attrs)}) |
|
|
|
|
return self.render_to_response(context={ |
|
|
|
|
'widget': widget.get_html_code(attrs), |
|
|
|
|
'payment': course_payment, |
|
|
|
|
'course': course, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch') |
|
|
|
|
@ -159,7 +169,7 @@ class SchoolBuyView(TemplateView): |
|
|
|
|
school_payment.bonus = bonus |
|
|
|
|
school_payment.save() |
|
|
|
|
if school_payment.is_paid(): |
|
|
|
|
return redirect('%s?duration=%s' % (str(reverse_lazy('payment-success')), duration)) |
|
|
|
|
return redirect('%s?duration=%s' % (str(reverse_lazy('payment-success', args=[school_payment.id])), duration)) |
|
|
|
|
if payment_id and school_payment.bonus and not use_bonuses: |
|
|
|
|
bonus = school_payment.bonus |
|
|
|
|
school_payment.amount += school_payment.bonus |
|
|
|
|
@ -181,7 +191,7 @@ class SchoolBuyView(TemplateView): |
|
|
|
|
'evaluation': 1, |
|
|
|
|
'demo': 1, |
|
|
|
|
'test_mode': 1, |
|
|
|
|
'success_url': host + str(reverse_lazy('payment-success')) + '?duration=%s' % duration, |
|
|
|
|
'success_url': host + str(reverse_lazy('payment-success', args=[school_payment.id])) + '?duration=%s' % duration, |
|
|
|
|
'failure_url': host + str(reverse_lazy('payment-error')), |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
@ -241,7 +251,7 @@ class DrawingCampBuyView(TemplateView): |
|
|
|
|
camp_payment.bonus = bonus |
|
|
|
|
camp_payment.save() |
|
|
|
|
if camp_payment.is_paid(): |
|
|
|
|
return redirect(reverse_lazy('camp-payment-success')) |
|
|
|
|
return redirect(reverse_lazy('camp-payment-success', args=[camp_payment.id])) |
|
|
|
|
product = Product( |
|
|
|
|
f'drawing_camp_{camp_payment.id}', |
|
|
|
|
camp_payment.amount, |
|
|
|
|
@ -258,7 +268,7 @@ class DrawingCampBuyView(TemplateView): |
|
|
|
|
'evaluation': 1, |
|
|
|
|
'demo': 1, |
|
|
|
|
'test_mode': 1, |
|
|
|
|
'success_url': host + str(reverse_lazy('camp-payment-success')), |
|
|
|
|
'success_url': host + str(reverse_lazy('camp-payment-success', args=[camp_payment.id])), |
|
|
|
|
'failure_url': host + str(reverse_lazy('payment-error')), |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
@ -266,7 +276,11 @@ class DrawingCampBuyView(TemplateView): |
|
|
|
|
if request.user_agent.is_mobile: |
|
|
|
|
attrs['width'] = '100%' |
|
|
|
|
attrs['height'] = '600' |
|
|
|
|
return self.render_to_response(context={'widget': widget.get_html_code(attrs)}) |
|
|
|
|
return self.render_to_response(context={ |
|
|
|
|
'widget': widget.get_html_code(attrs), |
|
|
|
|
'payment': camp_payment, |
|
|
|
|
'camp': True, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(csrf_exempt, name='dispatch') |
|
|
|
|
@ -427,10 +441,25 @@ class GiftCertificateBuyView(TemplateView): |
|
|
|
|
def get(self, request, pk, *args, **kwargs): |
|
|
|
|
gift_certificate = get_object_or_404(GiftCertificate, pk=pk) |
|
|
|
|
roistat_visit = request.COOKIES.get('roistat_visit', None) |
|
|
|
|
use_bonuses = request.GET.get('use_bonuses') |
|
|
|
|
gift_certificate_payment = GiftCertificatePayment.objects.create( |
|
|
|
|
user=request.user, |
|
|
|
|
gift_certificate=gift_certificate, |
|
|
|
|
roistat_visit=roistat_visit,) |
|
|
|
|
if use_bonuses and request.user.bonus: |
|
|
|
|
if request.user.bonus >= gift_certificate_payment.amount: |
|
|
|
|
bonus = UserBonus.objects.create(amount=-gift_certificate_payment.amount, user=request.user, |
|
|
|
|
payment=gift_certificate_payment) |
|
|
|
|
gift_certificate_payment.amount = 0 |
|
|
|
|
gift_certificate_payment.status = Pingback.PINGBACK_TYPE_REGULAR |
|
|
|
|
else: |
|
|
|
|
bonus = UserBonus.objects.create(amount=-request.user.bonus, user=request.user, |
|
|
|
|
payment=gift_certificate_payment) |
|
|
|
|
gift_certificate_payment.amount -= request.user.bonus |
|
|
|
|
gift_certificate_payment.bonus = bonus |
|
|
|
|
gift_certificate_payment.save() |
|
|
|
|
if gift_certificate_payment.is_paid(): |
|
|
|
|
return redirect(reverse_lazy('gift-certificate-payment-success', args=[gift_certificate_payment.id])) |
|
|
|
|
context = self.get_context_data(**kwargs) |
|
|
|
|
product = Product( |
|
|
|
|
f'gift_certificate_{gift_certificate_payment.id}', |
|
|
|
|
@ -458,19 +487,24 @@ class GiftCertificateBuyView(TemplateView): |
|
|
|
|
attrs['width'] = '100%' |
|
|
|
|
attrs['height'] = '600' |
|
|
|
|
context['widget'] = widget.get_html_code(attrs) |
|
|
|
|
context['payment'] = gift_certificate_payment |
|
|
|
|
context['gift_certificate'] = gift_certificate |
|
|
|
|
return self.render_to_response(context) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch') |
|
|
|
|
class GiftCertificateBuySuccessView(TemplateView): |
|
|
|
|
template_name = 'payment/gift_certificate_payment_success.html' |
|
|
|
|
template_name = 'payment/payment_success.html' |
|
|
|
|
|
|
|
|
|
def get(self, request, payment_id=None, *args, **kwargs): |
|
|
|
|
def get(self, request, payment_id, *args, **kwargs): |
|
|
|
|
try: |
|
|
|
|
GiftCertificatePayment.objects.get(id=payment_id) |
|
|
|
|
payment = GiftCertificatePayment.objects.get(id=payment_id) |
|
|
|
|
except: |
|
|
|
|
raise Http404() |
|
|
|
|
return self.render_to_response(context={'gift_certificate': True}) |
|
|
|
|
return self.render_to_response(context={ |
|
|
|
|
'gift_certificate': payment.gift_certificate, |
|
|
|
|
'payment': payment, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch') |
|
|
|
|
|