Skip to content

Commit

Permalink
Merge branch 'master' of github.com:dcramer/django-paypal
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Jul 19, 2010
2 parents 78da416 + e01b118 commit 2c391f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
.pydevproject
/dist
/build
/django_paypal.egg-info
/django_paypal.egg-info
*.swp
17 changes: 13 additions & 4 deletions paypal/standard/ipn/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
# -*- coding: utf-8 -*-
from django.http import HttpResponse
from django.views.decorators.http import require_POST
from django.views.decorators.csrf import csrf_exempt
from paypal.standard.ipn.forms import PayPalIPNForm
from paypal.standard.ipn.models import PayPalIPN


@require_POST
@csrf_exempt
def ipn(request, item_check_callable=None):
"""
PayPal IPN endpoint (notify_url).
Expand All @@ -16,30 +18,37 @@ def ipn(request, item_check_callable=None):
PayPal IPN Simulator:
https://developer.paypal.com/cgi-bin/devscr?cmd=_ipn-link-session
"""
#TODO: Clean up code so that we don't need to set None here and have a lot
# of if checks just to determine if flag is set.
flag = None
ipn_obj = None

# Clean up the data as PayPal sends some weird values such as "N/A"
data = request.POST.copy()
date_fields = ('time_created', 'payment_date', 'next_payment_date', 'subscr_date', 'subscr_effective')
date_fields = ('time_created', 'payment_date', 'next_payment_date',
'subscr_date', 'subscr_effective')
for date_field in date_fields:
if data.get(date_field) == 'N/A':
del data[date_field]

form = PayPalIPNForm(data)
if form.is_valid():
try:
ipn_obj = form.save(commit=False)
#When commit = False, object is returned without saving to DB.
ipn_obj = form.save(commit = False)
except Exception, e:
flag = "Exception while processing. (%s)" % e
else:
flag = "Invalid form. (%s)" % form.errors

if ipn_obj is None:
ipn_obj = PayPalIPN()


#Set query params and sender's IP address
ipn_obj.initialize(request)

if flag is not None:
#We save errors in the flag field
ipn_obj.set_flag(flag)
else:
# Secrets should only be used over SSL.
Expand All @@ -49,4 +58,4 @@ def ipn(request, item_check_callable=None):
ipn_obj.verify(item_check_callable)

ipn_obj.save()
return HttpResponse("OKAY")
return HttpResponse("OKAY")

0 comments on commit 2c391f8

Please sign in to comment.