Skip to content

Commit 2f8a0cc

Browse files
[PSDK-47] control of none response
1 parent 94937f3 commit 2f8a0cc

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

examples/operations.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
token = '2977e78d1e3e4c9fa6b70'
2121

2222
auth = ecommerce.authorization(card, amount, token=token)
23+
if not auth:
24+
print('Fallo al realizar el pago, Error al conectar con el servicio')
2325

24-
if auth.code != 0:
26+
elif auth.code != 0:
2527
print('Fallo al realizar el pago, Error: {}'.format(auth.description))
2628

2729
else:
@@ -36,7 +38,10 @@
3638

3739
auth2 = ecommerce.authorization(card, amount)
3840

39-
if auth2.code != 0:
41+
if not auth2:
42+
print('Fallo al realizar el pago, Error al conectar con el servicio')
43+
44+
elif auth2.code != 0:
4045
print('Fallo al realizar el pago, Error: {}'.format(auth2.description))
4146

4247
else:
@@ -49,15 +54,21 @@
4954

5055
auth3 = ecommerce.authorization(card, amount)
5156

52-
if auth3.code != 0:
57+
if not auth3:
58+
print('Fallo al realizar el pago, Error al conectar con el servicio')
59+
60+
elif auth3.code != 0:
5361
print('Fallo al realizar el pago, Error: {}'.format(auth3.description))
5462

5563
else:
5664
print('Pago procesado correctamente')
5765

5866
# cancelar el pago con tarjeta (auth)
5967
cancel = ecommerce.cancellation(auth.transaction_id)
60-
if cancel.code != 0:
68+
if not cancel:
69+
print('Fallo al cancelar el pago, Error al conectar con el servicio')
70+
71+
elif cancel.code != 0:
6172
print('Fallo al cancelar el pago, Error: {}'.format(cancel.description))
6273

6374
else:
@@ -67,7 +78,10 @@
6778
amount = Amount(834, 'EUR')
6879

6980
refund = ecommerce.refund(auth2.transaction_id, amount)
70-
if refund.code != 0:
81+
if not refund:
82+
print('Fallo al hacer la devolución, Error al conectar con el servicio')
83+
84+
elif refund.code != 0:
7185
print('Fallo al hacer la devolución, Error: {}'.format(refund.description))
7286

7387
else:
@@ -81,7 +95,10 @@
8195

8296
refund2 = ecommerce.refund(card, amount)
8397

84-
if refund2.code != 0:
98+
if not refund2:
99+
print('Fallo al hacer la devolución, Error al conectar con el servicio')
100+
101+
elif refund2.code != 0:
85102
print('Fallo al hacer la devolución, Error: {}'.format(refund2.description))
86103

87104
else:
@@ -93,7 +110,10 @@
93110

94111
register = ecommerce.register(card, 'newtoken')
95112

96-
if register.code != 0:
113+
if not register:
114+
print('Fallo al registrar la tarjeta, Error al conectar con el servicio')
115+
116+
elif register.code != 0:
97117
print('Fallo al registrar la tarjeta, Error: {}'.format(register.description))
98118

99119
else:
@@ -104,7 +124,10 @@
104124
# Borrar tarjeta de Sipay
105125
unregister = ecommerce.unregister('newtoken')
106126

107-
if unregister.code != 0:
127+
if not unregister:
128+
print('Fallo al borrar la tarjeta de Sipay, Error al conectar con el servicio')
129+
130+
elif unregister.code != 0:
108131
print('Fallo al borrar la tarjeta de Sipay, Error: {}'.format(unregister.description))
109132

110133
else:

examples/querys.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
# Consultar tarjeta
1212
card_res = ecommerce.card('tokenCard')
1313

14-
if card_res.code != 0:
14+
if not card_res:
15+
print('Fallo al consultar la tarjeta, Error al conectar con el servicio')
16+
17+
elif card_res.code != 0:
1518
print('Fallo al consultar la tarjeta, Error: {}'.format(card_res.description))
1619

1720
else:
@@ -22,7 +25,10 @@
2225
# Consultar operación por id
2326
query = ecommerce.query(transaction_id='transaction_id')
2427

25-
if query.code != 0:
28+
if not query:
29+
print('Fallo al hacer la consulta, Error al conectar con el servicio')
30+
31+
elif query.code != 0:
2632
print('Fallo al hacer la consulta, Error: {}'.format(query.description))
2733

2834
else:
@@ -34,7 +40,10 @@
3440
# Consultar operación por ticket
3541
query2 = ecommerce.query(order='order')
3642

37-
if query2.code != 0:
43+
if not query2:
44+
print('Fallo al hacer la consulta, Error al conectar con el servicio')
45+
46+
elif query2.code != 0:
3847
print('Fallo al hacer la consulta, Error: {}'.format(query2.description))
3948

4049
elif query2.code == 0:

0 commit comments

Comments
 (0)