From: levinse Date: Thu, 14 Jul 2011 04:22:28 +0000 (+0000) Subject: add Isracard validation, RT13643 X-Git-Url: http://git.freeside.biz/gitweb/?p=Business-CreditCard.git;a=commitdiff_plain;h=9a22a62a72ad936158c3a52bb618f7d8a8f72936 add Isracard validation, RT13643 --- diff --git a/CreditCard.pm b/CreditCard.pm index 4993f4e..df40315 100644 --- a/CreditCard.pm +++ b/CreditCard.pm @@ -219,7 +219,7 @@ sub cardtype { sub generate_last_digit { my ($number) = @_; - #XXX doesn't work for Isracard, should die + die "invalid operation" if length($number) == 8 || length($number) == 9; my ($i, $sum, $weight); @@ -242,8 +242,14 @@ sub validate { $number =~ s/\D//g; - return 1 if $number =~ /^[\dx]{8,9}$/; #XXX Isracard does not use LUHN, - # validation not yet implemented + if ( $number =~ /^[\dx]{8,9}$/ ) { # Isracard + $number = "0$number" if length($number) == 8; + for($i=1;$i= 13 && 0+$number; diff --git a/t/validation.t b/t/validation.t new file mode 100644 index 0000000..953e4bc --- /dev/null +++ b/t/validation.t @@ -0,0 +1,20 @@ + +use Test::More tests => 1; +use Business::CreditCard; + +ok( test_card_validation() ); + +sub test_card_validation { + my %test_table=( + '10830529' => 'Isracard', + '010830529' => 'Isracard', + ); + while( my ($k, $v)=each(%test_table) ){ + if(!validate($k)){ + warn "Card $k - should be a valid $v but validation failed\n"; + return; + } + } + return 1; +} +