|
|
|
|
@ -1,27 +1,25 @@ |
|
|
|
|
from django.conf import urls, settings |
|
|
|
|
from django.conf import settings |
|
|
|
|
from django.contrib import messages |
|
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin |
|
|
|
|
from django.db.models import Sum |
|
|
|
|
from django.http import HttpResponse, JsonResponse, HttpResponseForbidden |
|
|
|
|
from django.http import HttpResponse, JsonResponse |
|
|
|
|
from django.shortcuts import render, get_object_or_404 |
|
|
|
|
from django.utils import timezone |
|
|
|
|
from django.utils.decorators import method_decorator |
|
|
|
|
from django.views.decorators.csrf import csrf_exempt |
|
|
|
|
from django.views.generic import DetailView, CreateView |
|
|
|
|
from django.views.generic.base import View |
|
|
|
|
from pprint import pprint, pformat |
|
|
|
|
import logging |
|
|
|
|
|
|
|
|
|
from users.models import User |
|
|
|
|
from .forms import WithDrawForm, TmpCheckOrderForm, TmpPaymentAvisoForm |
|
|
|
|
from .models import InvoiceHistory, WithDraw, Transaction |
|
|
|
|
from users.mixins import CheckForUserMixin |
|
|
|
|
from users.models import User |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ScoreDetailView(DetailView): |
|
|
|
|
model = User |
|
|
|
|
template_name = 'score-detail.html' |
|
|
|
|
context_object_name = 'user_score' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs): |
|
|
|
|
context = super().get_context_data(**kwargs) |
|
|
|
|
user_score_balance = InvoiceHistory.objects.filter(user=self.get_object()).aggregate(Sum('sum')) |
|
|
|
|
@ -30,23 +28,20 @@ class ScoreDetailView(DetailView): |
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ScoreView(View): |
|
|
|
|
class ScoreView(LoginRequiredMixin, View): |
|
|
|
|
template_name = 'score-detail.html' |
|
|
|
|
|
|
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
|
if request.user.is_authenticated() and request.user.is_customer(): |
|
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
|
else: |
|
|
|
|
return HttpResponseForbidden('403 Forbidden') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
|
transaction = Transaction.objects.get_or_create(customer=request.user, complete=False) |
|
|
|
|
user_score = get_object_or_404(User.customer_objects, pk=kwargs.get('pk')) |
|
|
|
|
|
|
|
|
|
transaction = Transaction.objects.create(customer=request.user, type='add') |
|
|
|
|
user_score = get_object_or_404(User.objects, pk=kwargs.get('pk')) |
|
|
|
|
current_sum_info = InvoiceHistory.objects.filter(user=user_score).aggregate(Sum('sum')) |
|
|
|
|
user_score_balance = current_sum_info['sum__sum'] or 0 |
|
|
|
|
|
|
|
|
|
return render(request, self.template_name, { |
|
|
|
|
'transaction': transaction, |
|
|
|
|
'YANDEX_MONEY': settings.YANDEX_MONEY, |
|
|
|
|
'user_score': user_score, |
|
|
|
|
'user_score_balance': user_score_balance, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -98,23 +93,22 @@ class WithDrawCreate(CreateView): |
|
|
|
|
return super().form_invalid(form) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Yandex Money ------------------------------------------------ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TmpCheckOrderView(View): |
|
|
|
|
form_class = TmpCheckOrderForm |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(csrf_exempt) |
|
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
|
form = self.form_class(request.POST) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# trans = form.cleaned_data.get('transaction') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if form.is_valid(): |
|
|
|
|
res = """<?xml version="1.0" encoding="utf-8"?> |
|
|
|
|
<checkOrderResponse |
|
|
|
|
@ -127,7 +121,7 @@ class TmpCheckOrderView(View): |
|
|
|
|
invoice_id=form.cleaned_data.get('invoiceId'), |
|
|
|
|
shop_id=form.cleaned_data.get('shopId'), |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return HttpResponse(res, content_type='application/xml') |
|
|
|
|
else: |
|
|
|
|
res = """<?xml version="1.0" encoding="utf-8"?> |
|
|
|
|
@ -143,22 +137,27 @@ class TmpCheckOrderView(View): |
|
|
|
|
invoice_id=form.cleaned_data.get('invoiceId'), |
|
|
|
|
shop_id=form.cleaned_data.get('shopId'), |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return HttpResponse(res, content_type='application/xml') |
|
|
|
|
# return HttpResponse('<pre>{msg}</pre>'.format(msg=pformat(form.errors))) # Debug |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TmpPaymentAvisoView(View): |
|
|
|
|
form_class = TmpPaymentAvisoForm |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(csrf_exempt) |
|
|
|
|
def dispatch(self, request, *args, **kwargs): |
|
|
|
|
return super().dispatch(request, *args, **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
|
form = self.form_class(request.POST) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if form.is_valid(): |
|
|
|
|
transaction = form.cleaned_data.get('transaction_id') |
|
|
|
|
transaction.complete = True |
|
|
|
|
transaction.sum = form.cleaned_data.get('orderSumAmount') |
|
|
|
|
transaction.save() |
|
|
|
|
|
|
|
|
|
res = """<?xml version="1.0" encoding="utf-8"?> |
|
|
|
|
<paymentAvisoResponse |
|
|
|
|
performedDatetime="{date}" |
|
|
|
|
@ -170,7 +169,7 @@ class TmpPaymentAvisoView(View): |
|
|
|
|
invoice_id=form.cleaned_data.get('invoiceId'), |
|
|
|
|
shop_id=form.cleaned_data.get('shopId'), |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return HttpResponse(res, content_type='application/xml') |
|
|
|
|
else: |
|
|
|
|
res = """<?xml version="1.0" encoding="utf-8"?> |
|
|
|
|
@ -180,6 +179,6 @@ class TmpPaymentAvisoView(View): |
|
|
|
|
message="Payment aviso, validation error" |
|
|
|
|
techMessage="Payment aviso, validation error"/> |
|
|
|
|
""".format(date=timezone.now().isoformat()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return HttpResponse(res, content_type='application/xml') |
|
|
|
|
# return HttpResponse('<pre>{msg}</pre>'.format(msg=pformat(form.errors))) # Debug |
|
|
|
|
|