http://www.pdncommunity.com/pdn/board/message?board.id=samplecode&message.id=56
who adapted it from the code presented on:
http://www.darkcoding.net/projects/credit-card-generator/
It is pared down for just visa creation, and it create and returns a single valid visa number. This is perfect for generating numbers for use in sandbox cc processors.
All you need to do is call the function and you are set:
var myVisaNum = generateVisaCCNumber
function generateVisaCCNumber() {
var visaPrefixList = new Array("4539","4556","4916","4532","4929","40240071","4485","4716","4");
var ccnumber = visaPrefixList[ Math.floor(Math.random() * visaPrefixList.length) ];
// generate digits
while ( ccnumber.length < (15) ) { ccnumber += Math.floor(Math.random()*10); } // reverse number and convert to int and place in array var reversedCCnumber = new Array(); for ( var i=0; i < sum =" 0;" pos =" 0;" odd =" reversedCCnumber["> 9 ) {
odd -= 9;
}
sum += odd;
if ( pos != (14) ) {
sum += reversedCCnumber[ pos +1 ];
}
pos += 2;
}
// calculate check digit
var checkdigit = (( Math.floor(sum/10) + 1) * 10 - sum) % 10;
ccnumber += checkdigit;
return ccnumber;
}
No comments:
Post a Comment