|
|
|
@ -1,25 +1,19 @@ |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
import json |
|
|
|
import json |
|
|
|
import hashlib |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import itertools |
|
|
|
import itertools |
|
|
|
|
|
|
|
|
|
|
|
from django.db.models import Count |
|
|
|
from django.db.models import Count |
|
|
|
from django.shortcuts import render, redirect, get_object_or_404 |
|
|
|
from django.shortcuts import render, redirect, get_object_or_404 |
|
|
|
from django.http import ( |
|
|
|
from django.http import (HttpResponse, HttpResponseBadRequest) |
|
|
|
# HttpResponseForbidden, |
|
|
|
|
|
|
|
HttpResponse, HttpResponseBadRequest) |
|
|
|
|
|
|
|
from django.conf import settings |
|
|
|
|
|
|
|
# from django.views.decorators.csrf import csrf_exempt |
|
|
|
|
|
|
|
from django.contrib.auth.decorators import login_required |
|
|
|
from django.contrib.auth.decorators import login_required |
|
|
|
# from django.template.response import TemplateResponse |
|
|
|
|
|
|
|
from django.core.urlresolvers import reverse |
|
|
|
from django.core.urlresolvers import reverse |
|
|
|
from django.views.decorators.csrf import csrf_protect |
|
|
|
from django.views.decorators.csrf import csrf_protect |
|
|
|
from robokassa.forms import RobokassaForm |
|
|
|
from robokassa.forms import RobokassaForm |
|
|
|
|
|
|
|
|
|
|
|
from customer.models import License, LicensePrice, Payment |
|
|
|
from customer.models import License, LicensePrice, Payment |
|
|
|
from customer.forms import LicenseForm |
|
|
|
from customer.forms import LicenseForm |
|
|
|
from customer.utils import raise_if_no_profile |
|
|
|
from customer.utils import raise_if_no_profile, get_robokassa_url |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required |
|
|
|
@login_required |
|
|
|
@ -51,32 +45,7 @@ def order_license(request): |
|
|
|
user=request.user, |
|
|
|
user=request.user, |
|
|
|
type=1 |
|
|
|
type=1 |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
return redirect(get_robokassa_url(payment)) |
|
|
|
login = settings.ROBOKASSA_LOGIN |
|
|
|
|
|
|
|
inv_id = payment.pk |
|
|
|
|
|
|
|
out_summ = format(payment.order_amount, '.2f') |
|
|
|
|
|
|
|
desc = 'Оплата лицензии Dokumentor.ru' |
|
|
|
|
|
|
|
site = 'https://merchant.roboxchange.com/Index.aspx' |
|
|
|
|
|
|
|
if settings.ROBOKASSA_TEST_MODE: |
|
|
|
|
|
|
|
site = 'https://auth.robokassa.ru/Merchant/Index.aspx' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
signature = hashlib.md5( |
|
|
|
|
|
|
|
f'{login}:{out_summ}:{inv_id}:{settings.ROBOKASSA_PASSWORD1}'.encode("ascii") |
|
|
|
|
|
|
|
).hexdigest().upper() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
params = f'?MerchantLogin={login}' \ |
|
|
|
|
|
|
|
f'&SignatureValue={signature}' \ |
|
|
|
|
|
|
|
f'&InvId={inv_id}' \ |
|
|
|
|
|
|
|
f'&OutSum={out_summ}' \ |
|
|
|
|
|
|
|
f'&InvDesc={desc}' \ |
|
|
|
|
|
|
|
f'&Email={payment.user.email}' \ |
|
|
|
|
|
|
|
f'&Culture=ru' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if settings.ROBOKASSA_TEST_MODE: |
|
|
|
|
|
|
|
params += f'&isTest=1' |
|
|
|
|
|
|
|
url = f'{site}{params}' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return redirect(url) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if form.cleaned_data['payform'] == '0': |
|
|
|
if form.cleaned_data['payform'] == '0': |
|
|
|
Payment.objects.create( |
|
|
|
Payment.objects.create( |
|
|
|
@ -141,53 +110,6 @@ def delete_license(request, pk): |
|
|
|
return HttpResponse(data, content_type='application/json') |
|
|
|
return HttpResponse(data, content_type='application/json') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# @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): |
|
|
|
|
|
|
|
# nInvId = request.GET.get('orderNumber') |
|
|
|
|
|
|
|
# # order = License.objects.get(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"Возникла проблема. Ваш Заказ не оплачен. " \ |
|
|
|
|
|
|
|
# u"Попробуйте оформить заявку снова, или позвоните по номеру." |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# return TemplateResponse( |
|
|
|
|
|
|
|
# request, |
|
|
|
|
|
|
|
# 'customer/profile/end_order.html', |
|
|
|
|
|
|
|
# {'message': message, 'success': False}) |
|
|
|
|
|
|
|
# except: |
|
|
|
|
|
|
|
# return HttpResponseForbidden() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required |
|
|
|
@login_required |
|
|
|
def orders_list(request): |
|
|
|
def orders_list(request): |
|
|
|
"""List license and account for license in one page""" |
|
|
|
"""List license and account for license in one page""" |
|
|
|
|