Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 8-digit routing numbers #9

Open
yawetse opened this issue Mar 6, 2015 · 5 comments
Open

Add support for 8-digit routing numbers #9

yawetse opened this issue Mar 6, 2015 · 5 comments
Assignees

Comments

@yawetse
Copy link
Contributor

yawetse commented Mar 6, 2015

I'd like to make a small change, to only modify the rd if cv is missing and rd is too long. I'll submit a pull request.

Before

    // Some values need special coercing, so after they've been set by overrideLowLevel() we override them
    if(options.receivingDFI) {
        this.fields.receivingDFI.value = options.receivingDFI.slice(0,-1);
        this.fields.checkDigit.value = options.receivingDFI.slice(-1);
    }

After

    // Some values need special coercing, so after they've been set by overrideLowLevel() we override them
    if(options.receivingDFI) {
        this.fields.receivingDFI.value = (this.fields.receivingDFI.value.length>8)?  options.receivingDFI.slice(0,-1) : this.fields.receivingDFI.value ;
        this.fields.checkDigit.value = (!options.checkDigit && this.fields.receivingDFI.value.length>8)? options.receivingDFI.slice(-1): this.fields.checkDigit.value;
    }
yawetse added a commit to yawetse/nACH that referenced this issue Mar 6, 2015
@glenselle
Copy link
Owner

What about this? It seems a little simpler. We can just take advantage of the fact that the computeCheckDigit function already returns the value without modification if it's not 8 digits long.

if(options.receivingDFI) {
    this.fields.receivingDFI.value = utils.computeCheckDigit(options.receivingDFI).slice(0,-1);
    this.fields.checkDigit.value = utils.computeCheckDigit(options.receivingDFI).slice(-1);
}

For context, here's what computeCheckDigit looks like:

function computeCheckDigit(routing) {
    var a = routing.split('').map(Number);

    return a.length !== 8 ? routing : routing + (7 * (a[0] + a[3] + a[6]) + 3 * (a[1] + a[4] + a[7]) + 9 * (a[2] + a[5])) % 10;
};

@glenselle glenselle changed the title entry field validation on receivingDFI Add support for 8-digit routing numbers Mar 7, 2015
@glenselle
Copy link
Owner

@yawetse v0.3.2 should add preliminary support for 8-digit routing numbers -- I'm keeping this ticket open till I write tests to cover this scenario

@yawetse
Copy link
Contributor Author

yawetse commented Mar 9, 2015

this did the trick! thanks man!

@yawetse
Copy link
Contributor Author

yawetse commented Mar 9, 2015

BTW @glenselle I can't respond to your twitter DM because you don't follow me haha.

My question is around how you're parsing Amount values, if no decimal is passed are you appending values at the end of the string?

@glenselle
Copy link
Owner

Right now we're passing whatever you pass into the Number constructor

var amount = Number(options.amount);

Then later when the actual row is generated, it's passed to generateString where we check if the field is alphanumeric or should be blank. If it's not either case, we assume we're dealing with a number and we hit the following logic:

var string = field.number ? parseFloat(field.value).toFixed(2).replace(/\./, '') : field.value;
var paddingChar = field.paddingChar || '0';

result = result + pad(string, field.width, false, paddingChar);

We pass false to the pad function which means it pads the field to the left (padding to the right with zeroes would completely change the number). Are you seeing incorrect behavior when it comes to the way numbers are formatted?

@glenselle glenselle self-assigned this Mar 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants