Commit cd9a35e4 authored by Jérome Perrin's avatar Jérome Perrin

paypal_secure_payment: python3 support

parent 3d10316d
...@@ -26,15 +26,18 @@ ...@@ -26,15 +26,18 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
import zope import contextlib
from six.moves.urllib.parse import urlencode from six.moves.urllib.parse import urlencode
from six.moves.urllib.request import urlopen, Request from six.moves.urllib.request import urlopen, Request
import zope.interface
from zLOG import LOG, DEBUG from zLOG import LOG, DEBUG
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from erp5.component.interface.IPaymentService import IPaymentService from erp5.component.interface.IPaymentService import IPaymentService
@zope.interface.implementer(IPaymentService) @zope.interface.implementer(IPaymentService)
class PaypalService(XMLObject): class PaypalService(XMLObject):
"""Paypal Service for payment""" """Paypal Service for payment"""
...@@ -57,10 +60,7 @@ class PaypalService(XMLObject): ...@@ -57,10 +60,7 @@ class PaypalService(XMLObject):
"""See Payment Service Interface Documentation""" """See Payment Service Interface Documentation"""
def _getFieldList(self, paypal_dict): def _getFieldList(self, paypal_dict):
field_list = [] return list(paypal_dict.items())
for k,v in paypal_dict.iteritems():
field_list.append((k, v))
return field_list
def navigate(self, REQUEST=None, **kw): def navigate(self, REQUEST=None, **kw):
"""See Payment Service Interface Documentation""" """See Payment Service Interface Documentation"""
...@@ -96,13 +96,13 @@ class PaypalService(XMLObject): ...@@ -96,13 +96,13 @@ class PaypalService(XMLObject):
param_dict["cmd"] = "_notify-validate" param_dict["cmd"] = "_notify-validate"
if "service" in param_dict: if "service" in param_dict:
param_dict.pop("service") param_dict.pop("service")
param_list = urlencode(param_dict) param_list = urlencode(param_dict).encode()
paypal_url = self.getLinkUrlString() paypal_url = self.getLinkUrlString()
request = Request(paypal_url, param_list) request = Request(paypal_url, param_list)
request.add_header("Content-type", "application/x-www-form-urlencoded") request.add_header("Content-type", "application/x-www-form-urlencoded")
response = urlopen(request) with contextlib.closing(urlopen(request)) as response:
status = response.read() status = response.read()
LOG("PaypalService status", DEBUG, status) LOG("PaypalService status", DEBUG, status)
method_id = self._getTypeBasedMethod("reportPaymentStatus").id method_id = self._getTypeBasedMethod("reportPaymentStatus").id
getattr(self.activate(), method_id)(response_dict=REQUEST.form) getattr(self.activate(), method_id)(response_dict=REQUEST.form)
return status == "VERIFIED" return status == b"VERIFIED"
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment