diff --git a/lib/iso8583/lib/iso8583.js b/lib/iso8583/lib/iso8583.js index 5626d86..a5e6f8b 100644 --- a/lib/iso8583/lib/iso8583.js +++ b/lib/iso8583/lib/iso8583.js @@ -12,7 +12,6 @@ var ISO8583 = function(packagerName) { } this.config = require(packagerConfigFile); - this.format = this.config.format; this.fields = {}; @@ -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); @@ -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) { @@ -150,7 +143,7 @@ var ISO8583 = function(packagerName) { } return Buffer.concat(retArr, totalLength); - } + }; this.getBinMask = function(data) { var data = this._sort(data); @@ -179,7 +172,7 @@ var ISO8583 = function(packagerName) { } return maskBuf; - } + }; this.hexMask = function(data) { return data.toString('hex') @@ -188,7 +181,7 @@ 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')) { @@ -196,6 +189,6 @@ ISO8583.prototype.getOption = function(optionName) { } else { return null; } -} +}; module.exports = ISO8583; \ No newline at end of file diff --git a/lib/iso8583/lib/packager/openWay.js b/lib/iso8583/lib/packager/openWay.js index 5530645..f37353e 100644 --- a/lib/iso8583/lib/packager/openWay.js +++ b/lib/iso8583/lib/packager/openWay.js @@ -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' } }; @@ -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, @@ -521,7 +527,7 @@ exports.format = { type: 'fixed-b', alias: '' } -} +}; exports.validators = { isValidMessage: function(data) { @@ -532,7 +538,7 @@ exports.validators = { isExpiredPacket: function(packet, expirationLimitSeconds) { return false; } -} +}; exports.generators = { getHeader: function(lengthVal) { @@ -542,7 +548,7 @@ exports.generators = { return b; } -} +}; exports.processors = { splitByHeader: function(message) { @@ -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; } -} +}; diff --git a/lib/iso8583/lib/packager/smartVista.js b/lib/iso8583/lib/packager/smartVista.js index 65459ac..b9fd845 100644 --- a/lib/iso8583/lib/packager/smartVista.js +++ b/lib/iso8583/lib/packager/smartVista.js @@ -47,58 +47,58 @@ exports.options = { // System error messages reference by code errors: { - 000: 'Successful Transaction', - 001: 'Approve with ID. If transaction was Success, but MCC these is in next list 6010, 4829, 6051, 7995, 7511 – then reason code changes on 001', - 002: 'ATM performed a partial dispense', - 003: 'Successful Transaction', - 005: 'System Error', - 020: 'Successful transaction; used to indicate a negative balance in Field 4 on a Balance Inquiry', - 095: 'Reconcile Error', - 100: 'Do Not Honor Transaction', - 101: 'Expired Card', - 103: 'Call Issuer', - 104: 'Card is Restricted', - 105: 'Call Security', - 106: 'Excessive Pin Failures', - 107: 'Call Issuer', - 109: 'Invalid Merchant ID', - 110: 'Cannot Process Amount', - 111: 'Invalid Account - Retry', - 116: 'Insufficient Funds - Retry', - 117: 'Incorrect Pin', - 118: 'Forced Post, no Account on File', - 119: 'Transaction Not Permitted by Law', - 120: 'Not Permitted', - 121: 'Withdrawal Limit Exceeded - Retry', - 123: 'Limit Reached for Total Number of Transactions in Cycle', - 125: 'Bad Card', - 126: 'Pin Processing Error', - 127: 'Pin Processing Error', - 128: 'Pin Processing Error', - 200: 'Invalid Сard', - 201: 'Card Expired', - 202: 'Invalid Card', - 203: 'Call Security', - 204: 'Account Restricted', - 205: 'Call Security', - 206: 'Invalid Pin', - 208: 'Lost Card', - 209: 'Stolen Card', - 902: 'Invalid Transaction - Retry', - 903: 'Transaction Needs to Be Entered Again', - 904: 'The Message Received Was not Within Standards', - 905: 'Issuing Institution is Unknown', - 907: 'Issuer inoperative', - 908: 'Issuing Institution is Unknown', - 909: 'System Malfunction', - 910: 'Issuer Inoperative', - 911: 'SmartVista FE Has Knowledge of Any Attempt to Either Authorize or Deny the Transaction', - 912: 'Timeout Waiting for Response', - 913: 'Duplicate Transaction Received', - 914: 'Could not Find the Original Transaction', - 915: 'Amount Being Reversed is Greater than Original, or no Amount Being Reversed', - 920: 'Pin Processing Error', - 923: 'Request in Progress' + '000': 'Successful Transaction', + '001': 'Approve with ID. If transaction was Success, but MCC these is in next list 6010, 4829, 6051, 7995, 7511 – then reason code changes on 001', + '002': 'ATM performed a partial dispense', + '003': 'Successful Transaction', + '005': 'System Error', + '020': 'Successful transaction; used to indicate a negative balance in Field 4 on a Balance Inquiry', + '095': 'Reconcile Error', + '100': 'Do Not Honor Transaction', + '101': 'Expired Card', + '103': 'Call Issuer', + '104': 'Card is Restricted', + '105': 'Call Security', + '106': 'Excessive Pin Failures', + '107': 'Call Issuer', + '109': 'Invalid Merchant ID', + '110': 'Cannot Process Amount', + '111': 'Invalid Account - Retry', + '116': 'Insufficient Funds - Retry', + '117': 'Incorrect Pin', + '118': 'Forced Post, no Account on File', + '119': 'Transaction Not Permitted by Law', + '120': 'Not Permitted', + '121': 'Withdrawal Limit Exceeded - Retry', + '123': 'Limit Reached for Total Number of Transactions in Cycle', + '125': 'Bad Card', + '126': 'Pin Processing Error', + '127': 'Pin Processing Error', + '128': 'Pin Processing Error', + '200': 'Invalid Сard', + '201': 'Card Expired', + '202': 'Invalid Card', + '203': 'Call Security', + '204': 'Account Restricted', + '205': 'Call Security', + '206': 'Invalid Pin', + '208': 'Lost Card', + '209': 'Stolen Card', + '902': 'Invalid Transaction - Retry', + '903': 'Transaction Needs to Be Entered Again', + '904': 'The Message Received Was not Within Standards', + '905': 'Issuing Institution is Unknown', + '907': 'Issuer inoperative', + '908': 'Issuing Institution is Unknown', + '909': 'System Malfunction', + '910': 'Issuer Inoperative', + '911': 'SmartVista FE Has Knowledge of Any Attempt to Either Authorize or Deny the Transaction', + '912': 'Timeout Waiting for Response', + '913': 'Duplicate Transaction Received', + '914': 'Could not Find the Original Transaction', + '915': 'Amount Being Reversed is Greater than Original, or no Amount Being Reversed', + '920': 'Pin Processing Error', + '923': 'Request in Progress' } }; @@ -108,6 +108,12 @@ exports.format = { name: 'Message Type Indicator', type: 'fixed-n', 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, @@ -233,7 +239,7 @@ exports.format = { length: 12, name: 'Retrieval Reference Number', type: 'fixed-char', - alias: '' + alias: '', }, '38': { length: 6, @@ -287,7 +293,7 @@ exports.format = { length: 255, name: 'EMV Data', type: 'll-bin-char', - alias: '' + alias: '', }, '62': { length: 999, @@ -341,7 +347,7 @@ exports.headerReaders = { 'unpack': function(message, type, index, length) { return require('../packer/' + type).unpack(message.slice(index, index + length), {length: length}).data; } -} +}; // Here we generate header values exports.headerGenerators = { @@ -428,6 +434,11 @@ exports.processors = { } return exports.lengthHeaderLength; + }, + + // This method is triggered for every packet before it is being packed + beforePack: function(data) { + return data; } };