Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

added santander validator for account number #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/santander_check_number_validator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(function(window) {
var Moip = window.Moip || {};
window.Moip = Moip;

function SantanderCheckNumberCalculator() {
if ( !( this instanceof SantanderCheckNumberCalculator ) ) {
return new SantanderCheckNumberCalculator();
}
}

SantanderCheckNumberCalculator.prototype = {

calculateAccount: function(agencyNumber,accountNumber) {
var numbers = (agencyNumber + "00" + accountNumber).split("");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this "00" from here if you also remove the 0, 0 from the array at line 27

var sumSeq = 0;

for (var i = 0; i < numbers.length; i++) {
var number = parseInt(numbers[i]);
sumSeq += this.multiplyAccordingWeight(number, i);
}
sumSeq = parseInt(sumSeq.toString().substr(-1));
if ( sumSeq === 0 ) return "0";
else return (10 - sumSeq).toString();
},

multiplyAccordingWeight: function(number, index) {
var weight = [9,7,3,1,0,0,9,7,1,3,1,9,7,3];
var res = number * weight[index];
return parseInt(res.toString().substr(-1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a semicolon here

}
};

Moip.SantanderCheckNumberCalculator = SantanderCheckNumberCalculator();

})(window);
3 changes: 2 additions & 1 deletion src/santander_validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
},

accountCheckNumberMatch: function(bankAccount) {
return true;
var checkNumberCalculated = Moip.SantanderCheckNumberCalculator.calculateAccount(bankAccount.agencyNumber,bankAccount.accountNumber);
return checkNumberCalculated === bankAccount.accountCheckNumber.toUpperCase();
},

agencyNumberMsgError: function() {
Expand Down