Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added pdt

  • Loading branch information...
commit 2f78adc67f14142cb99a5e65e6754d5777c8634d 1 parent bf4781f
Michael Thornhill authored
Showing with 60 additions and 1 deletion.
  1. +1 −0  .gitignore
  2. +59 −1 standard/views.py
View
1  .gitignore
@@ -1,3 +1,4 @@
+*.pyc
.svn
.project
.pydevproject
View
60 standard/views.py
@@ -7,6 +7,12 @@
from paypal.standard.forms import *
from paypal.standard.models import PayPalIPN
+from models import POSTBACK_ENDPOINT, SANDBOX_POSTBACK_ENDPOINT
+from urllib import unquote_plus
+import urllib2
+import logging
+
+log = logging.getLogger('paypal')
# PayPal IPN Simulator:
# https://developer.paypal.com/cgi-bin/devscr?cmd=_ipn-link-session
@@ -47,4 +53,56 @@ def ipn(request, item_check_callable=None):
ipn_obj.verify(item_check_callable, test=False)
ipn_obj.save()
- return HttpResponse("OKAY")
+ return HttpResponse("OKAY")
+
+
+def pdt(request):
+ """
+ Payment data transfer implementation
+ https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_html_paymentdatatransfer
+ """
+
+ if not settings.PAYPAL_IDENTITY_TOKEN:
+ raise Exception("You must set settings.PAYPAL_IDENTITY_TOKEN in settings.py, you can get this token by enabling PDT in your paypal business account")
+
+ transaction_status = ''
+ tx = request.GET.get('tx', '')
+
+ postback_dict={}
+ postback_dict["cmd"]="_notify-synch"
+ postback_dict["at"]=settings.PAYPAL_IDENTITY_TOKEN
+ postback_dict["tx"]=tx
+ postback_params=urlencode(postback_dict)
+
+ PP_URL = POSTBACK_ENDPOINT
+ if settings.DEBUG:
+ PP_URL = SANDBOX_ENDPOINT
+
+ req = urllib2.Request(PP_URL)
+ req.add_header("Content-type", "application/x-www-form-urlencoded")
+ fo = urllib2.urlopen(PP_URL, postback_params)
+ paypal_response = fo.read()
+ fo.close()
+ paypal_response_list = paypal_response.split('\n')
+
+ paypal_response_dict = {}
+ i = 0
+ for paypal_line in paypal_response_list:
+ unquoted_paypal_line = unquote_plus(paypal_line)
+ if i == 0:
+ transaction_status = unquoted_paypal_line.strip()
+ else:
+ if transaction_status == 'SUCCESS':
+ try:
+ [k, v] = unquoted_paypal_line.split('=')
+ paypal_response_dict[k.strip()]=v.strip()
+ except ValueError, e:
+ log.error("comfirm_pay_pal error, %s, st=%s"%(e, unquoted_paypal_line))
+ else:
+ log.error('transaction_status = %s'%transaction_status)
+ i = i + 1
+
+ payment_status = ''
+
+ return render_to_response('paypal/standard/pdt.html', {'tx': tx,
+ 'paypal_response_dict': paypal_response_dict, 'transaction_status': transaction_status, 'payment_status': payment_status})
Please sign in to comment.
Something went wrong with that request. Please try again.