Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajustes para Python3 - add pix e link de pagamento #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Contributions were provided under the MIT License, as appropriate.
The following people have contributed to this lib:
Contributions were provided under the MIT License, as appropriate.

The following people have contributed to this lib:

* [Vinicius Cainelli](https://github.com/viniciuscainelli)
Empty file added __init__.py
Empty file.
3 changes: 1 addition & 2 deletions maxipago/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
# :copyright: (c) 2013 by Stored (www.stored.com.br).
# :license: BSD, see LICENSE for more details.

VERSION = (1, 0, 0)
VERSION = (1, 0, 3)
__version__ = '.'.join(map(str, VERSION[0:3])) + ''.join(VERSION[3:])
__author__ = 'Stored'
__contact__ = '[email protected]'
__docformat__ = 'restructuredtext'
__license__ = 'MIT'


from maxipago.client import Maxipago
2 changes: 1 addition & 1 deletion maxipago/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __getattr__(self, name):
module = __import__('maxipago.managers.{0}'.format(name), fromlist=[''])
klass = getattr(module, class_name)
return klass(self.maxid, self.api_key, self.api_version, self.sandbox)
except ImportError, AttributeError:
except (ImportError, AttributeError) as e:
if name in self.__dict__:
return self.__dict__.get('name')
else:
Expand Down
6 changes: 5 additions & 1 deletion maxipago/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class PaymentException(MaxipagoException):
pass


#http
class TransactionException(MaxipagoException):
pass


# http
class HttpErrorException(MaxipagoException):
pass
3 changes: 2 additions & 1 deletion maxipago/managers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ def send(self, command, params=None, requester=None, api_type=None, resource=Non
etree.SubElement(root, 'command').text = command

request = etree.SubElement(root, 'request')
options = etree.SubElement(request, 'filterOptions')

for key, value in params:
create_element_recursively(request, key).text = value
create_element_recursively(options, key).text = value

xml_data = etree.tostring(root, pretty_print=True, encoding='UTF-8', xml_declaration=True)

Expand Down
29 changes: 29 additions & 0 deletions maxipago/managers/link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# coding: utf-8
from maxipago.managers.base import ManagerTransaction, ManagerApi
from maxipago.requesters.link import LinkRequester
from maxipago.resources.link import LinkResource


class LinkManager(ManagerApi):

def create(self, **kwargs):
fields = (
('consumer_authentication', {'translated_name': 'consumerAuthentication', 'default': 'N'}),
('reference_num', {'translated_name': 'referenceNum'}),
('fraud_check', {'translated_name': 'fraudCheck', 'default': 'N'}),

('billing_email', {'translated_name': 'billing/email'}),
('billing_language', {'translated_name': 'billing/language', 'default': 'pt'}),
('billing_name', {'translated_name': 'billing/firstName'}),
('customer_id', {'translated_name': 'billing/customerIdExt'}),

('payment_info', {'translated_name': 'transactionDetail/description'}),
('email_subject', {'translated_name': 'transactionDetail/emailSubject'}),
('expiration_date', {'translated_name': 'transactionDetail/expirationDate', 'required': False}),
('accept_pix', {'translated_name': 'transactionDetail/acceptPix', 'default': 'Y'}),
('amount', {'translated_name': 'transactionDetail/payType/creditCard/amount'}),
('soft_descriptor', {'translated_name': 'transactionDetail/payType/creditCard/softDescriptor'}),
)

requester = LinkRequester(fields, kwargs)
return self.send(command='add-payment-order', requester=requester, resource=LinkResource)
2 changes: 1 addition & 1 deletion maxipago/managers/payment/payment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding: utf-8
from urllib import urlencode
from urllib.parse import urlencode
from hashlib import md5
from maxipago.managers.base import ManagerTransaction
from maxipago.requesters.payment import PaymentRequester
Expand Down
32 changes: 32 additions & 0 deletions maxipago/managers/pix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# coding: utf-8
from maxipago.managers.base import ManagerTransaction, ManagerApi
from maxipago.requesters.pix import PixRequester


class PixManager(ManagerTransaction):

def create(self, **kwargs):
fields = (
('processor_id', {'translated_name': 'processorID'}),
('reference_num', {'translated_name': 'referenceNum'}),
('fraud_check', {'translated_name': 'fraudCheck', 'default': 'N'}),
('customer_id', {'translated_name': 'customerIdExt'}),
('billing_name', {'translated_name': 'billing/name'}),
('billing_address1', {'translated_name': 'billing/address'}),
('billing_complement', {'translated_name': 'billing/address2'}),
('billing_neighborhood', {'translated_name': 'billing/district'}),
('billing_city', {'translated_name': 'billing/city'}),
('billing_state', {'translated_name': 'billing/state'}),
('billing_zip', {'translated_name': 'billing/postalcode'}),
('billing_country', {'translated_name': 'billing/country', 'default': 'BR'}),
('billing_phone', {'translated_name': 'billing/phone'}),
('billing_email', {'translated_name': 'billing/email'}),
('document_type', {'translated_name': 'billing/documents/document/documentType', 'default': 'CPF'}),
('document', {'translated_name': 'billing/documents/document/documentValue'}),
('expiration_time', {'translated_name': 'transactionDetail/payType/pix/expirationTime'}),
('payment_info', {'translated_name': 'transactionDetail/payType/pix/paymentInfo'}),
('charge_total', {'translated_name': 'payment/chargeTotal'}),
)

requester = PixRequester(fields, kwargs)
return self.send(command='sale', requester=requester)
4 changes: 3 additions & 1 deletion maxipago/managers/transaction.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# coding: utf-8
from maxipago.managers.base import ManagerRapi
from maxipago.requesters.transaction import TransactionRequester
from maxipago.resources.payment import PaymentResource
from maxipago.resources.transaction import TransactionResource


class TransactionManager(ManagerRapi):
Expand All @@ -10,7 +12,7 @@ def get(self, **kwargs):
('transaction_id', {'translated_name': 'transactionId'}),
)
requester = TransactionRequester(fields, kwargs)
return self.send(command='transactionDetailReport', requester=requester)
return self.send(command='transactionDetailReport', requester=requester, resource=TransactionResource)

def list(self, **kwargs):
fields = (
Expand Down
1 change: 1 addition & 0 deletions maxipago/requesters/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# coding: utf-8
from lxml.builder import unicode
from maxipago.exceptions import ValidationError


Expand Down
6 changes: 6 additions & 0 deletions maxipago/requesters/link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# coding: utf-8
from maxipago.requesters.base import Requester


class LinkRequester(Requester):
pass
6 changes: 6 additions & 0 deletions maxipago/requesters/pix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# coding: utf-8
from maxipago.requesters.base import Requester


class PixRequester(Requester):
pass
6 changes: 3 additions & 3 deletions maxipago/resources/card.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding: utf-8
from StringIO import StringIO
# from StringIO import StringIO
from maxipago.utils import etree
from maxipago.resources.base import Resource
from maxipago.exceptions import CardException
Expand All @@ -8,7 +8,7 @@
class CardAddResource(Resource):

def process(self):
tree = etree.parse(StringIO(self.data))
tree = etree.fromstring(self.data)

error_code = tree.find('errorCode').text

Expand All @@ -27,7 +27,7 @@ def process(self):

class CardDeleteResource(Resource):
def process(self):
tree = etree.parse(StringIO(self.data))
tree = etree.fromstring(self.data)

error_code = tree.find('errorCode').text

Expand Down
8 changes: 4 additions & 4 deletions maxipago/resources/customer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding: utf-8
from StringIO import StringIO
# from io import StringIO
from maxipago.utils import etree
from maxipago.resources.base import Resource
from maxipago.exceptions import CustomerAlreadyExists, CustomerException
Expand All @@ -8,7 +8,7 @@
class CustomerAddResource(Resource):

def process(self):
tree = etree.parse(StringIO(self.data))
tree = etree.fromstring(self.data)

error_code = tree.find('errorCode').text

Expand All @@ -31,7 +31,7 @@ def process(self):
class CustomerDeleteResource(Resource):

def process(self):
tree = etree.parse(StringIO(self.data))
tree = etree.fromstring(self.data)

error_code = tree.find('errorCode').text

Expand All @@ -51,7 +51,7 @@ def process(self):
class CustomerUpdateResource(Resource):

def process(self):
tree = etree.parse(StringIO(self.data))
tree = etree.fromstring(self.data)

error_code = tree.find('errorCode').text

Expand Down
28 changes: 28 additions & 0 deletions maxipago/resources/link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# coding: utf-8
# from io import StringIO
from maxipago.utils import etree
from maxipago.resources.base import Resource
from maxipago.exceptions import TransactionException


class LinkResource(Resource):

def process(self):
tree = etree.fromstring(self.data)
error_code = tree.find('errorCode')
if error_code is not None and error_code.text != '0':
error_message = tree.find('errorMessage').text
raise TransactionException(message=error_message)

result = tree.find('result')

fields = [
('url', 'url'),
('pay_order_id', 'pay_order_id'),
('message', 'message')
]

for f_name, f_translated in fields:
field = result.find(f_name)
if field is not None:
setattr(self, f_translated, field.text)
4 changes: 2 additions & 2 deletions maxipago/resources/payment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding: utf-8
from StringIO import StringIO
# from io import StringIO
from maxipago.utils import etree
from maxipago.resources.base import Resource
from maxipago.exceptions import PaymentException
Expand All @@ -12,7 +12,7 @@ def process(self):
self.authorized = False
self.captured = False

tree = etree.parse(StringIO(self.data))
tree = etree.fromstring(self.data)
error_code = tree.find('errorCode')
if error_code is not None and error_code.text != '0':
error_message = tree.find('errorMsg').text
Expand Down
39 changes: 39 additions & 0 deletions maxipago/resources/transaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# coding: utf-8
# from io import StringIO
from maxipago.utils import etree
from maxipago.resources.base import Resource
from maxipago.exceptions import TransactionException


class TransactionResource(Resource):

def process(self):
tree = etree.fromstring(self.data)
header = tree.find('header')
error_code = header.find('errorCode')
if error_code is not None and error_code.text != '0':
error_message = header.find('errorMsg').text
raise TransactionException(message=error_message)

transaction = tree.find('result').find('records').find('record')

fields = [
('transactionId', 'transaction_id'),
('approvalCode', 'auth_code'),
('orderId', 'order_id'),
('referenceNumber', 'reference_num'),
('transactionDate', 'transaction_date'),
('boletoUrl', 'boleto_url'),
('responseCode', 'response_code'),
('transactionAmount', 'amount'),
('transactionStatus', 'status')
]

for f_name, f_translated in fields:
field = transaction.find(f_name)
if field is not None:
setattr(self, f_translated, field.text)

response_message = tree.find('responseMessage')
if response_message is not None and response_message.text:
response_message = response_message.text.lower()
2 changes: 1 addition & 1 deletion maxipago/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from xml import *
from .xml import *
10 changes: 7 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ def get_version():
license='MIT',
keywords='',
url='',
packages=['maxipago'],
packages=['maxipago',
'maxipago.managers',
'maxipago.managers.payment',
'maxipago.requesters',
'maxipago.requesters.payment',
'maxipago.resources',
'maxipago.utils'],
long_description=read_file('README.md'),
classifiers=[
"Topic :: Utilities",
],
install_requires=[
'requests==1.1.0',
'lxml==3.1.0',
],
)
Loading