Answer the question
In order to leave comments, you need to log in
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('/')
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)
urlpatterns = [
url(r'^create/$', views.OrderCreate, name='OrderCreate'),
url(r'^payment/$', views.Payment, name='Payment'),
url(r'^check_order/$', views.CheckOrder, name='CheckOrder'),
]
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question