Skip to content

Commit 9d5d4ba

Browse files
committed
processor readability and error fix
1 parent 9d136b5 commit 9d5d4ba

File tree

3 files changed

+97
-34
lines changed

3 files changed

+97
-34
lines changed

maxipago/resources/payment.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ def process(self):
1313
self.captured = False
1414

1515
tree = etree.parse(StringIO(self.data))
16+
error_code = tree.find('errorCode')
17+
if error_code is not None and error_code != '0':
18+
error_message = tree.find('errorMsg').text
19+
raise PaymentException(message=error_message)
1620

1721
processor_code = tree.find('processorCode')
1822
if processor_code.text.lower() == 'a':

maxipago/utils.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests.py

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import unittest
44
from datetime import date
55
from maxipago import Maxipago, exceptions
6+
from maxipago.utils import payment_processors
67
from random import randint
78

89

@@ -157,7 +158,7 @@ def test_payment_authorize(self):
157158
REFERENCE = randint(1, 100000)
158159

159160
response = self.maxipago.payment.authorize(
160-
processor_id=1,
161+
processor_id=payment_processors.TEST,
161162
reference_num=REFERENCE,
162163

163164
billing_name=u'Fulano de Tal',
@@ -184,7 +185,7 @@ def test_payment_direct(self):
184185
REFERENCE = randint(1, 100000)
185186

186187
response = self.maxipago.payment.direct(
187-
processor_id=1,
188+
processor_id=payment_processors.TEST,
188189
reference_num=REFERENCE,
189190

190191
billing_name=u'Fulano de Tal',
@@ -211,7 +212,7 @@ def test_payment_direct_declined(self):
211212
REFERENCE = randint(1, 100000)
212213

213214
response = self.maxipago.payment.direct(
214-
processor_id=1,
215+
processor_id=payment_processors.TEST,
215216
reference_num=REFERENCE,
216217

217218
billing_name=u'Fulano de Tal',
@@ -234,5 +235,94 @@ def test_payment_direct_declined(self):
234235
self.assertFalse(response.authorized)
235236
self.assertFalse(response.captured)
236237

238+
def test_payment_direct_with_token(self):
239+
CUSTOMER_ID = randint(1, 100000)
240+
241+
response = self.maxipago.customer.add(
242+
customer_id=CUSTOMER_ID,
243+
first_name=u'Fulano',
244+
last_name=u'de Tal',
245+
)
246+
247+
self.assertTrue(hasattr(response, 'id'))
248+
249+
maxipago_customer_id = response.id
250+
251+
response = self.maxipago.card.add(
252+
customer_id=maxipago_customer_id,
253+
number=u'4111111111111111',
254+
expiration_month=u'02',
255+
expiration_year=date.today().year + 3,
256+
billing_name=u'Fulano de Tal',
257+
billing_address1=u'Rua das Alamedas, 123',
258+
billing_city=u'Rio de Janeiro',
259+
billing_state=u'RJ',
260+
billing_zip=u'20123456',
261+
billing_country=u'BR',
262+
billing_phone=u'552140634666',
263+
billing_email=u'[email protected]',
264+
)
265+
266+
self.assertTrue(getattr(response, 'token', False))
267+
REFERENCE = randint(1, 100000)
268+
269+
response = self.maxipago.payment.direct(
270+
processor_id=payment_processors.TEST,
271+
reference_num=REFERENCE,
272+
273+
customer_id=maxipago_customer_id,
274+
token=response.token,
275+
276+
charge_total='100.00',
277+
)
278+
279+
self.assertTrue(response.authorized)
280+
self.assertTrue(response.captured)
281+
282+
def test_payment_direct_with_token_decline(self):
283+
CUSTOMER_ID = randint(1, 100000)
284+
285+
response = self.maxipago.customer.add(
286+
customer_id=CUSTOMER_ID,
287+
first_name=u'Fulano',
288+
last_name=u'de Tal',
289+
)
290+
291+
self.assertTrue(hasattr(response, 'id'))
292+
293+
maxipago_customer_id = response.id
294+
295+
response = self.maxipago.card.add(
296+
customer_id=maxipago_customer_id,
297+
number=u'4111111111111111',
298+
expiration_month=u'02',
299+
expiration_year=date.today().year + 3,
300+
billing_name=u'Fulano de Tal',
301+
billing_address1=u'Rua das Alamedas, 123',
302+
billing_city=u'Rio de Janeiro',
303+
billing_state=u'RJ',
304+
billing_zip=u'20123456',
305+
billing_country=u'BR',
306+
billing_phone=u'552140634666',
307+
billing_email=u'[email protected]',
308+
)
309+
310+
self.assertTrue(getattr(response, 'token', False))
311+
REFERENCE = randint(1, 100000)
312+
313+
response = self.maxipago.payment.direct(
314+
processor_id=payment_processors.TEST,
315+
reference_num=REFERENCE,
316+
317+
customer_id=maxipago_customer_id,
318+
token=response.token,
319+
320+
charge_total='100.01',
321+
)
322+
323+
self.assertFalse(response.authorized)
324+
self.assertFalse(response.captured)
325+
326+
237327
if __name__ == '__main__':
238328
unittest.main()

0 commit comments

Comments
 (0)