Я пытаюсь обработать сигнал valid_ipn_received
из пакета django-paypal (документы: https://django -paypal.readthedocs.io / en / stable / standard / ipn.html )
engine / signal.py
from paypal.standard.models import ST_PP_COMPLETED
from paypal.standard.ipn.signals import valid_ipn_received
from engine.models import DatasetRequest
from django.views.decorators.csrf import csrf_exempt
def show_me_the_money(sender, **kwargs):
print('test')
ipn_obj = sender
if ipn_obj.payment_status == ST_PP_COMPLETED:
# WARNING !
# Check that the receiver email is the same we previously
# set on the `business` field. (The user could tamper with
# that fields on the payment form before it goes to PayPal)
if ipn_obj.receiver_email != "paypalemail@gmail.com":
# Not a valid payment
return
# ALSO: for the same reason, you need to check the amount
# received, `custom` etc. are all what you expect or what
# is allowed.
if ipn_obj.mc_gross == ipn_obj.amount and ipn_obj.mc_currency == 'USD':
pk = ipn_obj.invoice
dsr = DatasetRequest.objects.get(pk=pk)
dsr.is_paid = True
dsr.save()
else:
pass
valid_ipn_received.connect(show_me_the_money)
engine / apps.py
from django.apps import AppConfig
class EngineConfig(AppConfig):
name = 'engine'
def ready(self):
import engine.signals
engine / views.py
def pay_for_dataset_request(request, dsr_pk):
# dsr_pk = dataset request primary key
dsr = DatasetRequest.objects.get(pk=dsr_pk)
paypal_dict = {
"business": "paypalemail@gmail.com",
"amount": dsr.reward,
"item_name": dsr.title,
"invoice": dsr.pk,
"notify_url": request.build_absolute_uri(reverse('paypal-ipn')),
"return": request.build_absolute_uri(reverse('datasetrequest_detail', kwargs={'pk': dsr.pk, 'slug': dsr.slug})),
"cancel_return": request.build_absolute_uri(reverse('datasetrequest_detail', kwargs={'pk': dsr.pk, 'slug': dsr.slug})),
}
# Create the instance.
form = PayPalPaymentsForm(initial=paypal_dict)
context = {"form": form}
return render(request, "payment.html", context)
«valid_ipn_received» - этоне стреляет, когда я делаю платежи на 127.0.0.1:8000, ни ngrok, ни мой производственный сервер.Что не так с моим кодом?Я новичок в сигналах.