Skip to content

Commit

Permalink
The complete paypal workflow is now in place, including IPN.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dusty Phillips committed Jun 16, 2010
1 parent 8044221 commit 53a737f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
3 changes: 3 additions & 0 deletions paypal_registration/backend.py
Expand Up @@ -31,6 +31,9 @@ class PaypalBackend(object):
to *True* by default, which means you have to explicitly set it to
False in production instances.
* run syncdb to install the paypal_registration model
* ensure the sites model is correctly set up for your site in the django
admin. It is used to construct the paypal IPN url, so make sure it's
correct.
* create the normal django-registration templates (for the default backend) as well as:
* registration/pay_with_paypal.html which shows a 'pay now' button.
There is an example template in the app templates directory for
Expand Down
Expand Up @@ -16,9 +16,11 @@
<form action="https://www.{% if use_sandbox %}sandbox.{% endif %}paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="{{paypal_id}}" />
<input type="hidden" name="notify_url" value="{{notify_url}}" />
<input type="hidden" name="return" value="{{return_url}}" />
<input type="hidden" name="no_shipping" value="1" />
<input type="hidden" name="return" value="{% url confirm_payment_received %}" />
<!-- widget specifying the amount. Feel free to use a hidden field -->
<!-- widget specifying the amount. Feel free to use a hidden field, option,
etc. Just name it 'amount' -->
<select name="amount">
<option value="300">1 yr</option>
<option value="150">6 mos</option>
Expand Down
6 changes: 5 additions & 1 deletion paypal_registration/urls.py
Expand Up @@ -11,6 +11,7 @@

from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template
from django.views.decorators.csrf import csrf_exempt

from registration.views import activate
from registration.views import register
Expand Down Expand Up @@ -41,8 +42,11 @@
'paypal_registration.views.pay_with_paypal',
name='pay_with_paypal'),
url(r'^payment_confirmation/$',
direct_to_template,
csrf_exempt(direct_to_template),
{'template': 'registration/confirm_payment_received.html'},
name="confirm_payment_received"),
url(r'^paypal_IPN_notify/$',
'paypal_registration.views.paypal_instant_notify',
name='paypal_notify'),
(r'', include('registration.auth_urls')),
)
21 changes: 20 additions & 1 deletion paypal_registration/views.py
@@ -1,12 +1,31 @@
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import HttpResponse
from django.conf import settings
from django.core.urlresolvers import reverse
from django.contrib.sites.models import RequestSite
from django.contrib.sites.models import Site
from django.views.decorators.csrf import csrf_exempt

def pay_with_paypal(request, username):
paypal_id = settings.PAYPAL_ID
use_sandbox = getattr(settings, "USE_PAYPAL_SANDBOX", True)
if Site._meta.installed:
site = Site.objects.get_current()
else:
site = RequestSite(request)
paypal_ipn = "http://%s%s" % (site.domain, reverse('paypal_notify'))
return_url = "http://%s%s" % (site.domain, reverse('confirm_payment_received'))

return render_to_response("registration/pay_with_paypal.html",
RequestContext(request,
{'paypal_id': paypal_id,
'use_sandbox': use_sandbox}))
'use_sandbox': use_sandbox,
'notify_url': paypal_ipn,
'return_url': return_url}))

@csrf_exempt
def paypal_instant_notify(request):
# FIXME: Some validation here is absolutely essential
print("\n\n\nPAYPAL SAID YES\n\n\n")
return HttpResponse("ACK")

0 comments on commit 53a737f

Please sign in to comment.