diff --git a/archilance/settings/base.py b/archilance/settings/base.py index 1d9c3e2..5388b76 100644 --- a/archilance/settings/base.py +++ b/archilance/settings/base.py @@ -267,3 +267,19 @@ SHELL_PLUS_POST_IMPORTS = ( # Extra auto imports ) PAGE_SIZE = 10 # Pagination + + +YANDEX_MONEY = {'shop_password': 'x1uvmS9Iq8WBE3Oo'} + +if DEBUG: + YANDEX_MONEY.update({ + 'url': 'https://demomoney.yandex.ru/eshop.xml', + 'shop_id': 59838, + 'scid': 537400, + }) +else: + YANDEX_MONEY.update({ + 'url': 'https://money.yandex.ru/eshop.xml', + 'shop_id': 0, + 'scid': 0, + }) diff --git a/archilance/urls.py b/archilance/urls.py index b4886e8..c77fca5 100644 --- a/archilance/urls.py +++ b/archilance/urls.py @@ -6,26 +6,42 @@ from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.views.generic import TemplateView from .views import HomeTemplateView, TestChatTemplateView +from wallets.views import TmpCheckOrderView, TmpPaymentAvisoView -urlpatterns = [ - url(r'^$', HomeTemplateView.as_view()), - url('', include('social.apps.django_app.urls', namespace='social')), - url(r'^chattest/$', TestChatTemplateView.as_view()), - url(r'^work_sell/', include('work_sell.urls')), - url(r'^test/$', TemplateView.as_view(template_name='test.html'), name='test'), - url(r'^projects/', include('projects.urls')), - url(r'^reviews/', include('reviews.urls')), - url(r'^wallets/', include('wallets.urls')), - url(r'^chat/', include('chat.urls')), - url(r'^specializations/', include('specializations.urls')), - url(r'^users/', include('users.urls')), - url(r'^common/', include('common.urls')), - url(r'^password/', include('password_reset.urls')), - url(r'^users/', include('registration.backends.default.urls')), - url(r'^admin/', admin.site.urls), - url(r'^api/', include('api.urls')), - ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) +urlpatterns = [ + url(r'^$', HomeTemplateView.as_view()), + url('', include('social.apps.django_app.urls', namespace='social')), + url(r'^chattest/$', TestChatTemplateView.as_view()), + url(r'^work_sell/', include('work_sell.urls')), + url(r'^test/$', TemplateView.as_view(template_name='test.html'), name='test'), + url(r'^projects/', include('projects.urls')), + url(r'^reviews/', include('reviews.urls')), + url(r'^wallets/', include('wallets.urls')), + url(r'^chat/', include('chat.urls')), + url(r'^specializations/', include('specializations.urls')), + url(r'^users/', include('users.urls')), + url(r'^common/', include('common.urls')), + url(r'^password/', include('password_reset.urls')), + url(r'^users/', include('registration.backends.default.urls')), + url(r'^admin/', admin.site.urls), + url(r'^api/', include('api.urls')), + + + # TODO: Move URLs into the "wallets" app (Yandex Money settings modification needed): + + url(r'^yandex/check$', TmpCheckOrderView.as_view(), name='tmp-check-order'), + url(r'^yandex/aviso$', TmpPaymentAvisoView.as_view(), name='tmp-payment-aviso'), + + url(r'^payment/success$', TemplateView.as_view(template_name='message.html'), { + 'message': 'Оплата прошла успешно', + }, name='tmp-payment-success'), + + url(r'^payment/fail$', TemplateView.as_view(template_name='message.html'), { + 'message': 'Произошла ошибка при оплате', + }, name='tmp-payment-fail'), + +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) if settings.DEBUG: urlpatterns += staticfiles_urlpatterns() diff --git a/templates/home.html b/templates/home.html index bc6c7a9..8e6a337 100644 --- a/templates/home.html +++ b/templates/home.html @@ -1,5 +1,4 @@ {% extends 'partials/base.html' %} -{% load staticfiles %} {% block content %}
diff --git a/templates/message.html b/templates/message.html new file mode 100644 index 0000000..0346ef0 --- /dev/null +++ b/templates/message.html @@ -0,0 +1,11 @@ +{% extends 'partials/base.html' %} + +{% block content %} +
+
+
+

{{ message }}

+
+
+
+{% endblock %} diff --git a/templates/partials/base.html b/templates/partials/base.html index 4918bd8..3450bb2 100644 --- a/templates/partials/base.html +++ b/templates/partials/base.html @@ -37,7 +37,7 @@ {% endfor %} {% endif %} -
+
{{ request.user }}
{% if request.user.is_authenticated %} diff --git a/users/views.py b/users/views.py index f0a600a..6bfa5c5 100644 --- a/users/views.py +++ b/users/views.py @@ -67,7 +67,7 @@ class UserProfileEditView(BaseMixin, View): if form.is_valid(): form.save() - messages.info(request, 'Заказчик успешно отредактирован') + messages.info(request, 'Пользователь успешно отредактирован') redirect_to = request.POST.get('next') return redirect(redirect_to) else: diff --git a/wallets/forms.py b/wallets/forms.py index 3e871f3..bdfd997 100644 --- a/wallets/forms.py +++ b/wallets/forms.py @@ -1,13 +1,61 @@ from django import forms +from django.conf import settings + from .models import WithDraw class WithDrawForm(forms.ModelForm): - class Meta: model = WithDraw + fields = ( 'sum', 'yandex_card', 'user', ) + + +class TmpCheckOrderForm(forms.Form): + action = forms.CharField() # Has to be "checkOrder" + md5 = forms.CharField() + shopId = forms.IntegerField() + invoiceId = forms.IntegerField() + + def clean_action(self): + action = self.cleaned_data.get('action') + + if action != 'checkOrder': + raise forms.ValidationError('Wrong action') + + return action + + def clean_shopId(self): + shopId = self.cleaned_data.get('shopId') + + if shopId != settings.YANDEX_MONEY['shop_id']: + raise forms.ValidationError('Wrong shop ID') + + return shopId + + +class TmpPaymentAvisoForm(forms.Form): + action = forms.CharField() # Has to be "paymentAviso" + md5 = forms.CharField() + shopId = forms.IntegerField() + invoiceId = forms.IntegerField() + + def clean_action(self): + action = self.cleaned_data.get('action') + + if action != 'paymentAviso': + raise forms.ValidationError('Wrong action') + + return action + + def clean_shopId(self): + shopId = self.cleaned_data.get('shopId') + + if shopId != settings.YANDEX_MONEY['shop_id']: + raise forms.ValidationError('Wrong shop ID') + + return shopId diff --git a/wallets/templates/tmp_yandex_money_request_example.html b/wallets/templates/tmp_yandex_money_request_example.html new file mode 100755 index 0000000..37182a5 --- /dev/null +++ b/wallets/templates/tmp_yandex_money_request_example.html @@ -0,0 +1,20 @@ +{% extends 'partials/base.html' %} + +{% block content %} +
+
+
+
+

shopId:

+

scid:

+

sum:

+

customerNumber:

+ +

paymentType:

+ +

+
+
+
+
+{% endblock %} diff --git a/wallets/templates/tmp_yandex_money_responses_sumulation.html b/wallets/templates/tmp_yandex_money_responses_sumulation.html new file mode 100755 index 0000000..16b200b --- /dev/null +++ b/wallets/templates/tmp_yandex_money_responses_sumulation.html @@ -0,0 +1,54 @@ +{% extends 'partials/base.html' %} + +{% block content %} +
+
+
+

Simulating a Yandex "checkOrder" request

+ +
+

action:

+

md5:

+

shopId:

+

invoiceId:

+

customerNumber:

+

orderSumAmount:

+

orderSumCurrencyPaycash:

+

orderSumBankPaycash:

+

shopPassword:

+ +

orderNumber:

+ +

+
+
+
+ + + + + + +
+
+

Simulating a Yandex "paymentAviso" request

+ +
+

action:

+

md5:

+

shopId:

+

invoiceId:

+

customerNumber:

+

orderSumAmount:

+

orderSumCurrencyPaycash:

+

orderSumBankPaycash:

+

shopPassword:

+ +

orderNumber:

+ +

+
+
+
+
+{% endblock %} diff --git a/wallets/urls.py b/wallets/urls.py index bbbe2e1..3f71a17 100755 --- a/wallets/urls.py +++ b/wallets/urls.py @@ -1,10 +1,25 @@ -from django.conf import urls +from django.conf import urls, settings +from django.views.generic import TemplateView + from .views import ScoreDetailView, WithDrawCreate + app_name = 'wallets' urlpatterns = [ urls.url(r'^score/(?P\d+)/$', ScoreDetailView.as_view(), name='score-detail'), urls.url(r'^withdraw/create/$', WithDrawCreate.as_view(), name='withdraw-create'), - + + urls.url( + r'^tmp-yamoney-req/$', + TemplateView.as_view(template_name='tmp_yandex_money_request_example.html'), + {'YANDEX_MONEY': settings.YANDEX_MONEY}, + name='tmp-yamoney-req', + ), + + urls.url( + r'^tmp-yamoney-sim/$', + TemplateView.as_view(template_name='tmp_yandex_money_responses_sumulation.html'), + name='tmp-yamoney-sim', + ), ] diff --git a/wallets/views.py b/wallets/views.py index 76776cd..2baa619 100644 --- a/wallets/views.py +++ b/wallets/views.py @@ -1,11 +1,17 @@ -from django.http import JsonResponse from django.contrib import messages from django.db.models import Sum +from django.http import HttpResponse, JsonResponse +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 users.models import User -from users.mixins import CheckForUserMixin +from django.views.generic.base import View +from pprint import pprint, pformat + +from .forms import WithDrawForm, TmpCheckOrderForm, TmpPaymentAvisoForm from .models import InvoiceHistory, WithDraw -from .forms import WithDrawForm +from users.mixins import CheckForUserMixin +from users.models import User class ScoreDetailView(CheckForUserMixin, DetailView): @@ -67,3 +73,88 @@ class WithDrawCreate(CreateView): if self.request.is_ajax(): return JsonResponse(form.errors, status=400) 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) + + if form.is_valid(): + res = """ + + """.format( + date=timezone.now().isoformat(), + invoice_id=form.cleaned_data.get('invoiceId'), + shop_id=form.cleaned_data.get('shopId'), + ) + + return HttpResponse(res, content_type='application/xml') + else: + res = """ + + """.format( + date=timezone.now().isoformat(), + invoice_id=form.cleaned_data.get('invoiceId'), + shop_id=form.cleaned_data.get('shopId'), + ) + + # return HttpResponse(res, content_type='application/xml') + return HttpResponse('
{msg}
'.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(): + res = """ + + """.format( + date=timezone.now().isoformat(), + invoice_id=form.cleaned_data.get('invoiceId'), + shop_id=form.cleaned_data.get('shopId'), + ) + + return HttpResponse(res, content_type='application/xml') + else: + res = """ + + """.format(date=timezone.now().isoformat()) + + # return HttpResponse(res, content_type='application/xml') + return HttpResponse('
{msg}
'.format(msg=pformat(form.errors))) # Debug