Skip to content

Commit

Permalink
ISO8583 fields preprocessing #46
Browse files Browse the repository at this point in the history
  • Loading branch information
juks committed Dec 8, 2019
1 parent dd83a83 commit 0ceaa81
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 176 deletions.
33 changes: 13 additions & 20 deletions lib/iso8583/lib/iso8583.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var ISO8583 = function(packagerName) {
}

this.config = require(packagerConfigFile);

this.format = this.config.format;

this.fields = {};
Expand Down Expand Up @@ -54,7 +53,10 @@ var ISO8583 = function(packagerName) {
packager.type = global.overrides[id].type;
}

result = require('./packer/' + packager.type).pack(row, packager);
var packagerFile = require('./packer/' + packager.type);
if (this.format[id].hasOwnProperty('beforePack')) row = this.format[id].beforePack(row);

result = packagerFile.pack(row, packager);
} catch(e) {
var errMsg = 'Error packing data from bit ' + id + '\nPackager: ' + util.inspect(packager);
throw new Error(errMsg + ': ' + e.message + " " + e.stack);
Expand Down Expand Up @@ -111,25 +113,16 @@ var ISO8583 = function(packagerName) {
return sorted;
};

this.pack = function(data) {
var retMsg = '', retMap = {};
var result;
data = this._sort(data);
for(var i in data) {
result = this._pack(data[i], i);

retMap[i] = result.msg;
retMsg += result.msg;
}

return retMsg;
};

this.packWithBinMask = function(data) {
data = this._sort(data);
var retArr = [];
var totalLength = 0;

// Preprocess data if necessary
if (this.config.processors.hasOwnProperty('beforePack')) {
data = this.config.processors.beforePack(data);
}

data = this._sort(data);

for(var i in data) {
Expand All @@ -150,7 +143,7 @@ var ISO8583 = function(packagerName) {
}

return Buffer.concat(retArr, totalLength);
}
};

this.getBinMask = function(data) {
var data = this._sort(data);
Expand Down Expand Up @@ -179,7 +172,7 @@ var ISO8583 = function(packagerName) {
}

return maskBuf;
}
};

this.hexMask = function(data) {
return data.toString('hex')
Expand All @@ -188,14 +181,14 @@ var ISO8583 = function(packagerName) {

ISO8583.prototype.getOptions = function() {
return this.config.hasOwnProperty('options') ? this.config.options : {};
}
};

ISO8583.prototype.getOption = function(optionName) {
if (this.config.hasOwnProperty('options') && this.config.options.hasOwnProperty('optionName')) {
return this.config.options.optionName;
} else {
return null;
}
}
};

module.exports = ISO8583;
213 changes: 112 additions & 101 deletions lib/iso8583/lib/packager/openWay.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,103 +30,103 @@ exports.options = {

// System error messages reference by code
errors: {
00: 'Approved',
01: 'Refer to card issuer',
02: 'Refer to card issuer\'s special condition',
03: 'Invalid merchant or service provider',
04: 'Pick up card',
05: 'Do not honor',
06: 'Error',
07: 'Pick up card, special condition',
08: 'Honour with identification',
09: 'Request in progress',
10: 'Approved for partial amount',
11: 'Approved (VIP)',
12: 'Invalid transaction',
13: 'Invalid amount',
14: 'No such card',
15: 'No such issuer',
16: 'Approved, update track 3',
17: 'Customer cancellation',
18: 'Customer dispute',
19: 'Re-enter transaction',
20: 'Invalid response',
21: 'No action taken',
22: 'Suspected malfunction',
23: 'Unacceptable transaction fee',
24: 'File update not supported by receiver',
25: 'No such record',
26: 'Duplicate record update, old record replaced',
27: 'File update field edit error',
28: 'File locked out while update',
29: 'File update error, contact acquirer',
30: 'Format error',
31: 'Issuer signed-off',
32: 'Completed partially',
33: 'Expired card',
34: 'Suspect Fraud',
35: 'Pick-up, card acceptor contact acquirer',
36: 'Pick up, card restricted',
37: 'Pick up, call acquirer',
38: 'Pick up, Allowable PIN tries exceed',
39: 'No credit account (Visa ePay)',
40: 'Requested function not supported',
41: 'Pick up, lost card',
42: 'No universal account',
43: 'Pick up, stolen card',
44: 'No investment account',
45: 'Reserved for ISO use',
46: 'Reserved for ISO use2',
47: 'Reserved for ISO use3',
48: 'Reserved for ISO use4',
49: 'Reserved for ISO use5',
50: 'Do not renew',
51: 'Not sufficient funds',
52: 'No checking account',
53: 'No savings account',
54: 'Expired Card',
55: 'Incorrect PIN',
56: 'No card record',
57: 'Not permitted to client',
58: 'Not permitted to POS',
59: 'Suspected fraud',
60: 'Card acceptor contact acquirer',
61: 'Exceeds amount limit',
62: 'Restricted card',
63: 'Security violation',
64: 'Wrong original amount',
65: 'Exceeds frequency limit',
66: 'Acceptor call acquirer',
67: 'Card to be picked up at ATM',
68: 'Response received too late',
69: 'Reserved',
70: 'Invalid transaction; contact card issuer',
71: 'Decline PIN not changed',
72: 'Reserved2',
73: 'Reserved3',
74: 'Reserved4',
75: 'PIN tries exceeded',
76: 'Wrong PIN, tries exceeded',
77: 'Wrong Reference No.',
78: 'Record Not Found',
79: 'Already reversed',
80: 'Network error',
81: 'Foreign network error',
82: 'Time-out at issuer',
83: 'Transaction failed',
84: 'Pre-authorization timed out',
85: 'No reason to decline',
86: 'Unable to verify PIN',
87: 'Purchase Approval Only',
88: 'Cryptographic failure',
89: 'Authentication failure',
90: 'Cutoff is in progress',
91: 'Issuer unavailable',
92: 'Router unavailable',
93: 'Transaction cannot be completed',
94: 'Duplicate Transmission',
95: 'Reconcile error / Auth Not found',
96: 'System malfunction'
'00': 'Approved',
'01': 'Refer to card issuer',
'02': 'Refer to card issuer\'s special condition',
'03': 'Invalid merchant or service provider',
'04': 'Pick up card',
'05': 'Do not honor',
'06': 'Error',
'07': 'Pick up card, special condition',
'08': 'Honour with identification',
'09': 'Request in progress',
'10': 'Approved for partial amount',
'11': 'Approved (VIP)',
'12': 'Invalid transaction',
'13': 'Invalid amount',
'14': 'No such card',
'15': 'No such issuer',
'16': 'Approved, update track 3',
'17': 'Customer cancellation',
'18': 'Customer dispute',
'19': 'Re-enter transaction',
'20': 'Invalid response',
'21': 'No action taken',
'22': 'Suspected malfunction',
'23': 'Unacceptable transaction fee',
'24': 'File update not supported by receiver',
'25': 'No such record',
'26': 'Duplicate record update, old record replaced',
'27': 'File update field edit error',
'28': 'File locked out while update',
'29': 'File update error, contact acquirer',
'30': 'Format error',
'31': 'Issuer signed-off',
'32': 'Completed partially',
'33': 'Expired card',
'34': 'Suspect Fraud',
'35': 'Pick-up, card acceptor contact acquirer',
'36': 'Pick up, card restricted',
'37': 'Pick up, call acquirer',
'38': 'Pick up, Allowable PIN tries exceed',
'39': 'No credit account (Visa ePay)',
'40': 'Requested function not supported',
'41': 'Pick up, lost card',
'42': 'No universal account',
'43': 'Pick up, stolen card',
'44': 'No investment account',
'45': 'Reserved for ISO use',
'46': 'Reserved for ISO use2',
'47': 'Reserved for ISO use3',
'48': 'Reserved for ISO use4',
'49': 'Reserved for ISO use5',
'50': 'Do not renew',
'51': 'Not sufficient funds',
'52': 'No checking account',
'53': 'No savings account',
'54': 'Expired Card',
'55': 'Incorrect PIN',
'56': 'No card record',
'57': 'Not permitted to client',
'58': 'Not permitted to POS',
'59': 'Suspected fraud',
'60': 'Card acceptor contact acquirer',
'61': 'Exceeds amount limit',
'62': 'Restricted card',
'63': 'Security violation',
'64': 'Wrong original amount',
'65': 'Exceeds frequency limit',
'66': 'Acceptor call acquirer',
'67': 'Card to be picked up at ATM',
'68': 'Response received too late',
'69': 'Reserved',
'70': 'Invalid transaction; contact card issuer',
'71': 'Decline PIN not changed',
'72': 'Reserved2',
'73': 'Reserved3',
'74': 'Reserved4',
'75': 'PIN tries exceeded',
'76': 'Wrong PIN, tries exceeded',
'77': 'Wrong Reference No.',
'78': 'Record Not Found',
'79': 'Already reversed',
'80': 'Network error',
'81': 'Foreign network error',
'82': 'Time-out at issuer',
'83': 'Transaction failed',
'84': 'Pre-authorization timed out',
'85': 'No reason to decline',
'86': 'Unable to verify PIN',
'87': 'Purchase Approval Only',
'88': 'Cryptographic failure',
'89': 'Authentication failure',
'90': 'Cutoff is in progress',
'91': 'Issuer unavailable',
'92': 'Router unavailable',
'93': 'Transaction cannot be completed',
'94': 'Duplicate Transmission',
'95': 'Reconcile error / Auth Not found',
'96': 'System malfunction'
}
};

Expand All @@ -136,6 +136,12 @@ exports.format = {
name: 'Message Type Indicator',
type: 'fixed-hn',
alias: ''
/*
To have any field-specific logic of your own executed before packing the message, use 'beforePack method
beforePack: function(fieldValue) {
return fieldValue;
}*/
},
'1': {
length: 8,
Expand Down Expand Up @@ -521,7 +527,7 @@ exports.format = {
type: 'fixed-b',
alias: ''
}
}
};

exports.validators = {
isValidMessage: function(data) {
Expand All @@ -532,7 +538,7 @@ exports.validators = {
isExpiredPacket: function(packet, expirationLimitSeconds) {
return false;
}
}
};

exports.generators = {
getHeader: function(lengthVal) {
Expand All @@ -542,7 +548,7 @@ exports.generators = {

return b;
}
}
};

exports.processors = {
splitByHeader: function(message) {
Expand All @@ -560,5 +566,10 @@ exports.processors = {
}

return result;
},

// This method is triggered for every packet before it is being packed
beforePack: function(data) {
return data;
}
}
};
Loading

0 comments on commit 0ceaa81

Please sign in to comment.