Search code examples
djangodjango-paypal

django-paypal ipn works fine but signal is not received


I have this code at the end of my models.py file

from paypal.standard.ipn.signals import payment_was_successful

def confirm_payment(sender, **kwargs):
    # it's important to check that the product exists
    logging.debug('** CONFIRMED PAYMENT ***') #never reached this point
    try:
        bfeat = BuyingFeature.objects.get(slug=sender.item_number)
    except BuyingFeature.DoesNotExist:
        return
    # And that someone didn't tamper with the price
    if int(bfeat.price) != int(sender.mc_gross):
        return
    # Check to see if it's an existing customer
    try:
        customer = User.objects.get(email=sender.payer_email)
    except User.DoesNotExist:
        customer = User.objects.create(
            email=sender.payer_email,
            first_name=sender.first_name,
            last_name=sender.last_name
        )
    # Add a new order
    CustomerOrder.objects.create(customer=customer, feature=bfeat, quantity=1, paypal_email=sender.payer_email, invoice=sender.invoice, remarks='')

payment_was_successful.connect(confirm_payment)

The whole process runs ok. Payment is complete. return_url and cancel_url work fine. notify_url was tested from the paypal sandbox's test tools and works ok. However, signal is never received.

Signal code is placed at the end of the models.py and django-paypal code is placed inside my project's directory.

(code was 'stolen' from here)

I must be doing something completely wrong. Any help would be appreciated!


Solution

  • In django-paypal there are two signals for basic transactions:

    payment_was_successful
    payment_was_flagged
    

    You must handle both signals.