Confirm Paypal payments via PDT and IPN
Homepage Repository PyPI Python
pip install pypay==0.2.1
pypay provides a clean API for confirming Paypal payments via PDT or IPN. It takes the boilerplate out of interacting with these services and normalises the Paypal response into something sensible.
Under the hood pypay uses the excellent Requests library for handling http.
pip install pypay
To check a payment via PDT
import pypay
response = pypay.pdt_confirm('your_transaction_id', 'your_identity_token')
To check a payment via IPN
import pypay
response = pypay.ipn_confirm('query_params_from_paypal')
You can pass the query params as either a string (e.g. 'quantity=1&name=joe') or a dict. This is particularly useful if you're using Django as you can drop in request.POST and everything will just work.
Response objects always have two properties
response.confirmed # bool indicating if payment is verified
response.details # dict containing all the Paypal variables that were returned
In the event of a problem making the http call to Paypal, pypay will raise a pypay.exceptions.RequestError.
The values passed to pdt_confirm and ipn_confirm are sanity checked and a pypay.exceptions.InvalidPaypalData will be raised if they are of the wrong type.
pypay runs on Python 2.6, 2.7, 3.3, 3.4, 3.5 and 3.6 using the Six compatibility library.
Run the test suite with Tox
pip install tox
Tests are written with pytest