Search code examples
djangopaypalhttp-status-code-403paypal-ipn

Django-Paypal IPN 403 Error


I was working on the paypal ipn listener - it didn't seem to be 'hearing' the signals, although the database was updated so I know the ipn was accepted by the paypal.standard.ipn package.

Now I get a 403 error from the ipn simulator - does anyone have any idea why this would happen? When I navigate directly to the listener url there is no error.

I added @csrf_exempt to the listener, but that didn't help.

Any suggestions are welcome.

Listeners.py:

from django.dispatch import receiver
from django.contrib.sites.models import Site

from django.views.decorators.csrf import csrf_exempt
from paypal.standard.ipn import signals as paypal_signals
from messaging import send
from utests.models import Test
 import logging


@csrf_exempt
@receiver(paypal_signals.payment_was_successful)
def payment_was_succesful_listener(sender, **kwargs):
     #:sender is the PayPalIPN model instance
    logging.debug("in payment successful listener")
    ... the rest of the code is commented out while I debug...


@receiver(paypal_signals.payment_was_flagged, dispatch_uid="dl-payment_was_flagged")
def payment_was_flagged_listener(sender, **kwargs):
    #:sender is the PayPalIPN model instance
    pass

As you can see, all that is supposed to happen is some debugging, but it doesn't get there.


Solution

  • I just ran into the same issue again. Here is the solution in case anyone else has this problem:

    The @csrf_exempt needs to be added to the django-paypal package itself.

    In paypal/standard/ipn/views.py add:

    from django.views.decorators.csrf import csrf_exempt
    

    at the top, among the rest of the imports, and

    @csrf_exempt
    

    above the @require_POST above the function declaration.