|
|
|
|
@ -2,20 +2,21 @@ |
|
|
|
|
import json |
|
|
|
|
import hashlib |
|
|
|
|
|
|
|
|
|
from django.shortcuts import render, redirect |
|
|
|
|
from django.shortcuts import render, redirect, get_object_or_404 |
|
|
|
|
from django.http import Http404, HttpResponseRedirect, HttpResponseForbidden, HttpResponse |
|
|
|
|
from django.conf import settings |
|
|
|
|
from django.views.decorators.csrf import csrf_exempt |
|
|
|
|
from django.utils.http import urlquote |
|
|
|
|
from django.contrib.auth.decorators import login_required |
|
|
|
|
from django.template.response import TemplateResponse |
|
|
|
|
from django.core.urlresolvers import reverse |
|
|
|
|
from django.views.decorators.csrf import csrf_protect |
|
|
|
|
from django.conf import settings |
|
|
|
|
|
|
|
|
|
from yandex_money.models import Payment |
|
|
|
|
|
|
|
|
|
from project.customer import consts |
|
|
|
|
|
|
|
|
|
from ..models import License, LicensePrice |
|
|
|
|
from ..consts import PAYFORMS |
|
|
|
|
from ..forms import LicenseForm, YaForm |
|
|
|
|
from ..utils import raise_if_no_profile |
|
|
|
|
|
|
|
|
|
@ -24,13 +25,15 @@ from ..utils import raise_if_no_profile |
|
|
|
|
@csrf_protect |
|
|
|
|
def yandex_pay(request, payment_id): |
|
|
|
|
template_name = 'customer/profile/yandex.html' |
|
|
|
|
payment = Payment.objects.get(id=payment_id) |
|
|
|
|
|
|
|
|
|
payment = Payment.objects.get(pk=payment_id) |
|
|
|
|
|
|
|
|
|
if payment.user != request.user: |
|
|
|
|
raise Exception(u'[yandex_pay error] Different users! | payment.user_id = %d ; request.user_id = %d' % (payment.user_id, request.user.pk,)) |
|
|
|
|
|
|
|
|
|
form = YaForm(instance=payment) |
|
|
|
|
return render(request, template_name, {'form': form, |
|
|
|
|
'ya_url': settings.YANDEX_MONEY_PAYMENT_URL}) |
|
|
|
|
|
|
|
|
|
return render(request, template_name, {'form': form, 'ya_url': settings.YANDEX_MONEY_PAYMENT_URL}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required |
|
|
|
|
@ -41,34 +44,50 @@ def order_license(request): |
|
|
|
|
raise_if_no_profile(request) |
|
|
|
|
|
|
|
|
|
template_name = 'customer/profile/license.html' |
|
|
|
|
form = LicenseForm(request.POST or None, |
|
|
|
|
initial = {'term': LicensePrice.objects.all()[1], 'payform': 0}) |
|
|
|
|
dictionary = { |
|
|
|
|
'form': form, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# срок лицензии. по умолчанию, 6 месяцев |
|
|
|
|
# TODO don't use the magic index `1`. maybe add field to LicensePrice model to mark the default record via admin |
|
|
|
|
term_default = LicensePrice.objects.all()[1] |
|
|
|
|
|
|
|
|
|
form = LicenseForm( |
|
|
|
|
request.POST or None, |
|
|
|
|
initial = { |
|
|
|
|
'term': term_default, |
|
|
|
|
'payform': consts.PAYFORM_BEZNAL, |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if form.is_valid(): |
|
|
|
|
new_license = License(company=request.user.profile, |
|
|
|
|
term=form.cleaned_data['term'].term, |
|
|
|
|
payform=form.cleaned_data['payform'], |
|
|
|
|
pay_sum=form.cleaned_data['term'].price, |
|
|
|
|
) |
|
|
|
|
_payform = int(form.cleaned_data['payform']) |
|
|
|
|
|
|
|
|
|
new_license = License( |
|
|
|
|
company = request.user.profile, |
|
|
|
|
term = form.cleaned_data['term'].term, |
|
|
|
|
payform = _payform, |
|
|
|
|
pay_sum = form.cleaned_data['term'].price, |
|
|
|
|
) |
|
|
|
|
new_license.save() |
|
|
|
|
if form.cleaned_data['payform'] == '1': |
|
|
|
|
payment, _ = Payment.objects.get_or_create(order_amount=form.cleaned_data['term'].price, |
|
|
|
|
payment_type=Payment.PAYMENT_TYPE.AC, |
|
|
|
|
order_number=new_license.id, |
|
|
|
|
) |
|
|
|
|
payment.user=request.user |
|
|
|
|
# payment.cps_email=request.user.email |
|
|
|
|
payment.customer_number=request.user.email |
|
|
|
|
# payment.customer_number=request.user.profile.get_company_name().strip() |
|
|
|
|
|
|
|
|
|
if _payform == consts.PAYFORM_CARD: |
|
|
|
|
payment, _ = Payment.objects.get_or_create( |
|
|
|
|
order_amount = form.cleaned_data['term'].price, |
|
|
|
|
payment_type = Payment.PAYMENT_TYPE.AC, |
|
|
|
|
order_number = new_license.pk, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
payment.user = request.user |
|
|
|
|
# payment.cps_email = request.user.email |
|
|
|
|
payment.customer_number = request.user.email |
|
|
|
|
# payment.customer_number = request.user.profile.get_company_name().strip() |
|
|
|
|
|
|
|
|
|
payment.save() |
|
|
|
|
return redirect(reverse('yamoney_confirm', kwargs={'payment_id': payment.id})) |
|
|
|
|
|
|
|
|
|
return redirect(reverse('yamoney_confirm', kwargs={'payment_id': payment.pk})) |
|
|
|
|
|
|
|
|
|
return redirect(reverse('customer_license_list')) |
|
|
|
|
|
|
|
|
|
return render(request, template_name, dictionary) |
|
|
|
|
return render(request, template_name, {'form': form}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required |
|
|
|
|
def license_list(request): |
|
|
|
|
@ -77,11 +96,11 @@ def license_list(request): |
|
|
|
|
raise_if_no_profile(request) |
|
|
|
|
|
|
|
|
|
template_name = 'customer/profile/license_list.html' |
|
|
|
|
licenses = License.objects.filter(company=request.user.profile, deleted=False, status__gt=-1).order_by('-id') |
|
|
|
|
dictionary = { |
|
|
|
|
'licenses': licenses, |
|
|
|
|
} |
|
|
|
|
return render(request, template_name, dictionary) |
|
|
|
|
|
|
|
|
|
# TODO maybe explicitly list license statuses? |
|
|
|
|
licenses = License.objects.filter(company=request.user.profile, status__gt=consts.LICENSE_TEST_PERIOD, deleted=False).order_by('-id') |
|
|
|
|
|
|
|
|
|
return render(request, template_name, {'licenses': licenses}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required |
|
|
|
|
@ -91,12 +110,20 @@ def paid_list(request): |
|
|
|
|
raise_if_no_profile(request) |
|
|
|
|
|
|
|
|
|
template_name = 'customer/profile/paid_list.html' |
|
|
|
|
licenses = License.objects.filter(company=request.user.profile, |
|
|
|
|
status__in=[-1, 1, 2, 3, 4], deleted=False).order_by('-id') |
|
|
|
|
dictionary = { |
|
|
|
|
'licenses': licenses, |
|
|
|
|
} |
|
|
|
|
return render(request, template_name, dictionary) |
|
|
|
|
|
|
|
|
|
licenses = License.objects.filter( |
|
|
|
|
company=request.user.profile, |
|
|
|
|
status__in = [ |
|
|
|
|
consts.LICENSE_TEST_PERIOD, |
|
|
|
|
consts.LICENSE_PAID, |
|
|
|
|
consts.LICENSE_ACTIVE, |
|
|
|
|
consts.LICENSE_EXPIRED, |
|
|
|
|
consts.LICENSE_SUSPENDED, |
|
|
|
|
], |
|
|
|
|
deleted=False |
|
|
|
|
).order_by('-id') |
|
|
|
|
|
|
|
|
|
return render(request, template_name, {'licenses': licenses}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required |
|
|
|
|
@ -107,7 +134,7 @@ def delete_license(request, pk): |
|
|
|
|
raise_if_no_profile(request) |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
license = License.objects.get(pk=pk, status=0, company=request.user.profile) |
|
|
|
|
license = License.objects.get(pk=pk, status=consts.LICENSE_UNPAID, company=request.user.profile) |
|
|
|
|
if request.method == 'POST': |
|
|
|
|
license.deleted = True |
|
|
|
|
license.save() |
|
|
|
|
@ -143,19 +170,12 @@ def delete_license(request, pk): |
|
|
|
|
@csrf_exempt |
|
|
|
|
def payment_success(request): |
|
|
|
|
nInvId = request.GET.get('orderNumber') |
|
|
|
|
order = License.objects.get(pk=nInvId) |
|
|
|
|
|
|
|
|
|
order = get_object_or_404(License, pk=nInvId) |
|
|
|
|
context = {'success': True, 'order_num': nInvId} |
|
|
|
|
return TemplateResponse(request, 'customer/profile/end_order.html', context) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt |
|
|
|
|
def payment_fail(request): |
|
|
|
|
try: |
|
|
|
|
nInvId = request.GET.get('') |
|
|
|
|
|
|
|
|
|
message = u"Возникла проблема. Ваш Заказ не оплачен. Попробуйте оформить заявку снова, или позвоните по номеру." |
|
|
|
|
|
|
|
|
|
return TemplateResponse(request, 'customer/profile/end_order.html', {'message': message, 'success': False}) |
|
|
|
|
except Order.DoesNotExist: |
|
|
|
|
return HttpResponseForbidden() |
|
|
|
|
message = u"Возникла проблема. Ваш Заказ не оплачен. Попробуйте оформить заявку снова, или позвоните по номеру." |
|
|
|
|
return TemplateResponse(request, 'customer/profile/end_order.html', {'message': message, 'success': False}) |
|
|
|
|
|