Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Using PayPal Payments Standard IPN:

1. Download the code from GitHub:

git clone git://github.com/johnboxall/django-paypal.git paypal
git clone git://github.com/shezi/django-paypal.git paypal

1. Edit `settings.py` and add `paypal.standard.ipn` to your `INSTALLED_APPS`
and `PAYPAL_RECEIVER_EMAIL`:
Expand Down Expand Up @@ -142,6 +142,16 @@ Paypal Payment Data Transfer (PDT) allows you to display transaction details to
(r'^paypal/pdt/', include('paypal.standard.pdt.urls')),
...
)
Alternatively, you can use the pdt decorator to work with PDT information in one of your own views.
To do this, add the decorator to one of your views.
# views.py
from paypal.standard.pdt.decorators import pdt

@pdt
def view_func(request, *args, **kwargs):
...
The decorator checks for any GET parameters corresponding to a PDT call and adds the keyword arguments `pdt_active`, `pdt_failed` and `pdt` to the view call.


Using PayPal Payments Standard with Subscriptions:
--------------------------------------------------
Expand Down
56 changes: 56 additions & 0 deletions paypal/standard/pdt/decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# -*- encoding: utf-8 -*-

from paypal.standard.pdt.models import PayPalPDT
from paypal.standard.pdt.forms import PayPalPDTForm


def pdt(f):
"""Parses out GET parameters corresponding to a paypal PDT request and adds `pdt_active`, `pdt_failed` and `pdt` to the call **kwargs.

Payment data transfer implementation: http://tinyurl.com/c9jjmw"""

def aux(request, *args, **kwargs):
if request.method == 'POST':
return f(request, *args, **kwargs)

pdt_obj = None
pdt_active = False
txn_id = request.GET.get('tx')
failed = False
if txn_id is not None:
pdt_active = True
# If an existing transaction with the id tx exists: use it
try:
pdt_obj = PayPalPDT.objects.get(txn_id=txn_id)
except PayPalPDT.DoesNotExist:
# This is a new transaction so we continue processing PDT request
pass

if pdt_obj is None:
form = PayPalPDTForm(request.GET)
if form.is_valid():
try:
pdt_obj = form.save(commit=False)
except Exception, e:
error = repr(e)
failed = True
else:
error = form.errors
failed = True

if failed:
pdt_obj = PayPalPDT()
pdt_obj.set_flag("Invalid form. %s" % error)

pdt_obj.initialize(request)

if not failed:
# The PDT object gets saved during verify
pdt_obj.verify(item_check_callable)
else:
pass # we ignore any PDT requests that don't have a transaction id

kwargs.update({'pdt_active': pdt_active, 'pdt_failed': failed, 'pdt_obj': pdt_obj})
return f(request, *args, **kwargs)

return aux
48 changes: 6 additions & 42 deletions paypal/standard/pdt/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,12 @@
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.views.decorators.http import require_GET
from paypal.standard.pdt.models import PayPalPDT
from paypal.standard.pdt.forms import PayPalPDTForm

from paypal.standard.pdt.decorators import pdt

@require_GET
def pdt(request, item_check_callable=None, template="pdt/pdt.html", context=None):
@pdt
def pdt(request, pdt_active=True, pdt_failed=False, pdt_obj=None, item_check_callable=None, template="pdt/pdt.html", context=None):
"""Payment data transfer implementation: http://tinyurl.com/c9jjmw"""
context = context or {}
pdt_obj = None
txn_id = request.GET.get('tx')
failed = False
if txn_id is not None:
# If an existing transaction with the id tx exists: use it
try:
pdt_obj = PayPalPDT.objects.get(txn_id=txn_id)
except PayPalPDT.DoesNotExist:
# This is a new transaction so we continue processing PDT request
pass

if pdt_obj is None:
form = PayPalPDTForm(request.GET)
if form.is_valid():
try:
pdt_obj = form.save(commit=False)
except Exception, e:
error = repr(e)
failed = True
else:
error = form.errors
failed = True

if failed:
pdt_obj = PayPalPDT()
pdt_obj.set_flag("Invalid form. %s" % error)

pdt_obj.initialize(request)

if not failed:
# The PDT object gets saved during verify
pdt_obj.verify(item_check_callable)
else:
pass # we ignore any PDT requests that don't have a transaction id

context.update({"failed":failed, "pdt_obj":pdt_obj})
return render_to_response(template, context, RequestContext(request))
context = context or {}
context.update({"failed":pdt_failed, "pdt_obj":pdt_obj})
return render_to_response(template, context, RequestContext(request))