33import unittest
44from datetime import date
55from maxipago import Maxipago , exceptions
6+ from maxipago .utils import payment_processors
67from 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,105 @@ 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+ def test_http_exception (self ):
327+ CUSTOMER_ID = randint (1 , 100000 )
328+ customer_manager = self .maxipago .customer
329+ customer_manager .uri_api = 'https://testapi.maxipago.net/UniversalAPI/WrongUri'
330+ with self .assertRaises (exceptions .HttpErrorException ):
331+ customer_manager .add (
332+ customer_id = CUSTOMER_ID ,
333+ first_name = 'Fulano' ,
334+ last_name = 'de Tal' ,
335+ )
336+
337+
237338if __name__ == '__main__' :
238339 unittest .main ()
0 commit comments