I’m trying to follow the Paypal tutorial site to build a simple working Paypal webpage to test with my sandbox accounts. The webpage won’t load and I have the webserver running. My other webpages work fine for my other apps.
(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
urlpatterns = [
path('paypal/', include("paypal.standard.ipn.urls")),
path('payment.html', views.Checkout, name='checkout'),
]
(venv) root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:~/cquence/djangopaypal# cat views.py
from django.shortcuts import render
from django.urls import reverse
from paypal.standard.forms import PayPalPaymentsForm
from django.conf import settings
def Checkout(request):
# What you want the button to do.
paypal_dict = {
"business": "receiver_email@example.com",
"amount": "10000000.00",
"item_name": "name of the item",
"invoice": "unique-invoice-id",
"notify_url": request.build_absolute_uri(reverse('paypal-ipn')),
"return": request.build_absolute_uri(reverse('your-return-view')),
"cancel_return": request.build_absolute_uri(reverse('your-cancel-view')),
"custom": "premium_plan", # Custom command to correlate to some function later (optional)
}
# Create the instance.
form = PayPalPaymentsForm(initial=paypal_dict)
context = {"form": form}
return render(request, "payment.html", context)
(venv) root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:~/cquence/djangopaypal# cat admin.py
from django.contrib import admin
# Register your models here.
(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
def show_me_the_money(sender, **kwargs):
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 != "receiver_email@example.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.
# Undertake some action depending upon `ipn_obj`.
if ipn_obj.custom == "premium_plan":
price = ...
else:
price = ...
if ipn_obj.mc_gross == price and ipn_obj.mc_currency == 'USD':
...
else:
#...
valid_ipn_received.connect(show_me_the_money)
(venv) root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:~/cquence/djangopaypal# cat templates/payment.html
<!DOCTYPE html>
<html>
<head>
<title>Hello, World!</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
(venv) root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:~/cquence/djangopaypal# cd templates/
(venv) root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:~/cquence/djangopaypal/templates# ls
payment.html
(venv) root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:~/cquence/djangopaypal/templates# cat ../../config/urls.py
"""
URL configuration for config project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/5.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path
from web import views as views
urlpatterns = [
path("polls/", include("polls.urls")),
path('', include('registration.urls')),
path('registration/', include('registration.urls')),
path('admin/', admin.site.urls),
path('', include('paypal.standard.ipn.urls')),
path('djangopaypal/', include('djangopaypal.urls')),
#path('', views.index),
]
(venv) root@ubuntu-s-1vcpu-512mb-10gb-sfo3-01:~/cquence/djangopaypal/templates#