|
|
|
|
@ -19,7 +19,7 @@ from django.utils.html import strip_tags |
|
|
|
|
|
|
|
|
|
from courses.models import Course |
|
|
|
|
from courses.api import CourseParamsApi |
|
|
|
|
from finance.models import Bill, Invoice |
|
|
|
|
from finance.models import Bill, Invoice, InvoiceRebilling |
|
|
|
|
from finance.serializers import BillSerializer, InvoiceSerializer |
|
|
|
|
from finance.tasks import setup_periodic_billing |
|
|
|
|
from lms.global_decorators import transaction_decorator |
|
|
|
|
@ -99,6 +99,8 @@ class InvoiceDetailView(APIView): |
|
|
|
|
price = request.JSON.get('price', None) |
|
|
|
|
comment = request.JSON.get('comment', None) |
|
|
|
|
real_price = request.JSON.get('real_price', None) |
|
|
|
|
rebilling_on = request.JSON.get('is_rebilling', False) |
|
|
|
|
pay_count = request.JSON.get('pay_count', None) |
|
|
|
|
|
|
|
|
|
if bill_id is None: |
|
|
|
|
return Response("Не передан id счёта", status=400) |
|
|
|
|
@ -117,22 +119,32 @@ class InvoiceDetailView(APIView): |
|
|
|
|
if bill.check_validate(invoice_id) and is_open: |
|
|
|
|
return Response("Уже есть платёж открывающий курс", status=400) |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
invoice = Invoice.objects.get(id=invoice_id) |
|
|
|
|
except Invoice.DoesNotExist: |
|
|
|
|
if not invoice_id == 0: |
|
|
|
|
return Response("Платёж не найден", status=404) |
|
|
|
|
|
|
|
|
|
if bill.check_pay(): |
|
|
|
|
return Response( |
|
|
|
|
"Нельзя добавить новый платёж, так как один из платежей по счёту уже оплачен", status=400) |
|
|
|
|
invoice = Invoice.objects.create( |
|
|
|
|
if rebilling_on: |
|
|
|
|
invoice = InvoiceRebilling.objects.create( |
|
|
|
|
bill=bill, |
|
|
|
|
method=method, |
|
|
|
|
status=status, |
|
|
|
|
is_open=is_open, |
|
|
|
|
pay_count=pay_count, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
try: |
|
|
|
|
invoice = Invoice.objects.get(id=invoice_id) |
|
|
|
|
except Invoice.DoesNotExist: |
|
|
|
|
if not invoice_id == 0: |
|
|
|
|
return Response("Платёж не найден", status=404) |
|
|
|
|
|
|
|
|
|
if bill.check_pay(): |
|
|
|
|
return Response( |
|
|
|
|
"Нельзя добавить новый платёж, так как один из платежей по счёту уже оплачен", status=400) |
|
|
|
|
invoice = Invoice.objects.create( |
|
|
|
|
bill=bill, |
|
|
|
|
method=method, |
|
|
|
|
status=status, |
|
|
|
|
is_open=is_open, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if invoice.status == "F": |
|
|
|
|
return Response(InvoiceSerializer(invoice).data, status=200) |
|
|
|
|
|
|
|
|
|
@ -248,6 +260,10 @@ class YandexPay(APIView): |
|
|
|
|
def get(request, pk): |
|
|
|
|
try: |
|
|
|
|
pay = Payment.objects.get(id=pk) |
|
|
|
|
try: |
|
|
|
|
inv = InvoiceRebilling.objects.get(yandex_pay=pay) |
|
|
|
|
except InvoiceRebilling: |
|
|
|
|
inv = None |
|
|
|
|
r = requests.post('https://money.yandex.ru/eshop.xml', data={ |
|
|
|
|
'shopId': pay.shop_id, |
|
|
|
|
'scid': pay.scid, |
|
|
|
|
@ -255,7 +271,7 @@ class YandexPay(APIView): |
|
|
|
|
'customerNumber': pay.customer_number, |
|
|
|
|
'orderNumber': pay.order_number, |
|
|
|
|
'cps_email': pay.cps_email, |
|
|
|
|
'rebillingOn': pay.invoice.rebilling_on, |
|
|
|
|
'rebillingOn': False if inv is None else inv.rebilling_on, |
|
|
|
|
'shopSuccessURL': settings.YANDEX_MONEY_SUCCESS_URL, |
|
|
|
|
'shopFailURL': settings.YANDEX_MONEY_FAIL_URL, |
|
|
|
|
}) |
|
|
|
|
|