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.
 
 
 
 
 
 

91 lines
3.4 KiB

# coding=utf-8
## Реализация платежных сервисов
from django.shortcuts import render
from lms.decors import response_decor
from finance.models import Bill
from django.http import Http404
from lms.tools import gen_pay_sig
@response_decor(template='good_pay.html', without_auth=True)
def success(request):
# Страница успешного платежа
if request.GET.get('sp_sig') and gen_pay_sig(request.GET) == request.GET.get('sp_sig'):
try:
bill = Bill.objects.get(id=request.GET['sp_order_id'])
except Bill.DoesNotExist:
raise Http404
else:
bill.status = 'F' if request.GET['sp_result'] == '1' else 'C'
bill.out_id = request.GET['sp_payment_id']
bill._method = 'S'
bill.save()
url = '/?success_pay=True' if bill.service.freepay else '/?success_pay=True&course_id={0}'.format(bill.service.course.id)
if bill.admitad_uid:
url += '&admitad_uid={0}&order_id={1}&email={2}'.format(bill.admitad_uid, bill.id, bill.user.email)
return {'redirect': url}
else:
raise Http404
@response_decor(template='fail_pay.html', without_auth=True)
def fail(request):
# Страница ошибки платежа
if request.GET.get('sp_sig') and gen_pay_sig(request.GET) == request.GET.get('sp_sig'):
try:
bill = Bill.objects.get(id=request.GET['sp_order_id'])
except Bill.DoesNotExist:
raise Http404
else:
bill.status = 'F' if request.GET['sp_result'] else 'C'
bill.out_id = request.GET['sp_payment_id']
bill._method = 'S'
bill.save()
url = '/?fail_pay=True&fail_url={0}'.format(bill.service.url) if bill.service.freepay else '/?fail_pay=True&fail_pay_id={0}'.format(bill.id)
return {'redirect': url}
else:
raise Http404
def result(request):
# Страница получения результата о платежах
if request.GET.get('sp_sig') and gen_pay_sig(request.GET) == request.GET.get('sp_sig'):
try:
bill = Bill.objects.get(id=request.GET['sp_order_id'])
except Bill.DoesNotExist:
keys = {'sp_salt': request.GET['sp_salt'],
'sp_status': 'error',
'sp_description': 'Order not found'}
return render(request, 'simplepayresult.xml',
{"salt": request.GET['sp_salt'],
'status': 'error',
'description': 'Order not found',
'sig': gen_pay_sig(keys)},
content_type="application/xhtml+xml")
else:
bill.status = 'F' if request.GET['sp_result'] == '1' else 'C'
bill.out_id = request.GET['sp_payment_id']
bill._method = 'S'
bill.save()
keys = {'sp_salt': request.GET['sp_salt'],
'sp_status': 'ok',
'sp_description': 'Good pay'}
return render(request, 'simplepayresult.xml',
{'salt': request.GET['sp_salt'],
'status': 'ok',
'sig': gen_pay_sig(keys),
'description': 'Good pay'},
content_type="application/xhtml+xml")
else:
raise Http404