Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sp-nacha

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sp-nacha - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

test/ach_file/ACH011001726PEIN2023092211583479.ach

242

lib/batch/index.js

@@ -12,172 +12,172 @@ // Batch

function Batch(options) {
this._entries = [];
this._entries = [];
// Allow the batch header/control defaults to be overriden if provided
this.header = options.header ? _.merge(options.header, require('./header'), _.defaults) : _.cloneDeep(require('./header'));
this.control = options.control ? _.merge(options.header, require('./control'), _.defaults) : _.cloneDeep(require('./control'));
// Allow the batch header/control defaults to be overriden if provided
this.header = options.header ? _.merge(options.header, require('./header'), _.defaults) : _.cloneDeep(require('./header'));
this.control = options.control ? _.merge(options.header, require('./control'), _.defaults) : _.cloneDeep(require('./control'));
// Configure high-level overrides (these override the low-level settings if provided)
utils.overrideLowLevel(highLevelHeaderOverrides, options, this);
utils.overrideLowLevel(highLevelControlOverrides, options, this);
// Configure high-level overrides (these override the low-level settings if provided)
utils.overrideLowLevel(highLevelHeaderOverrides, options, this);
utils.overrideLowLevel(highLevelControlOverrides, options, this);
// Validate the routing number (ABA) before slicing
validate.validateRoutingNumber(utils.computeCheckDigit(options.originatingDFI));
// Validate the routing number (ABA) before slicing
validate.validateRoutingNumber(utils.computeCheckDigit(options.originatingDFI));
if(options.companyName) {
this.header.companyName.value = options.companyName.slice(0, this.header.companyName.width);
}
if (options.companyName) {
this.header.companyName.value = options.companyName.slice(0, this.header.companyName.width);
}
if(options.companyEntryDescription) {
this.header.companyEntryDescription.value = options.companyEntryDescription.slice(0, this.header.companyEntryDescription.width);
}
if (options.companyEntryDescription) {
this.header.companyEntryDescription.value = options.companyEntryDescription.slice(0, this.header.companyEntryDescription.width);
}
if(options.companyDescriptiveDate) {
this.header.companyDescriptiveDate.value = options.companyDescriptiveDate.slice(0, this.header.companyDescriptiveDate.width);
}
if (options.companyDescriptiveDate) {
this.header.companyDescriptiveDate.value = options.companyDescriptiveDate.slice(0, this.header.companyDescriptiveDate.width);
}
if(options.effectiveEntryDate) {
this.header.effectiveEntryDate.value = utils.formatDate(options.effectiveEntryDate);
}
if (options.effectiveEntryDate) {
this.header.effectiveEntryDate.value = utils.formatDate(options.effectiveEntryDate);
}
if(options.originatingDFI) {
this.header.originatingDFI.value = utils.computeCheckDigit(options.originatingDFI).slice(0, this.header.originatingDFI.width);
}
if (options.originatingDFI) {
this.header.originatingDFI.value = utils.computeCheckDigit(options.originatingDFI).slice(0, this.header.originatingDFI.width);
}
// Set control values which use the same header values
this.control.serviceClassCode.value = this.header.serviceClassCode.value;
this.control.companyIdentification.value = this.header.companyIdentification.value;
this.control.originatingDFI.value = this.header.originatingDFI.value;
// Set control values which use the same header values
this.control.serviceClassCode.value = this.header.serviceClassCode.value;
this.control.companyIdentification.value = this.header.companyIdentification.value;
this.control.originatingDFI.value = this.header.originatingDFI.value;
// Perform validation on all the passed values
this._validate();
// Perform validation on all the passed values
this._validate();
return this;
return this;
}
Batch.prototype._validate = function() {
Batch.prototype._validate = function () {
// Validate required fields have been passed
validate.validateRequiredFields(this.header);
// Validate required fields have been passed
validate.validateRequiredFields(this.header);
// Validate the batch's ACH service class code
validate.validateACHServiceClassCode(this.header.serviceClassCode.value);
// Validate the batch's ACH service class code
validate.validateACHServiceClassCode(this.header.serviceClassCode.value);
// Validate field lengths
validate.validateLengths(this.header);
// Validate field lengths
validate.validateLengths(this.header);
// Validate datatypes
validate.validateDataTypes(this.header);
// Validate datatypes
validate.validateDataTypes(this.header);
// Validate required fields have been passed
validate.validateRequiredFields(this.control);
// Validate required fields have been passed
validate.validateRequiredFields(this.control);
// Validate field lengths
validate.validateLengths(this.control);
// Validate field lengths
validate.validateLengths(this.control);
// Validate datatypes
validate.validateDataTypes(this.control);
// Validate datatypes
validate.validateDataTypes(this.control);
};
Batch.prototype.addEntry = function(entry) {
let self = this;
Batch.prototype.addEntry = function (entry) {
let self = this;
// Increment the addendaCount of the batch
this.control.addendaCount.value += entry.getRecordCount();
// Increment the addendaCount of the batch
this.control.addendaCount.value += entry.getRecordCount();
// Add the new entry to the entries array
this._entries.push(entry);
// Add the new entry to the entries array
this._entries.push(entry);
// Update the batch values like total debit and credit $ amounts
let entryHash = 0;
let totalDebit = 0;
let totalCredit = 0;
// Update the batch values like total debit and credit $ amounts
let entryHash = 0;
let totalDebit = 0;
let totalCredit = 0;
// (22, 23, 24, 27, 28, 29, 32, 33, 34, 37, 38 & 39)
let creditCodes = ['22', '23', '24', '32', '33', '34'];
let debitCodes = ['27', '28', '29', '37', '38', '39'];
// (22, 23, 24, 27, 28, 29, 32, 33, 34, 37, 38 & 39)
let creditCodes = ['21', '22', '23', '24', '31', '32', '33', '34', '41', '42', '43', '44', '51', '52', '53', '54'];
let debitCodes = ['26','27', '28', '29', '36','37', '38', '39','46','47','48','49','55','56'];
async.each(this._entries, function(entry, done) {
entryHash += Number(entry.fields.receivingDFI.value);
async.each(this._entries, function (entry, done) {
entryHash += Number(entry.fields.receivingDFI.value);
if(_.includes(creditCodes, entry.fields.transactionCode.value)) {
totalCredit += entry.fields.amount.value;
done();
} else if(_.includes(debitCodes, entry.fields.transactionCode.value)) {
totalDebit += entry.fields.amount.value;
done();
} else {
console.log('Transaction codes did not match or are not supported yet (unsupported status codes include: 23, 24, 28, 29, 33, 34, 38, 39)');
}
}, function() {
self.control.totalCredit.value = totalCredit;
self.control.totalDebit.value = totalDebit;
if (_.includes(creditCodes, entry.fields.transactionCode.value)) {
totalCredit += entry.fields.amount.value;
done();
} else if (_.includes(debitCodes, entry.fields.transactionCode.value)) {
totalDebit += entry.fields.amount.value;
done();
} else {
console.log('Transaction codes did not match or are not supported yet (unsupported status codes include: 23, 24, 28, 29, 33, 34, 38, 39)');
}
}, function () {
self.control.totalCredit.value = totalCredit;
self.control.totalDebit.value = totalDebit;
// Add up the positions 4-11 and compute the total. Slice the 10 rightmost digits.
self.control.entryHash.value = entryHash.toString().slice(-10);
});
// Add up the positions 4-11 and compute the total. Slice the 10 rightmost digits.
self.control.entryHash.value = entryHash.toString().slice(-10);
});
};
Batch.prototype.generateHeader = function(cb) {
utils.generateString(this.header, function(string) {
cb(string);
});
Batch.prototype.generateHeader = function (cb) {
utils.generateString(this.header, function (string) {
cb(string);
});
};
Batch.prototype.generateControl = function(cb) {
utils.generateString(this.control, function(string) {
cb(string);
});
Batch.prototype.generateControl = function (cb) {
utils.generateString(this.control, function (string) {
cb(string);
});
};
Batch.prototype.generateEntries = function(cb) {
let result = '';
Batch.prototype.generateEntries = function (cb) {
let result = '';
async.each(this._entries, function(entry, done) {
entry.generateString(function(string) {
result += string + utils.newLineChar();
done();
});
}, function() {
cb(result);
});
async.each(this._entries, function (entry, done) {
entry.generateString(function (string) {
result += string + utils.newLineChar();
done();
});
}, function () {
cb(result);
});
};
Batch.prototype.generateString = function(cb) {
let self = this;
Batch.prototype.generateString = function (cb) {
let self = this;
self.generateHeader(function(headerString) {
self.generateEntries(function(entryString) {
self.generateControl(function(controlString) {
cb(headerString + utils.newLineChar() + entryString + controlString);
});
});
});
self.generateHeader(function (headerString) {
self.generateEntries(function (entryString) {
self.generateControl(function (controlString) {
cb(headerString + utils.newLineChar() + entryString + controlString);
});
});
});
};
Batch.prototype.get = function(field) {
Batch.prototype.get = function (field) {
// If the header has the field, return the value
if(this.header[field]) {
return this.header[field]['value'];
}
// If the header has the field, return the value
if (this.header[field]) {
return this.header[field]['value'];
}
// If the control has the field, return the value
if(this.control[field]) {
return this.control[field]['value'];
}
// If the control has the field, return the value
if (this.control[field]) {
return this.control[field]['value'];
}
};
Batch.prototype.set = function(field, value) {
Batch.prototype.set = function (field, value) {
// If the header has the field, set the value
if(this.header[field]) {
this.header[field]['value'] = value;
}
// If the header has the field, set the value
if (this.header[field]) {
this.header[field]['value'] = value;
}
// If the control has the field, set the value
if(this.control[field]) {
this.control[field]['value'] = value;
}
// If the control has the field, set the value
if (this.control[field]) {
this.control[field]['value'] = value;
}
};
module.exports = Batch;
{
"name": "sp-nacha",
"description": "NACHA file format is a set of instructions that, when uploaded into a bank portal, successfully initiates a batch of ACH payments. NACHA file format is the protocol for structuring those instructions in a way that successfully initiates the payments. NACHA is a highly customizable Node.js module exposing a high & low-level API for generating ACH files for use within the ACH network.",
"version": "1.0.4",
"version": "1.0.5",
"keywords": [

@@ -6,0 +6,0 @@ "Seerportal Nacha",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc