Using PayPal Payments Pro (WPP)ΒΆ
PayPal Payments Pro (or “Website Payments Pro”) is a more awesome version of PayPal that lets you accept payments on your site. This is now documented by PayPal as a Classic API and should not be confused with the “PayPal Payments Pro (Payflow Edition)” which is a newer API.
The PayPal Payments Pro solution reuses code from paypal.standard so you’ll
need to include both apps. django-paypal makes the whole process incredibly easy
to use through the provided PayPalPro
class.
Obtain PayPal Pro API credentials: login to PayPal, click My Account, Profile, Request API credentials, Set up PayPal API credentials and permissions, View API Signature.
Edit
settings.py
and addpaypal.standard
andpaypal.pro
to yourINSTALLED_APPS
and put in your PayPal Pro API credentials.INSTALLED_APPS = [ # .. 'paypal.standard', 'paypal.pro', ] PAYPAL_TEST = True PAYPAL_WPP_USER = "???" PAYPAL_WPP_PASSWORD = "???" PAYPAL_WPP_SIGNATURE = "???"
Write a wrapper view for
paypal.pro.views.PayPalPro
:In views.py:
from paypal.pro.views import PayPalPro def nvp_handler(nvp): # This is passed a PayPalNVP object when payment succeeds. # This should do something useful! pass def buy_my_item(request): item = {"paymentrequest_0_amt": "10.00", # amount to charge for item "inv": "inventory", # unique tracking variable paypal "custom": "tracking", # custom tracking variable for you "cancelurl": "http://...", # Express checkout cancel url "returnurl": "http://..."} # Express checkout return url ppp = PayPalPro( item=item, # what you're selling payment_template="payment.html", # template name for payment confirm_template="confirmation.html", # template name for confirmation success_url="/success/", # redirect location after success nvp_handler=nvp_handler) return ppp(request)
Create templates for payment and confirmation. By default both templates are populated with the context variable
form
which contains either aPaymentForm
or aConfirmation
form.payment.html:
<h1>Show me the money</h1> <form method="post" action=""> {{ form }} <input type="submit" value="Pay Up"> </form>
confirmation.html:
<!-- confirmation.html --> <h1>Are you sure you want to buy this thing?</h1> <form method="post" action=""> {{ form }} <input type="submit" value="Yes I Yams"> </form>
Add your view to
urls.py
, and add the IPN endpoint to receive callbacks from PayPal:from django.conf.urls import url, include from myproject import views urlpatterns = [ ... url(r'^payment-url/$', views.buy_my_item), url(r'^paypal/', include('paypal.standard.ipn.urls')), ]
Profit.
Alternatively, if you want to get down to the nitty gritty and perform some
more advanced operations with Payments Pro, use the paypal.pro.helpers.PayPalWPP
class directly.