You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
5.0 KiB
143 lines
5.0 KiB
# -*- coding: utf-8 -*-
|
|
import hashlib
|
|
|
|
from django.shortcuts import render, redirect
|
|
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 ..models import License, LicensePrice
|
|
from ..consts import PAYFORMS
|
|
from ..forms import LicenseForm
|
|
|
|
|
|
@login_required
|
|
@csrf_protect
|
|
def order_license(request):
|
|
"""заказ лицензии
|
|
"""
|
|
template_name = 'customer/profile/license.html'
|
|
form = LicenseForm(request.POST or None,
|
|
initial = {'term': LicensePrice.objects.all()[1], 'payform': 0})
|
|
dictionary = {
|
|
'form': form,
|
|
}
|
|
|
|
if form.is_valid():
|
|
new_license = License(user=request.user,
|
|
term=form.cleaned_data['term'].term,
|
|
payform=form.cleaned_data['payform'],
|
|
pay_sum=form.cleaned_data['term'].price,
|
|
)
|
|
new_license.save()
|
|
print form.cleaned_data['payform']
|
|
if form.cleaned_data['payform'] == '1':
|
|
print 222222
|
|
sMerchantLogin = settings.ROBOKASSA_LOGIN
|
|
nOutSum = form.cleaned_data['term'].price
|
|
nInvId = new_license.id
|
|
sInvDesc = u"Оплата лицензии Документор.ру"
|
|
sign_str = u"%s:%s:%s:%s" % (sMerchantLogin, nOutSum, nInvId, settings.ROBOKASSA_PASSWORD1)
|
|
sSignatureValue = hashlib.md5(sign_str).hexdigest()
|
|
print sign_str, sSignatureValue
|
|
sEmail = request.user.email
|
|
|
|
robokassa = 'http://test.robokassa.ru/Index.aspx?MrchLogin=%s&OutSum=%s&InvId=%s&Desc=%s&SignatureValue=%s&Email=%s&Culture=ru&Encoding=utf-8' % (sMerchantLogin, nOutSum, nInvId, urlquote(sInvDesc), sSignatureValue, sEmail)
|
|
print robokassa
|
|
return redirect(robokassa)
|
|
return redirect(reverse('customer_license_list'))
|
|
|
|
return render(request, template_name, dictionary)
|
|
|
|
|
|
@login_required
|
|
def license_list(request):
|
|
"""Список счетов на лицензии
|
|
"""
|
|
template_name = 'customer/profile/license_list.html'
|
|
licenses = License.objects.filter(user=request.user).order_by('-id')
|
|
dictionary = {
|
|
'licenses': licenses,
|
|
}
|
|
return render(request, template_name, dictionary)
|
|
|
|
|
|
@login_required
|
|
def paid_list(request):
|
|
"""Оплаченные лицензии
|
|
"""
|
|
template_name = 'customer/profile/paid_list.html'
|
|
licenses = License.objects.filter(user=request.user, status__in=[-1, 1, 2, 3]).order_by('-id')
|
|
dictionary = {
|
|
'licenses': licenses,
|
|
}
|
|
return render(request, template_name, dictionary)
|
|
|
|
|
|
@login_required
|
|
def delete_license(request, pk):
|
|
template_name = 'customer/profile/delete_license.html'
|
|
try:
|
|
license = License.objects.get(pk=pk)
|
|
except:
|
|
raise Http404
|
|
dictionary = {'license': license}
|
|
return render(request, template_name, dictionary)
|
|
|
|
|
|
@csrf_exempt
|
|
def payment_result(request):
|
|
if request.method == 'POST':
|
|
try:
|
|
nInvId = request.POST.get('InvId')
|
|
|
|
nOutSum = request.POST.get('OutSum')
|
|
sSignatureValue = request.POST.get('SignatureValue')
|
|
SignatureValue = hashlib.md5('%s:%s:%s' % (nOutSum, nInvId, settings.ROBOKASSA_PASSWORD2)).hexdigest()
|
|
if sSignatureValue.upper() == SignatureValue.upper():
|
|
license = License.objects.get(pk=nInvId)
|
|
license.status = 1
|
|
license.save()
|
|
return HttpResponse('OK%s' % nInvId)
|
|
else:
|
|
return HttpResponse('bad sign')
|
|
except License.DoesNotExist:
|
|
return HttpResponseForbidden()
|
|
else:
|
|
return HttpResponseForbidden()
|
|
|
|
|
|
@csrf_exempt
|
|
def payment_success(request):
|
|
if request.method == 'POST':
|
|
print request.POST
|
|
try:
|
|
nInvId = request.POST.get('InvId')
|
|
order = License.objects.get(pk=nInvId)
|
|
|
|
context = {'success': True, 'order_num': nInvId}
|
|
return TemplateResponse(request, 'customer/profile/end_order.html', context)
|
|
except License.DoesNotExist:
|
|
return HttpResponseForbidden()
|
|
else:
|
|
return HttpResponseForbidden()
|
|
|
|
|
|
@csrf_exempt
|
|
def payment_fail(request):
|
|
if request.method == 'POST':
|
|
try:
|
|
nInvId = request.POST.get('InvId')
|
|
|
|
message = u"Возникла проблема. Ваш Заказ не оплачен. Попробуйте оформить заявку снова, или позвоните по номеру."
|
|
|
|
return TemplateResponse(request, 'customer/profile/end_order.html', {'message': message, 'success': False})
|
|
except Order.DoesNotExist:
|
|
return HttpResponseForbidden()
|
|
else:
|
|
return HttpResponseForbidden()
|
|
|