Django-paypal not returning IPN's into admin model

I am running django-paypal program; however, it is not returning IPN’s into the admin models table. My site is public facing so I don’t need ngrok. I can see the transactions leaving the customer test account and showing up in the business test account with no issues on the pyapal ledger side.

Here is my views.py

(venv) root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:~/cquence/djangopaypal# cat views.py
import uuid

from django.contrib import messages
from django.shortcuts import render, redirect
from django.urls import reverse
from paypal.standard.forms import PayPalPaymentsForm
from django.conf import settings
from .models import Order

def checkout(request):
  #if request.POST:
        paypal_dict = {
        'business': 'business@cquence.com',
        'amount': '1.00',
        'item_name': 'JIUJITSU REGISTRATION',
        'no_shipping': '2',
        'invoice': str(uuid.uuid4()),
        'currency_code': 'USD',
        'notify_url': request.build_absolute_uri(reverse("paypal-ipn")),
        'return_url': request.build_absolute_uri(reverse("payment-success")),
        'cancel_return': request.build_absolute_uri(reverse("payment-failed")),
    }
    # Create the instance.
    form = PayPalPaymentsForm(initial=paypal_dict)
    context = {"form": form}
    return render(request, "payment.html", context)

def paymentSuccessful(request):
    print("success")
    messages.success(request, 'Payment was successful')
    return render(request, 'payment-success.html')

def paymentFailed(request):
    print("failed")
    messages.error(request, 'Payment Failed')
    return render(request, 'payment-failed.html')

Payments leaving the personal sandbox

Payments incoming into the business sandbox

The admin page shows no IPN’s coming in

I think a problem I’m having is I need to turn on IPN’s on my “test business Paypal sandbox account” side, but I’m not clear on what URL to use for receiving IPN’s.

Payments go through fine to paypal; however the IPN just keeps failing


Have you configured your IPN view according to the docs at Using PayPal Standard IPN — django-paypal 2.0 documentation (steps 4 & 5)? If you believe you have done so, please post that code here for verification.

I did

Main urls.py

(venv) root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:~/cquence/djangopaypal# cat ../config/urls.py
from django.contrib import admin
from django.urls import include, path
from web import views as views

urlpatterns = [
    path('', include('registration.urls')),
    path('registration/', include('registration.urls')),
    path('admin/', admin.site.urls),
    path('', include('paypal.standard.ipn.urls')),
    path('paypal/', include('paypal.standard.ipn.urls')),
    path('djangopaypal/', include('djangopaypal.urls')),
    path('', include('djangopaypal.urls')),
]

app urls.py

(venv) root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:~/cquence/djangopaypal# cat urls.py
from django.urls import path, include
from . import views
from .views import checkout
from .views import paymentSuccessful
from .views import paymentFailed

urlpatterns = [
    path('paypal/', include("paypal.standard.ipn.urls")),
    path('', include("paypal.standard.ipn.urls")),
    path('payment.html', checkout, name='checkout'),
    path('payment-success.html', paymentSuccessful, name='payment-success'),
    path('payment-failed.html', paymentFailed, name='payment-failed'),
]

Paypal settings in settings.py

(venv) root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:~/cquence/djangopaypal# cat ../config/settings.py

PAYPAL_RECIEVER_EMAIL = 'business@cquence.com'
PAYPAL_TEST = True

apps.py

(venv) root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:~/cquence/djangopaypal# cat apps.py
from django.apps import AppConfig

class DjangopaypalConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'djangopaypal'

    def ready(self):
        import djangopaypal.hooks

hooks.py

(venv) root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:~/cquence/djangopaypal# cat hooks.py
from paypal.standard.models import ST_PP_COMPLETED
from paypal.standard.ipn.signals import valid_ipn_received
from django.dispatch import receiver
from django.conf import settings

@receiver(valid_ipn_received)
def paypal_payment_received(sender, **kwargs):
    ipn_obj = sender
    if ipn_obj.payment_status == ST_PP_COMPLETED:
        print(ipn_obj)
        print(f'Amount Paid: {ipn_obj.mc_gross}')
    else:
        print(ipn_obj)
        print(f'Amount Paid: {ipn_obj.mc_gross}')
        print(f'Paypal payment status not completed: {ipn_obj.payment_status}')

Are you seeing any requests coming in from unknown or unusual addresses attempting to access anything looking like a payments URL? (Check both your server’s access and error logs.)

Not much to go off of. Is there a debug mode or verbose setting I can put nginx in to get more details in the logs?

68.116.247.99 - - [12/Sep/2024:16:07:48 +0000] "GET /payment.html HTTP/1.1" 200 587 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
68.116.247.99 - - [12/Sep/2024:16:08:07 +0000] "GET /payment-success.html?PayerID=W7Q4UB3DE92EG HTTP/1.1" 200 454 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:/var/log/nginx# cat error.log
root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:/var/log/nginx# date
Thu Sep 12 16:10:14 UTC 2024
root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:/var/log/nginx#

So there are two separate issues here - first, you’re not showing any POST submissions to your site from Paypal. Either you’re not seeing them in the logs, or you just didn’t post them here, or they aren’t there. If they aren’t there at all, then you’ve got something wrong with your paypal configuration.

The second issue is that you’ve got a lot of unnecessary duplications of URL definitions that will end up causing problems. You need to ensure that every url module that you are including is being included once. (You’ve got registration.urls included twice, djangopaypal.urls included twice, and paypal.standard.ipn.urls included four times.

That makes sense with my urls.py , I cleaned them up.

(venv) root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:~/cquence# cat config/urls.py
from django.contrib import admin
from django.urls import include, path
from web import views as views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('registration.urls')),
    path('', include('paypal.standard.ipn.urls')),
    path('', include('djangopaypal.urls')),
]
(venv) root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:~/cquence# cat djangopaypal/urls.py
from django.urls import path, include
from . import views
from .views import checkout
from .views import paymentSuccessful
from .views import paymentFailed

urlpatterns = [
    path('payment.html', checkout, name='checkout'),
    path('payment-success.html', paymentSuccessful, name='payment-success'),
    path('payment-failed.html', paymentFailed, name='payment-failed'),
]

I am using only sandbox accounts through Paypal since I’m testing. I have tried digging around for different settings and the only ones that make sense to me that would have any effect are below. I do agree its strange how I’m not getting anything back from Paypal, but I feel like that goes back, to my original question of what should the notification URL be to receive IPN’s?



This still isn’t a good idea. Having multiple entries with path '' means that you have no segregation of URLs. If the same URL path happens to be defined within any two of these included modules, access to the second will be blocked by the first.

This also doesn’t match what the docs tell you to do for the paypal urls.

If you want a better understanding of what’s going on, you should read the source for that package.

The requests back from PayPal should show up in your server logs as a POST request to the paypal/ path if you follow the instructions in the docs. Even if you don’t have the url properly defined, PayPal would still be issuing the request and your server would be returning a 404.