Example #1
0
 def __init__(self):
    ISO8583.__init__(self, iso="", debug=False)
    #obj.redefineBit(self, bit, smallStr, largeStr, bitType, size, valueType)
    ISO8583.redefineBit(self, 7, '7', 'Timestamp', 'N', 14, 'n')
    ISO8583.redefineBit(self, 11, '11', 'TransactionID', 'N', 15, 'an')
    ISO8583.redefineBit(self, 48, '48', 'query', 'LLL', 999, 'ansb')
    ISO8583.redefineBit(self, 63, '63', 'PartnerID', 'LL', 99, 'an')
    #self.redefineBit(64, '64', 'Signature', 'LLL', 999, 'an')
    ISO8583._BITS_VALUE_TYPE[64] = ['64', 'Signature', 'LLL', 999, 'ansb']
Example #2
0
    def run_server(self):
        '''
        Run the server on socket and accept connections
        '''
        #create socket
        self.sock = socket(AF_INET, SOCK_STREAM)
        #bind it on a port
        self.sock.bind((self.serverip, self.port))
        #accept maximum two connections from client
        self.sock.listen(5)
        while True:
            conn, address = self.sock.accept()
            while True:
                iso = conn.recv(2048)
                if iso:
                    pack = ISO8583()
                    #parse ISO
                    pack.setNetworkISO(iso)
                    if not pack.getMTI() == '0200':
                        #print "Cool, thats the format we are accepting connections in "
                        print("PLease send the message MTI as 0200 ")

                    records = pack.getBitsAndValues()

                    #comment out this part, for debugging
                    self.validate_transaction(records)
Example #3
0
    def create_message(self, MTI, account_number, transaction_amount, message):
        '''
        Reads all the account number and creates a random amount transaction
        '''
        iso = ISO8583()
        iso.setMTI(MTI)
        #set the acoount number
        iso.setBit(2, account_number)
        #set the transaction amount
        iso.setBit(4, transaction_amount)
        iso.setBit(63, message)

        return iso
Example #4
0
 def save(self, iso, is_send, request_log=None, payment_id=None):
     row = Iso()
     row.forwarder = self.forwarder 
     row.ip = self.bank_ip
     row.mti = iso.getMTI()
     row.raw = ISO8583.getRawIso(iso)
     row.is_send = is_send
     if request_log:
         row.request_id = request_log.id
     row.payment_id = payment_id
     d = dict()
     for bit in TRANSACTION_BITS:
         try:
             val = iso.get_value(bit)
         except BitNotSet:
             continue
         field = 'bit_{}'.format(str(bit).zfill(3))
         d[field] = val
     row.from_dict(d)
     self.DBSession.add(row)
     self.DBSession.flush()
     self.DBSession.commit()
     return row
Example #5
0
 def save(self, iso, is_send, request_log=None, payment_id=None):
     row = Iso()
     row.forwarder = self.forwarder
     row.ip = self.bank_ip
     row.mti = iso.getMTI()
     row.raw = ISO8583.getRawIso(iso)
     row.is_send = is_send
     if request_log:
         row.request_id = request_log.id
     row.payment_id = payment_id
     d = dict()
     for bit in TRANSACTION_BITS:
         try:
             val = iso.get_value(bit)
         except BitNotSet:
             continue
         field = 'bit_{}'.format(str(bit).zfill(3))
         d[field] = val
     row.from_dict(d)
     self.DBSession.add(row)
     self.DBSession.flush()
     self.DBSession.commit()
     return row
 def getRawIso(self):
     data = self.get_values()
     self.log_info('Encode MTI %s Data %s' % (self.getMTI(), data))
     raw = ISO8583.getRawIso(self)
     self.log_info('ISO8583 to raw %s' % [raw])
     return raw
 def setIsoContent(self, raw):
     self.log_info('Raw to ISO8583 %s' % [raw])
     ISO8583.setIsoContent(self, raw)
     data = self.get_values()
     self.log_info('Decode MTI %s Data %s' % (self.getMTI(), data))
 def __init__(self, from_iso=None, debug=False):
     ISO8583.__init__(self, debug=debug)
     self.from_iso = from_iso
     if from_iso:
         self.from_data = self.get_values()
 def getRawIso(self):
     data = self.get_values()
     self.log_info('Encode MTI %s Data %s' % (self.getMTI(), data))
     raw = ISO8583.getRawIso(self)
     self.log_info('ISO8583 to raw %s' % [raw])
     return raw
s.listen(maxConn)

auth_code = '00000'
response_code = '00'

# Run forever
while 1:
    #wait new Client Connection
    connection, address = s.accept()
    while 1:
        # receive message
        isoStr = connection.recv(2048)
        #isoStr = isoStr[4:2048]
        if isoStr:
            print("\nInput ASCII |%s|" % isoStr)
            pack = ISO8583()
            #change the protocol
            pack.redefineBit(18, '18', 'Merchant Category Code', 'N', 4, 'n')
            pack.redefineBit(60, '60', 'Additional Data', 'LLL', 999, 'ans')
            pack.redefineBit(62, '62', 'Custom Data', 'AN', 26, 'ans')
            #parse the iso
            try:
                if bigEndian:
                    pack.setNetworkISO(isoStr)
                else:
                    pack.setNetworkISO(isoStr, False)

                v1 = pack.getBitsAndValues()
                for v in v1:
                    print('Bit %s of type %s with value = %s' %
                          (v['bit'], v['type'], v['value']))
Example #11
0
along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""

from ISO8583.ISO8583 import ISO8583
from ISO8583.ISOErrors import *

import traceback

import os

os.system(['clear', 'cls'][os.name == 'nt'])

#Enable Debug Information
# It's print a lot of information ... So only use if you are developping the library!
p2 = ISO8583(debug=True)
p2.setMTI('0800')
p2.setBit(2, 2)
p2.setBit(4, 4)
p2.setBit(12, 12)
p2.setBit(21, 21)
p2.setBit(17, 17)
p2.setBit(49, 986)
p2.setBit(99, 99)
print('MTI = %s' % p2.getMTI())
print('Bitmap = %s' % p2.getBitmap())
p2.showIsoBits()

iso = p2.getRawIso()
#Show debug information of the parsing function
print('\n\n\n------------------------------------------\n')
Example #12
0
   00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15    0123456789012345
   -----------------------------------------------    ----------------
00 30 32 31 30 42 32 33 38 30 30 30 31 30 32 43 30    0210B238000102C0
01 38 30 30 34 30 30 30 30 30 30 30 30 30 30 30 30    8004000000000000
02 30 30 30 32 31 30 30 30 30 30 30 30 30 30 30 30    0002100000000000
03 30 30 31 37 30 30 30 31 30 38 31 34 34 36 35 34    0017000108144654
04 36 39 34 32 31 36 31 34 34 36 35 37 30 31 30 38    6942161446570108
05 31 31 30 30 33 30 31 30 30 30 30 30 30 4e 33 39    1100301000000N39
06 39 39 31 35 34 34 34 33 30 33 35 30 30 30 31 39    9915444303500019
07 39 39 31 35 34 34 39 38 36 30 32 30 20 56 61 6c    991544986020 Val
08 6f 72 20 6e 61 6f 20 70 65 72 6d 69 74 69 21 21    ue not allowed!!
09 30 30 39 30 30 30 30 39 35 34 39 32                009000095492

'''
#i2 = ISO8583(debug=True)
i2 = ISO8583()

iso2 = '0210B238000102C080040000000000000002100000000000001700010814465469421614465701081100301000000N399915444303500019991544986020 Value not allowed!!009000095492'
print('\n\n\n------------------------------------------\n')
print('This is the ISO <%s> parse it!' % iso2)

i2.setIsoContent(iso2)
print('Bitmap = %s' % i2.getBitmap())
print('MTI = %s' % i2.getMTI())

print('Bits')
v3 = i2.getBitsAndValues()
for v in v3:
    print('(1) Bit %s of type %s and value = %s' %
          (v['bit'], v['type'], v['value']))
Example #13
0
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""

from ISO8583.ISO8583 import ISO8583
from ISO8583.ISOErrors import *
import traceback

#Clean the shell
import os
os.system(['clear', 'cls'][os.name == 'nt'])

# get new object
p = ISO8583()
#some string describing the transation type
transation = "200"
print('Setting transation type to %s' % transation)
p.setTransationType(transation)
# Is the same that:
#p.setMTI(transation)

#Some tests and
print('Setting bits')

p.setBit(3, "100000")
p.setBit(4, 1200)
p.setBit(7, "1207231505")
p.setBit(11, 12)
p.setBit(12, "231505")
# coding=UTF-8

from ISO8583.ISO8583 import ISO8583

message = ISO8583()
message.setMTI('0800')
message.setBit(3, '300000')
message.setBit(24, '045')
message.setBit(41, '11111111')
message.setBit(42, '222222222222222')
message.setBit(62, '--Mensagem enviada do cliente--')
message.setBit(63, '0810')

print '\nNetwork message: \n%s\n' % message.getNetworkISO()

for v in message.getBitsAndValues():
    print '\t Bit: %s type: %s value: %s' % (v['bit'], v['type'], v['value'])

print '\n'
Example #15
0
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""

from ISO8583.ISO8583 import ISO8583
from ISO8583.ISOErrors import *

import traceback

import os
os.system(['clear', 'cls'][os.name == 'nt'])

# Testing some funcionalities
p2 = ISO8583()
p2.setMTI('0800')
p2.setBit(2, 2)
p2.setBit(4, 4)
p2.setBit(12, 12)
p2.setBit(17, 17)
p2.setBit(99, 99)

print('The MTI is = %s' % p2.getMTI())
print('The Bitmap is = %s' % p2.getBitmap())

#Showing bits...
p2.showIsoBits()

#Save the ASCII ISO value without size
iso = p2.getRawIso()
Example #16
0
s = socket(AF_INET, SOCK_STREAM)    
# bind it to the server port
s.bind((serverIP, serverPort))   
# Configure it to accept up to N simultaneous Clients waiting...
s.listen(maxConn)                        


# Run forever
while 1:
        #wait new Client Connection
        connection, address = s.accept() 
        while 1:
                # receive message
                isoStr = connection.recv(2048) 
                if isoStr:
                        pack = ISO8583()
                        #parse the iso
                        try:
                                pack.setNetworkISO(isoStr)
                                pack.getBitsAndValues()
                        except InvalidIso8583, ii:
                                print ii
                                break
                        except:
                                print 'Something happened!!!!'
                                break
                        
                        #send answer
                        pack.setMTI('0810')
                        ans = pack.getNetworkISO()
                        connection.send(ans)
 def __init__(self, from_iso=None, debug=False):
     ISO8583.__init__(self, debug=debug)
     self.from_iso = from_iso
     if from_iso:
         self.from_data = self.get_values()
 def setIsoContent(self, raw):
     self.log_info('Raw to ISO8583 %s' % [raw])
     ISO8583.setIsoContent(self, raw)
     data = self.get_values()
     self.log_info('Decode MTI %s Data %s' % (self.getMTI(), data))
Example #19
0
        s = socket.socket(af, socktype, proto)
    except socket.error, msg:
        s = None
        continue
    try:
        s.connect(sa)
    except socket.error, msg:
        s.close()
        s = None
        continue
    break
if s is None:
    print('Could not connect :(')
    sys.exit(1)

iso = ISO8583()
iso.redefineBit(41, 41, 'Card Acceptor Terminal Identification', 'N', 16, 'an')
iso.redefineBit(18, 18, 'Merchants Type', 'N', 4, 'n')
iso.setMTI('0200')
iso.setBit(2, '000')
iso.setBit(3, '503011')
iso.setBit(4, '000000010000')
iso.setBit(7, '0172162255')
iso.setBit(11, '006241')
iso.setBit(12, '162255')
iso.setBit(13, '0712')
iso.setBit(15, '0712')
iso.setBit(18, '6011')
iso.setBit(32, '515274')
iso.setBit(37, '000000000000')
iso.setBit(41, 'test123         ')
Example #20
0
s.listen(maxConn)

# Run forever
while 1:
    #wait new Client Connection
    connection, address = s.accept()
    while 1:
        # receive message
        isoStr = connection.recv(2048)

        if isoStr is None or len(isoStr) == 0:
            break
        linenum = inspect.getframeinfo(inspect.currentframe())[1]
        debugstring(isoStr, linenum, len(isoStr))

        pack = ISO8583(debug=True)
        send = ISO8583()
        try:
            pack.setNetworkISO(isoStr)

            ret = recvTrans(pack, sysbit37, sysbit38)
            if ret == "" or ret == None:
                break
            HEADER = "6000030000603100310120"
            doPackTrans(send, ret, HEADER)

            ans = send.getNetworkISO()
        except ISOError as msg:
            print msg
            break
        #except: