Skip to content

Commit 1b22fa8

Browse files
n3stormddiazpinto
authored andcommitted
Python 2.7 and 3 compatible
Detect which version of python is running and conditionally create variable
1 parent 662fce8 commit 1b22fa8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

redsys/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
import sys
23
import re
34
import hashlib
45
import json
@@ -51,7 +52,11 @@ def decode_parameters(self, parameters):
5152

5253
def encrypt_3DES(self, order):
5354
pycrypto = DES3.new(base64.b64decode(self.secret_key), DES3.MODE_CBC, IV=b'\0\0\0\0\0\0\0\0')
54-
order_padded = order.ljust(16, u'\x00')
55+
if (sys.version_info > (3,0)):
56+
order_padded = order.ljust(16, u'\x00')
57+
else:
58+
order_padded = order.ljust(16, b'\0')
59+
5560
return pycrypto.encrypt(order_padded)
5661

5762
def sign_hmac256(self, encrypted_order, merchant_parameters):

0 commit comments

Comments
 (0)