Skip to content

Commit 09c4d45

Browse files
first commit
0 parents  commit 09c4d45

31 files changed

+1123
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.pyc
2+
.DS_Store

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright 2013 Stored and other contributors
2+
http://stored.com.br/
3+
4+
Permission is hereby granted, free of charge, to any person obtaining
5+
a copy of this software and associated documentation files (the
6+
"Software"), to deal in the Software without restriction, including
7+
without limitation the rights to use, copy, modify, merge, publish,
8+
distribute, sublicense, and/or sell copies of the Software, and to
9+
permit persons to whom the Software is furnished to do so, subject to
10+
the following conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.rst

Whitespace-only changes.

TODO.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Input validation

maxipago/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""maxiPago python integration"""
2+
# :copyright: (c) 2013 by Stored (www.stored.com.br).
3+
# :license: BSD, see LICENSE for more details.
4+
5+
VERSION = (1, 0, 0)
6+
__version__ = '.'.join(map(str, VERSION[0:3])) + ''.join(VERSION[3:])
7+
__author__ = 'Stored'
8+
__contact__ = '[email protected]'
9+
__docformat__ = 'restructuredtext'
10+
__license__ = 'MIT'
11+
12+
13+
from maxipago.client import Maxipago

maxipago/client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# coding: utf-8
2+
3+
4+
class Maxipago(object):
5+
6+
def __init__(self, maxid, api_key, api_version='3.1.1.15', sandbox=False):
7+
self.maxid = maxid
8+
self.api_key = api_key
9+
self.api_version = api_version
10+
self.sandbox = sandbox
11+
12+
def __getattr__(self, name):
13+
try:
14+
class_name = ''.join([n.title() for n in name.split('_') + ['manager']])
15+
module = __import__('maxipago.managers.{0}'.format(name), fromlist=[''])
16+
klass = getattr(module, class_name)
17+
return klass(self.maxid, self.api_key, self.api_version, self.sandbox)
18+
except ImportError, AttributeError:
19+
if name in self.__dict__:
20+
return self.__dict__.get('name')
21+
else:
22+
raise AttributeError

maxipago/exceptions.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# coding: utf-8
2+
3+
4+
class MaxipagoException(Exception):
5+
def __init__(self, message):
6+
self.message = message
7+
8+
def __str__(self):
9+
return self.message
10+
11+
12+
class ValidationError(MaxipagoException):
13+
def __repr__(self):
14+
return 'ValidationError(%s)' % self.message
15+
16+
17+
# customer
18+
class CustomerException(MaxipagoException):
19+
pass
20+
21+
22+
class CustomerAlreadyExists(CustomerException):
23+
pass
24+
25+
26+
class CardException(MaxipagoException):
27+
pass
28+
29+
30+
class PaymentException(MaxipagoException):
31+
pass

maxipago/managers/__init__.py

Whitespace-only changes.

maxipago/managers/base.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# coding: utf-8
2+
import requests
3+
from maxipago.utils import etree, create_element_recursively
4+
5+
6+
class Manager(object):
7+
api_type = None
8+
9+
def __init__(self, maxid, api_key, api_version, sandbox):
10+
self.maxid = maxid
11+
self.api_key = api_key
12+
self.api_version = api_version
13+
self.sandbox = sandbox
14+
15+
if sandbox:
16+
self.uri_transaction = 'https://testapi.maxipago.net/UniversalAPI/postXML'
17+
self.uri_api = 'https://testapi.maxipago.net/UniversalAPI/postAPI'
18+
self.uri_rapi = 'https://testapi.maxipago.net/ReportsAPI/servlet/ReportsAPI'
19+
else:
20+
self.uri_transaction = 'https://api.maxipago.net/UniversalAPI/postXML'
21+
self.uri_api = 'https://api.maxipago.net/UniversalAPI/postAPI'
22+
self.uri_rapi = 'https://api.maxipago.net/ReportsAPI/servlet/ReportsAPI'
23+
24+
def request(self, xml_data, api_type=None):
25+
uri = self.get_uri(api_type)
26+
response = requests.post(url=uri, data=xml_data, headers={'content-type': 'text/xml'})
27+
return response
28+
29+
def get_uri(self, api_type=None):
30+
api_type = api_type or self.uri_rapi
31+
32+
uri_list = {
33+
'transaction': self.uri_transaction,
34+
'api': self.uri_api,
35+
'rapi': self.uri_rapi,
36+
}
37+
return uri_list.get(self.api_type)
38+
39+
40+
class ManagerApi(Manager):
41+
api_type = 'api'
42+
43+
def send(self, command, params=None, requester=None, api_type=None, resource=None):
44+
if not params:
45+
params = requester.translated_data
46+
47+
root = etree.Element('api-request')
48+
49+
verification = etree.SubElement(root, 'verification')
50+
etree.SubElement(verification, 'merchantId').text = self.maxid
51+
etree.SubElement(verification, 'merchantKey').text = self.api_key
52+
53+
etree.SubElement(root, 'command').text = command
54+
55+
request = etree.SubElement(root, 'request')
56+
57+
for key, value in params:
58+
create_element_recursively(request, key).text = value
59+
60+
xml_data = etree.tostring(root, pretty_print=True, encoding='UTF-8', xml_declaration=True)
61+
62+
response = self.request(xml_data)
63+
if resource:
64+
return resource(data=response.content, requester=requester, manager=self)
65+
return response
66+
67+
68+
class ManagerTransaction(Manager):
69+
api_type = 'transaction'
70+
71+
def send(self, command, params=None, requester=None, api_type=None, resource=None):
72+
if not params:
73+
params = requester.translated_data
74+
75+
root = etree.Element('transaction-request')
76+
77+
etree.SubElement(root, 'version').text = self.api_version
78+
79+
verification = etree.SubElement(root, 'verification')
80+
etree.SubElement(verification, 'merchantId').text = self.maxid
81+
etree.SubElement(verification, 'merchantKey').text = self.api_key
82+
83+
order = etree.SubElement(root, 'order')
84+
85+
command = etree.SubElement(order, command)
86+
87+
for key, value in params:
88+
create_element_recursively(command, key).text = value
89+
90+
xml_data = etree.tostring(root, pretty_print=True, encoding='UTF-8', xml_declaration=True)
91+
92+
response = self.request(xml_data)
93+
if resource:
94+
return resource(data=response.content, requester=requester, manager=self)
95+
return response
96+
97+
98+
class ManagerRapi(Manager):
99+
api_type = 'rapi'
100+
101+
def send(self, command, params=None, requester=None, api_type=None, resource=None):
102+
if not params:
103+
params = requester.translated_data
104+
105+
root = etree.Element('rapi-request')
106+
107+
etree.SubElement(root, 'version').text = self.api_version
108+
109+
verification = etree.SubElement(root, 'verification')
110+
etree.SubElement(verification, 'merchantId').text = self.maxid
111+
etree.SubElement(verification, 'merchantKey').text = self.api_key
112+
113+
etree.SubElement(root, 'command').text = command
114+
115+
request = etree.SubElement(root, 'request')
116+
117+
for key, value in params:
118+
create_element_recursively(request, key).text = value
119+
120+
xml_data = etree.tostring(root, pretty_print=True, encoding='UTF-8', xml_declaration=True)
121+
122+
response = self.request(xml_data)
123+
if resource:
124+
return resource(data=response.content, requester=requester, manager=self)
125+
return response

maxipago/managers/card.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# coding: utf-8
2+
from .base import ManagerApi
3+
from maxipago.requesters.card import CardRequester
4+
from maxipago.resources.card import CardAddResource, CardDeleteResource
5+
6+
7+
class CardManager(ManagerApi):
8+
9+
def add(self, **kwargs):
10+
fields = (
11+
('customer_id', {'translated_name': 'customerId'}),
12+
('number', {'translated_name': 'creditCardNumber'}),
13+
('expiration_month', {'translated_name': 'expirationMonth'}),
14+
('expiration_year', {'translated_name': 'expirationYear'}),
15+
('billing_name', {'translated_name': 'billingName'}),
16+
('billing_address1', {'translated_name': 'billingAddress1'}),
17+
('billing_address2', {'translated_name': 'billingAddress2', 'required': False}),
18+
('billing_city', {'translated_name': 'billingCity'}),
19+
('billing_state', {'translated_name': 'billingState'}),
20+
('billing_zip', {'translated_name': 'billingZip'}),
21+
('billing_country', {'translated_name': 'billingCountry'}),
22+
('billing_phone', {'translated_name': 'billingPhone'}),
23+
('billing_email', {'translated_name': 'billingEmail'}),
24+
('onfile_end_date', {'translated_name': 'onFileEndDate', 'required': False}),
25+
('onfile_permissions', {'translated_name': 'onFilePermissions', 'required': False}),
26+
('onfile_comment', {'translated_name': 'onFileComment', 'required': False}),
27+
('onfile_max_charge_amount', {'translated_name': 'onFileMaxChargeAmount', 'required': False}),
28+
)
29+
requester = CardRequester(fields, kwargs)
30+
return self.send(command='add-card-onfile', requester=requester, resource=CardAddResource)
31+
32+
def delete(self, **kwargs):
33+
fields = (
34+
('customer_id', {'translated_name': 'customerId'}),
35+
('token', {}),
36+
)
37+
requester = CardRequester(fields, kwargs)
38+
return self.send(command='delete-card-onfile', requester=requester, resource=CardDeleteResource)

0 commit comments

Comments
 (0)