Kaynağa Gözat

remove test() from paypal script

mk200789 10 yıl önce
ebeveyn
işleme
1f374eb08d

+ 14 - 20
hackathon_starter/hackathon/scripts/paypal.py

@@ -96,6 +96,8 @@ class PaypalOauthClient(object):
 		This methods obtain new access token when current access_token expires.
 		'''
 
+		link  = 'https://api.sandbox.paypal.com/v1/identity/openidconnect/tokenservice'
+
 		headers = {
 					'Accept': 'application/json',
 					'Accept-Language': 'en_US',
@@ -104,7 +106,7 @@ class PaypalOauthClient(object):
 		data = { 'grant_type': 'refresh_token',
 				  'refresh_token': refresh_token}
 
-		req = requests.post(access_token_url, data=data, headers=headers, auth=(self.client_id, self.client_secret))
+		req = requests.post(link, data=data, headers=headers, auth=(self.client_id, self.client_secret))
 		
 		if req.status_code != 200:
 			raise Exception("Invalid response %s." %  req.status_code)
@@ -112,28 +114,20 @@ class PaypalOauthClient(object):
 		content = unicodedata.normalize('NFKD', req.text).encode('ascii','ignore')
 		jsonlist = json2.loads(content)
 
-		print jsonlist
+		#print jsonlist
 		self.access_token = jsonlist['access_token']
 		self.token_type = jsonlist['token_type']
 		return self.access_token
 
 
+	def userinfo(self):
+		link = 'https://api.sandbox.paypal.com/v1/identity/openidconnect/userinfo/?schema=openid'
+		headers = { 'Content-Type':'application/json', 
+				   'Authorization': self.token_type + ' '+ self.access_token,
+				   'Accept-Language': 'en_US',
+				   'content-type': 'application/x-www-form-urlencoded'
+				 }
+		req = requests.get(link, headers=headers)
+		#print req.content
 
-
-	def test(self):
-		#link ='https://www.sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/identity/openidconnect/userinfo' #/?schema=openid'
-		link = 'https://api.sandbox.paypal.com/v1/identity/openidconnect/tokenservice'
-		header = { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type':'application/json'}
-		body = { 'schema':'openid', 'access_token': self.access_token}
-		
-		#req = requests.post(link, headers={'Content-Type':'application/json', 'Authorization': self.token_type+' '+self.access_token})
-		req = requests.post(link, headers=header, data=body)
-		
-		if req.status_code != 200:
-			raise Exception("Invalid response %s." %  req.status_code)
-		
-		content = unicodedata.normalize('NFKD', req.text).encode('ascii','ignore')
-		print content
-		
-
-
+	

+ 1 - 0
hackathon_starter/hackathon/views.py

@@ -270,6 +270,7 @@ def paypal(request):
     authorization_code = request.GET['code']
     refresh_token = getPaypal.get_access_token(authorization_code)
     getPaypal.get_refresh_token(refresh_token)
+    #getPaypal.userinfo()
 
     context = {'title':'paypal'}
     return render(request, 'hackathon/paypal.html', context)