Commit 4df644c6 authored by Rafael Monnerat's avatar Rafael Monnerat Committed by Xiaowu Zhang

Include API to query Transactions informations on Paypal

parent 7f82568d
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2010,2013 Nexedi SA and Contributors. All Rights Reserved.
# François-Xavier Algrain <fxalgrain@tiolive.com> # François-Xavier Algrain <fxalgrain@tiolive.com>
# Gabriel Monnerat <gabriel@nexedi.com>
# #
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential # programmers who take the whole responsability of assessing all potential
...@@ -27,16 +28,71 @@ ...@@ -27,16 +28,71 @@
# #
############################################################################## ##############################################################################
import zope import zope
from cgi import parse_qsl
from urllib import urlencode from urllib import urlencode
from urllib2 import urlopen, Request from urllib2 import urlopen, Request
from zLOG import LOG, DEBUG from zLOG import LOG, DEBUG, WARNING
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.Document import newTempDocument from Products.ERP5Type.Document import newTempDocument
class PaypalService(XMLObject): def response_to_dict(response):
return dict(parse_qsl(response))
class PaypalWebServiceMixin:
def getCredential(self):
return urlencode({"USER": self.getServiceUsername(),
"PWD": self.getServicePassword(),
"SIGNATURE": self.getServiceSignature(),
"VERSION":"65.2",}) + "&"
def getTransactionIDList(self, start_date, **kw):
nvp_link = self.getNvpLink()
credential = self.getCredential()
parameter_dict = {"METHOD": "TransactionSearch",
"STARTDATE": start_date.strftime("%Y-%m-%dT%H:%M:%SZ")}
for key, value in kw.iteritems():
parameter_dict[key] = value
query_string = credential + urlencode(parameter_dict)
response = urlopen(nvp_link, query_string).read()
response_dict = response_to_dict(response)
if response_dict.get("ACK", "") != "Success":
LOG("Paypal Failure", WARNING, response_dict)
return filter(lambda x: x[0].startswith("L_TRANSACTIONID"), response_dict.items())
def getTransactionList(self, start_date, **kw):
nvp_link = self.getNvpLink()
credential = self.getCredential()
transaction_id_list = self.getTransactionIDList(start_date, **kw)
LOG("Paypal", DEBUG, transaction_id_list)
transaction_dict = {}
for key,transaction_id in transaction_id_list:
parameter_dict = {"METHOD": "GetTransactionDetails",
"TRANSACTIONID": transaction_id}
query_string = credential + urlencode(parameter_dict)
response = urlopen(nvp_link, query_string).read()
response_dict = response_to_dict(response)
if response_dict["ACK"] != "Success":
LOG("Paypal Failure", WARNING, response_dict)
continue
transaction_dict[transaction_id] = response_dict
return transaction_dict
def getTransaction(self, transaction_id):
parameter_dict = {"METHOD": "GetTransactionDetails",
"TRANSACTIONID": transaction_id}
query_string = self.getCredential() + urlencode(parameter_dict)
response = urlopen(self.getNvpLink(), query_string).read()
response_dict = response_to_dict(response)
return response_dict
class PaypalService(XMLObject, PaypalWebServiceMixin):
"""Paypal Service for payment""" """Paypal Service for payment"""
meta_type = 'Paypal Service' meta_type = 'Paypal Service'
......
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