A
A
AntonIgin2017-06-07 11:13:19
Django
AntonIgin, 2017-06-07 11:13:19

How to set up HTTP notifications from Yandex.Money in Django?

Actually, the essence of my problem is in the title. You need to accept an HTTP request that comes after the transfer to Yandex.Money. For these purposes, I went to the notification settings: https://money.yandex.ru/myservices/online.xml
In the address field, I indicated a link to the handler view, or more precisely, rankoff.pythonanywhere.com/order/check_order/.
For the test, I took the test_notification variable, which, if I understood the documentation correctly, should be in the request. Here is a link to the document: https://tech.yandex.ru/money/doc/dg/reference/noti...
But nothing comes. Can you suggest what could be the problem?
The code of the view that receives the notification

def CheckOrder(request):
    if request.method=='POST':
        changed_good = Product.objects.get(pk=1)
        changed_good.description='Проверка' #Для проверки факта, что запрос вообще пришел на сервер
        changed_good.save()
        amount = request.POST.get('amount')
        sender = request.POST.get('sender')
        note = ''
        if request.POST.get('test_notification'):
            note = request.POST.get('test_notification')
        mail_host = '[email protected]'
        recipients= ['[email protected]',]
        message = '''
            Вам пришел перевод! Вот данные:
            Сумма:{0}
            Отправитель:{1}
            Секретный код: {2}'''.format(amount, sender, note)
        subject= 'Данные о переводе'
        send_mail(subject, message, mail_host, recipients, fail_silently=False)
    return redirect('/')

I need the Product object card, specified at the beginning of the view, to see that the letter arrived at all and began to be processed. But even the card does not change, that is, either the if condition is not met, or the link in the Yandex settings is incorrect at all. For verification, I am attaching two files urls.
main urls.py
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^cart/', include('shop_cart.urls', namespace='cart')),
    url(r'^order/', include('orders.urls', namespace='orders')),
    url(r'', include('main_site.urls')),
] +static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urls.py application order
urlpatterns = [
    url(r'^create/$', views.OrderCreate, name='OrderCreate'),
    url(r'^payment/$', views.Payment, name='Payment'),
    url(r'^check_order/$', views.CheckOrder, name='CheckOrder'),

]

What have I done wrong? I will be glad for any hints.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FulTupFul, 2019-05-09
@FulTupFul

So the first possible problem is cross domain requests.
https://developer.mozilla.org/ru/docs/Web/HTTP/CORS
Yandex sends you confirmations from its servers and you need to whitelist them and allow the post and get methods. You can resolve cors requests with django-cors:
https://pypi.org/project/django-cors-headers/
See also logs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question