From b16ca882c9fa9abc19a83854b4420ac0052c379e Mon Sep 17 00:00:00 2001 From: gzbender Date: Thu, 22 Aug 2019 19:16:50 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=BF=D0=BB=D0=B0=D1=82=D0=B0=20=D0=B1?= =?UTF-8?q?=D0=BE=D0=BD=D1=83=D1=81=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/payment/templates/payment/pay.html | 27 +++++++++++++++++++++---- apps/payment/views.py | 16 ++++++++++----- web/src/js/pages/pay.js | 11 ++++++++++ web/src/sass/_common.sass | 21 +++++++++++++++++++ web/webpack.config.js | 1 + 5 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 web/src/js/pages/pay.js diff --git a/apps/payment/templates/payment/pay.html b/apps/payment/templates/payment/pay.html index e25caa87..ec26e9ca 100644 --- a/apps/payment/templates/payment/pay.html +++ b/apps/payment/templates/payment/pay.html @@ -1,10 +1,29 @@ -{% extends "templates/lilcity/index.html" %} {% load static %} {% block content %} -{% if school and request.user.bonus %} +{% extends "templates/lilcity/index.html" %} +{% load static %} +{% load rupluralize from plural %} -{% endif %} +{% block content %}
- {% include "./paymentwall_widget.html" %} + {% if school and request.user.bonus and not payment.bonus %} + {% if request.user.bonus >= payment.amount %} + Оплатить бонусами +

или купить онлайн

+ {% else %} +

Для оплаты части стоимости вы можете использовать бонусы

+ + {% endif %} + {% endif %} +
+ {% include "./paymentwall_widget.html" %} +
{% endblock content %} + +{% block foot %} + +{% endblock foot %} diff --git a/apps/payment/views.py b/apps/payment/views.py index 688287c2..34eb6bc2 100644 --- a/apps/payment/views.py +++ b/apps/payment/views.py @@ -14,7 +14,7 @@ from django.http import HttpResponse, Http404 from django.shortcuts import redirect, get_object_or_404 from django.views.generic import View, TemplateView from django.views.decorators.csrf import csrf_exempt -from django.urls import reverse_lazy +from django.urls import reverse from django.utils.decorators import method_decorator from django.utils.timezone import now @@ -156,7 +156,7 @@ class SchoolBuyView(TemplateView): school_payment.bonus = bonus school_payment.save() if school_payment.is_paid(): - return redirect(reverse_lazy('payment-success')) + return redirect('%s?duration=%s' % (reverse('payment-success'), duration)) if payment_id and school_payment.bonus and not use_bonuses: bonus = school_payment.bonus school_payment.amount += school_payment.bonus @@ -178,11 +178,17 @@ class SchoolBuyView(TemplateView): 'evaluation': 1, 'demo': 1, 'test_mode': 1, - 'success_url': host + str(reverse_lazy('payment-success')) + '?duration=%s' % duration, - 'failure_url': host + str(reverse_lazy('payment-error')), + 'success_url': host + reverse('payment-success') + '?duration=%s' % duration, + 'failure_url': host + reverse('payment-error'), } ) - return self.render_to_response(context={'widget': widget.get_html_code()}) + if self.request.is_ajax(): + self.template_name = 'payment/paymentwall_widget.html' + return self.render_to_response(context={ + 'widget': widget.get_html_code({'height': '400'}), + 'school': True, + 'payment': school_payment, + }) @method_decorator(login_required, name='dispatch') diff --git a/web/src/js/pages/pay.js b/web/src/js/pages/pay.js new file mode 100644 index 00000000..ea217e10 --- /dev/null +++ b/web/src/js/pages/pay.js @@ -0,0 +1,11 @@ +import $ from 'jquery'; + +$(document).ready(function () { + const $useBonuses = $('#use-bonuses-checkbox input'); + const $widget = $('#pw-widget'); + $useBonuses.change(e => { + $.get($useBonuses.data('url') + '&use_bonuses=' + ($useBonuses.prop('checked') ? 1 : '')).then(response => { + $widget.html(response); + }); + }); +}); diff --git a/web/src/sass/_common.sass b/web/src/sass/_common.sass index badaeaf4..8c5ca684 100755 --- a/web/src/sass/_common.sass +++ b/web/src/sass/_common.sass @@ -5238,6 +5238,27 @@ a width: 24px margin-bottom: -6px + +.pw-widget + display: inline-block + position: relative + + &:before + content: ' ' + position: absolute + top: 30% + left: 50% + width: 50px + height: 50px + border-left: 3px solid transparent + border: 3px solid #B5B5B5 + border-right: none + border-top: none + border-bottom: none + z-index: -1 + border-radius: 50% + animation: loading .6s infinite linear + .mobile-hide +m display: none diff --git a/web/webpack.config.js b/web/webpack.config.js index afdec32d..24404936 100644 --- a/web/webpack.config.js +++ b/web/webpack.config.js @@ -17,6 +17,7 @@ module.exports = { liveLesson: "./src/js/pages/live-lesson.js", freeLessons: "./src/js/pages/free-lessons.js", userGalleryEdit: "./src/js/pages/user-gallery-edit.js", + pay: "./src/js/pages/pay.js", mixpanel: "./src/js/third_party/mixpanel-2-latest.js", sprite: glob('./src/icons/*.svg'), images: glob('./src/img/*.*'),