|
|
|
@ -21,7 +21,6 @@ from courses.models import Course |
|
|
|
from courses.api import CourseParamsApi |
|
|
|
from courses.api import CourseParamsApi |
|
|
|
from finance.models import Bill, Invoice, InvoiceRebilling |
|
|
|
from finance.models import Bill, Invoice, InvoiceRebilling |
|
|
|
from finance.serializers import BillSerializer, InvoiceSerializer |
|
|
|
from finance.serializers import BillSerializer, InvoiceSerializer |
|
|
|
from finance.tasks import setup_periodic_billing |
|
|
|
|
|
|
|
from lms.global_decorators import transaction_decorator |
|
|
|
from lms.global_decorators import transaction_decorator |
|
|
|
from lms.tools import get_real_name |
|
|
|
from lms.tools import get_real_name |
|
|
|
from django.utils import timezone |
|
|
|
from django.utils import timezone |
|
|
|
@ -39,6 +38,38 @@ def test_pay(request): |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FreezeView(APIView): |
|
|
|
|
|
|
|
renderer_classes = (JSONRenderer,) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
|
|
|
def post(request, pk): |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
bill = Bill.objects.get(id=pk) |
|
|
|
|
|
|
|
except Bill.DoesNotExist: |
|
|
|
|
|
|
|
return Response("Счёт не найден", status=404) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if request.user.is_authenticated and request.user.email == bill.user.email: |
|
|
|
|
|
|
|
bill.freeze_course() |
|
|
|
|
|
|
|
return Response(status=204) |
|
|
|
|
|
|
|
return Response("Permission denied", status=403) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UnFreezeView(APIView): |
|
|
|
|
|
|
|
renderer_classes = (JSONRenderer,) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
|
|
|
def post(request, pk): |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
bill = Bill.objects.get(id=pk) |
|
|
|
|
|
|
|
except Bill.DoesNotExist: |
|
|
|
|
|
|
|
return Response("Счёт не найден", status=404) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if request.user.is_authenticated and request.user.email == bill.user.email: |
|
|
|
|
|
|
|
bill.unfreeze_course() |
|
|
|
|
|
|
|
return Response(status=204) |
|
|
|
|
|
|
|
return Response("Permission denied", status=403) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BillListView(APIView): |
|
|
|
class BillListView(APIView): |
|
|
|
renderer_classes = (JSONRenderer,) |
|
|
|
renderer_classes = (JSONRenderer,) |
|
|
|
|
|
|
|
|
|
|
|
@ -109,8 +140,7 @@ class InvoiceDetailView(APIView): |
|
|
|
price = request.JSON.get('price', None) |
|
|
|
price = request.JSON.get('price', None) |
|
|
|
comment = request.JSON.get('comment', None) |
|
|
|
comment = request.JSON.get('comment', None) |
|
|
|
real_price = request.JSON.get('real_price', None) |
|
|
|
real_price = request.JSON.get('real_price', None) |
|
|
|
rebilling_on = request.JSON.get('is_rebilling', False) |
|
|
|
pay_count = int(request.JSON.get('pay_count', '1')) |
|
|
|
pay_count = request.JSON.get('pay_count', None) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if bill_id is None: |
|
|
|
if bill_id is None: |
|
|
|
return Response("Не передан id счёта", status=400) |
|
|
|
return Response("Не передан id счёта", status=400) |
|
|
|
@ -129,14 +159,15 @@ class InvoiceDetailView(APIView): |
|
|
|
if bill.check_validate(invoice_id) and is_open: |
|
|
|
if bill.check_validate(invoice_id) and is_open: |
|
|
|
return Response("Уже есть платёж открывающий курс", status=400) |
|
|
|
return Response("Уже есть платёж открывающий курс", status=400) |
|
|
|
|
|
|
|
|
|
|
|
if rebilling_on: |
|
|
|
if pay_count > 1: |
|
|
|
invoice = InvoiceRebilling.objects.create( |
|
|
|
invoice = InvoiceRebilling.objects.create( |
|
|
|
bill=bill, |
|
|
|
bill=bill, |
|
|
|
method=method, |
|
|
|
method=method, |
|
|
|
status=status, |
|
|
|
status=status, |
|
|
|
is_open=is_open, |
|
|
|
is_open=is_open, |
|
|
|
pay_count=pay_count, |
|
|
|
rebilling_on=True, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
|
else: |
|
|
|
try: |
|
|
|
try: |
|
|
|
invoice = Invoice.objects.get(id=invoice_id) |
|
|
|
invoice = Invoice.objects.get(id=invoice_id) |
|
|
|
@ -172,6 +203,9 @@ class InvoiceDetailView(APIView): |
|
|
|
invoice.is_open = is_open |
|
|
|
invoice.is_open = is_open |
|
|
|
invoice.comment = comment |
|
|
|
invoice.comment = comment |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if pay_count > 1: |
|
|
|
|
|
|
|
invoice.create_child_pays(pay_count) |
|
|
|
|
|
|
|
|
|
|
|
if invoice.method == 'Y' and invoice.yandex_pay is None: |
|
|
|
if invoice.method == 'Y' and invoice.yandex_pay is None: |
|
|
|
yandex_pay = Payment.objects.create( |
|
|
|
yandex_pay = Payment.objects.create( |
|
|
|
order_amount=invoice.price, |
|
|
|
order_amount=invoice.price, |
|
|
|
@ -427,6 +461,9 @@ class YandexAvisoView(APIView): |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
pay.shop_amount = data['shopSumAmount'] |
|
|
|
pay.shop_amount = data['shopSumAmount'] |
|
|
|
|
|
|
|
invoice = pay.invoice |
|
|
|
|
|
|
|
invoice.key = data['invoiceId'] |
|
|
|
|
|
|
|
invoice.save() |
|
|
|
pay.status = Payment.STATUS.SUCCESS |
|
|
|
pay.status = Payment.STATUS.SUCCESS |
|
|
|
now = timezone.now() |
|
|
|
now = timezone.now() |
|
|
|
pay.performed_datetime = now.isoformat() |
|
|
|
pay.performed_datetime = now.isoformat() |
|
|
|
@ -457,12 +494,6 @@ class YandexAvisoView(APIView): |
|
|
|
msg.attach_alternative(html_content, "text/html") |
|
|
|
msg.attach_alternative(html_content, "text/html") |
|
|
|
msg.send() |
|
|
|
msg.send() |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
InvoiceRebilling.objects.get(yandex_pay=pay) |
|
|
|
|
|
|
|
setup_periodic_billing(pay.order_number) |
|
|
|
|
|
|
|
except InvoiceRebilling.DoesNotExist: |
|
|
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return HttpResponse(xml_res, content_type='application/xml') |
|
|
|
return HttpResponse(xml_res, content_type='application/xml') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -470,7 +501,7 @@ class YandexFailView(APIView): |
|
|
|
renderer_classes = (JSONRenderer,) |
|
|
|
renderer_classes = (JSONRenderer,) |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
@staticmethod |
|
|
|
def post(request): |
|
|
|
def get(request): |
|
|
|
data = dict() |
|
|
|
data = dict() |
|
|
|
for i in request.body.decode('utf-8').split('&'): |
|
|
|
for i in request.body.decode('utf-8').split('&'): |
|
|
|
key = i.split('=')[0] |
|
|
|
key = i.split('=')[0] |
|
|
|
|