add Isracard support, RT#13529
[Business-CreditCard.git] / CreditCard.pm
index ba63d63..4993f4e 100644 (file)
@@ -5,7 +5,7 @@ use vars qw( @ISA $VERSION $Country );
 
 @ISA = qw( Exporter );
 
-$VERSION = "0.31";
+$VERSION = "0.32_01";
 
 $Country = 'US';
 
@@ -49,6 +49,7 @@ Possible return values are:
   Solo
   China Union Pay
   Laser
+  Isracard
   Unknown
 
 "Not a credit card" is returned on obviously invalid data values.
@@ -130,7 +131,7 @@ types.  Lee also contributed a working test.pl.  Alexandr Ciornii
 
 Copyright (C) 1995,1996,1997 Jon Orwant
 Copyright (C) 2001-2006 Ivan Kohler
-Copyright (C) 2007-2009 Freeside Internet Services, Inc.
+Copyright (C) 2007-2011 Freeside Internet Services, Inc.
 
 This library is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself, either Perl version 5.8.8 or,
@@ -160,7 +161,11 @@ sub cardtype {
     #$number =~ s/\D//g;
     {
       local $^W=0; #no warning at next line
-      return "Not a credit card" unless length($number) >= 13 && 0+$number;
+      return "Not a credit card"
+        unless ( length($number) >= 13
+                 || length($number) == 8 || length($number) == 9 #Isracard
+               )
+            && 0+$number;
     }
 
     return "Switch"
@@ -205,11 +210,17 @@ sub cardtype {
     return "Laser"
       if $number =~ /^6(304|7(06|09|71))[\dx]{12,15}$/o;
 
+    return "Isracard"
+      if $number =~ /^[\dx]{8,9}$/;
+
     return "Unknown";
 }
 
 sub generate_last_digit {
     my ($number) = @_;
+
+    #XXX doesn't work for Isracard, should die
+
     my ($i, $sum, $weight);
 
     $number =~ s/\D//g;
@@ -224,12 +235,16 @@ sub generate_last_digit {
 
 sub validate {
     my ($number) = @_;
+
     my ($i, $sum, $weight);
     
     return 0 if $number =~ /[^\d\s]/;
 
     $number =~ s/\D//g;
 
+    return 1 if $number =~ /^[\dx]{8,9}$/; #XXX Isracard does not use LUHN,
+                                           # validation not yet implemented
+
     return 0 unless length($number) >= 13 && 0+$number;
 
     for ($i = 0; $i < length($number) - 1; $i++) {