diff --git a/project/customer/consts.py b/project/customer/consts.py index 49f1364..1323b14 100644 --- a/project/customer/consts.py +++ b/project/customer/consts.py @@ -20,7 +20,7 @@ LICENSE_STATUSES = ( PAYFORMS = ( (-1, u'Бесплатно'), (0, u'Безналичный расчёт'), - (1, u'Робокасса'), + (1, u'Яндекс-касса'), (2, u'Квитанция Сбербанка'), ) diff --git a/project/customer/forms.py b/project/customer/forms.py index c7e19c9..248730d 100644 --- a/project/customer/forms.py +++ b/project/customer/forms.py @@ -4,6 +4,7 @@ from django.utils.encoding import force_unicode from django.utils.safestring import mark_safe from django.conf import settings +from yandex_money.forms import PaymentForm from project.commons.forms import MyBaseModelForm, set_field_error from . import consts, models @@ -464,3 +465,7 @@ class LicenseForm(forms.Form): payform = forms.ChoiceField(choices=consts.PAYFORMS[1:], widget=forms.RadioSelect, label=u'Форма оплаты') + +class YaForm(PaymentForm): + def get_display_field_names(self): + return () diff --git a/project/customer/urls.py b/project/customer/urls.py index 66d5178..be7a31f 100644 --- a/project/customer/urls.py +++ b/project/customer/urls.py @@ -18,9 +18,10 @@ urlpatterns = patterns('', url(r'^license/$', license.order_license, name='customer_order_license'), url(r'^delete_license/(?P\d+)/$', license.delete_license, name='customer_delete_license'), url(r'^get_doc/(?P\d+)/$', docs.get_doc, name='customer_license_get_doc'), - url(r'^robokassa/result/$', license.payment_result, name='robokassa_result'), - url(r'^robokassa/success/$', license.payment_success, name='robokassa_success'), - url(r'^robokassa/fail/$', license.payment_fail, name='robokassa_fail'), + url(r'^payment/confirm/(?P\d+)$', license.yandex_pay, name='yamoney_confirm'), + url(r'^payment/result/$', license.payment_result, name='yamoney_result'), + url(r'^payment/success/$', license.payment_success, name='yamoney_success'), + url(r'^payment/fail/$', license.payment_fail, name='yamoney_fail'), url(r'^license_list/$', license.license_list, name='customer_license_list'), url(r'^paid_list/$', license.paid_list, name='customer_paid_list'), diff --git a/project/customer/views/license.py b/project/customer/views/license.py index d560b33..cc25a58 100644 --- a/project/customer/views/license.py +++ b/project/customer/views/license.py @@ -12,9 +12,22 @@ from django.template.response import TemplateResponse from django.core.urlresolvers import reverse from django.views.decorators.csrf import csrf_protect +from yandex_money.models import Payment + from ..models import License, LicensePrice from ..consts import PAYFORMS -from ..forms import LicenseForm +from ..forms import LicenseForm, YaForm + + +@login_required +@csrf_protect +def yandex_pay(request, payment_id): + template_name = 'customer/profile/yandex.html' + payment = Payment.objects.get(id=payment_id) + if payment.user != request.user: + raise + form = YaForm(instance=payment) + return render(request, template_name, {'form': form}) @login_required @@ -37,21 +50,22 @@ def order_license(request): ) new_license.save() if form.cleaned_data['payform'] == '1': - sMerchantLogin = settings.ROBOKASSA_LOGIN - nOutSum = form.cleaned_data['term'].price - nInvId = new_license.id - sInvDesc = u"Оплата лицензии Документор.ру" - sign_str = u"%s:%s:%s:%s" % (sMerchantLogin, nOutSum, nInvId, settings.ROBOKASSA_PASSWORD1) - sSignatureValue = hashlib.md5(sign_str).hexdigest() - sEmail = request.user.email - - robokassa = '%sIndex.aspx?MrchLogin=%s&OutSum=%s&InvId=%s&Desc=%s&SignatureValue=%s&Email=%s&Culture=ru&Encoding=utf-8' % (settings.ROBOKASSA_ADDR, sMerchantLogin, nOutSum, nInvId, urlquote(sInvDesc), sSignatureValue, sEmail) - return redirect(robokassa) + payment, _ = Payment.objects.get_or_create(order_amount=form.cleaned_data['term'].price, + payment_type=Payment.PAYMENT_TYPE.AC, + order_number=new_license.id, + ) + # payment.customer_number=self.buyer.phone + payment.user=request.user + payment.cps_email='' + # payment.cps_phone=self.buyer.phone + payment.save() + # return redirect('https://demomoney.yandex.ru/eshop.xml', **payment.__dict__) + return redirect(reverse('yamoney_confirm', kwargs={'payment_id': payment.id})) + return redirect(reverse('customer_license_list')) return render(request, template_name, dictionary) - @login_required def license_list(request): """Список счетов на лицензии diff --git a/project/settings.py b/project/settings.py index cae7740..3b753b6 100644 --- a/project/settings.py +++ b/project/settings.py @@ -169,7 +169,7 @@ INSTALLED_APPS = ( 'menus', # helper for model independent hierarchical website navigation 'sekizai', # for javascript and css management 'captcha', - #'robokassa', + 'yandex_money', 'djangocms_admin_style', # for the admin skin. You **must** add 'djangocms_admin_style' in the list before 'django.contrib.admin'. 'django.contrib.messages', # to enable messages framework (see :ref:`Enable messages `) 'filer', @@ -226,7 +226,14 @@ LOGGING = { 'level': 'ERROR', 'filters': ['require_debug_false'], 'class': 'django.utils.log.AdminEmailHandler' - } + }, + 'yandex_money': { + 'level': 'DEBUG', + 'class': 'logging.handlers.RotatingFileHandler', + 'filename': path('yandex_money.log'), + 'maxBytes': 1024 * 1024 * 5, + 'backupCount': 5, + }, }, 'loggers': { 'django.request': { @@ -234,6 +241,11 @@ LOGGING = { 'level': 'ERROR', 'propagate': True, }, + 'yandex_money': { + 'handlers': ['yandex_money'], + 'level': 'DEBUG', + 'propagate': False + }, } } @@ -282,12 +294,6 @@ BROKER_VHOST = "dokumentor" CELERY_TIMEZONE = 'Europe/Moscow' CELERY_ACCEPT_CONTENT = ['pickle'] # will be disabled in Celery 3.2 -ROBOKASSA_ADDR = 'http://test.robokassa.ru/' -ROBOKASSA_LOGIN = 'test_shop123456' -ROBOKASSA_PASSWORD1 = 'password123456' -ROBOKASSA_PASSWORD2 = 'password987654' -ROBOKASSA_TEST_MODE = True - from datetime import timedelta CALLBACK_SETTINGS = { @@ -337,6 +343,15 @@ THUMBNAIL_PROCESSORS = ( 'easy_thumbnails.processors.filters', ) +YANDEX_MONEY_DEBUG = False +YANDEX_MONEY_SCID = 12345 +YANDEX_MONEY_SHOP_ID = 56789 +YANDEX_MONEY_SHOP_PASSWORD = 'sQuMtorHE02U' +YANDEX_MONEY_FAIL_URL = 'https://dokumentor.ru/my/payment/fail/' +YANDEX_MONEY_SUCCESS_URL = 'https://dokumentor.ru/my/payment/success/' +# информировать о случаях, когда модуль вернул Яндекс.Кассе ошибку +YANDEX_MONEY_MAIL_ADMINS_ON_PAYMENT_ERROR = True + try: from project.local_settings import * except ImportError: diff --git a/project/templates/customer/profile/license.html b/project/templates/customer/profile/license.html index cd80994..24dee1e 100644 --- a/project/templates/customer/profile/license.html +++ b/project/templates/customer/profile/license.html @@ -10,6 +10,7 @@ {% endif %}
+
{% csrf_token %} diff --git a/project/templates/customer/profile/yandex.html b/project/templates/customer/profile/yandex.html new file mode 100644 index 0000000..dbb6378 --- /dev/null +++ b/project/templates/customer/profile/yandex.html @@ -0,0 +1,29 @@ +{% extends "base.html" %} +{% load pytils_numeral %} +{% block title %}Подтвердить платёж{% endblock %} + +{% block content %} +

Купить лицензию

+ + {% if form.non_field_errors %} +

{{ form.non_field_errors }}

+ {% endif %} + +
+
+ + + {{ form.as_ul }} +

Сумма: + {{ form.sum.value }}

+
+ +
+ +
+
+{% endblock %} + +{% block js %} +{% endblock %} + diff --git a/project/urls.py b/project/urls.py index f763d67..3f29060 100644 --- a/project/urls.py +++ b/project/urls.py @@ -30,6 +30,7 @@ urlpatterns = patterns('', url(r'^user/', include('project.myauth.urls')), url(r'^captcha/', include('captcha.urls')), url(r'^', include('cms.urls')), + url(r'^yandex-money/', include('yandex_money.urls')), ) diff --git a/project/yandex_money.log b/project/yandex_money.log new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt index a56ed30..76238e5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,7 +19,7 @@ django-filer==0.9.9 django-filter==0.7 django-mptt==0.6.1 django-polymorphic==0.6.1 -django-robokassa==1.2 +git+https://github.com/yandex-money/yandex-money-kit-django.git@2b9865847b53702174518d004b0a3aff5277e54f django-sekizai==0.7 django-simple-captcha==0.4.2 djangocms-admin-style==0.2.2