[interchange] Update guess_cc_type from Business::CreditCard
Josh Lavin
interchange-cvs at icdevgroup.org
Thu Jul 21 23:37:33 UTC 2016
commit 7324f742636916af17d501f65a6d56fac086b200
Author: Josh Lavin <jlavin at endpoint.com>
Date: Thu Jul 21 16:37:06 2016 -0700
Update guess_cc_type from Business::CreditCard
and add additional test credit card numbers
lib/Vend/Order.pm | 25 +++++++++++++------------
t/credit_cards.t | 47 +++++++++++++++++++++++++++++++++++++++--------
2 files changed, 52 insertions(+), 20 deletions(-)
---
diff --git a/lib/Vend/Order.pm b/lib/Vend/Order.pm
index 7880263..ac7e259 100644
--- a/lib/Vend/Order.pm
+++ b/lib/Vend/Order.pm
@@ -477,7 +477,7 @@ sub guess_cc_type {
if ($ccnum eq '')
{ return '' }
- elsif ($ccnum =~ /^4(?:\d{12}|\d{15})$/)
+ elsif ($ccnum =~ /^4[0-8]\d{11,17}$/)
{ return 'visa' }
elsif ($ccnum =~ /^5[1-5]\d{14}$/ || ($ccnum =~ /^(2\d{5})\d{10}$/ && ($1 >= 222100 && $1 < 272100)))
@@ -486,11 +486,12 @@ sub guess_cc_type {
elsif (
$ccnum =~ /^30[0-5]\d{11}(?:\d{2})?$/ # Diners Club: 300-305
or $ccnum =~ /^3095\d{10}(?:\d{2})?$/ # Diners Club: 3095
- or $ccnum =~ /^3[68]\d{12}(?:\d{2})?$/ # Diners Club: 36
- or $ccnum =~ /^6011\d{12}$/
- or $ccnum =~ /^64[4-9]\d{13}$/
- or $ccnum =~ /^65\d{14}$/
- or ( $ccnum =~ /^62[24-68]\d{13}$/ and $country ne 'CN' ) # China Unionpay
+ or $ccnum =~ /^36\d{12,17}$/ # Diners Club: 36
+ or $ccnum =~ /^3[89]\d{14,17}$/ # Diners Club: 38 and 39
+ or $ccnum =~ /^6011\d{12,15}$/
+ or $ccnum =~ /^64[4-9]\d{13,16}$/
+ or $ccnum =~ /^65\d{14,17}$/
+ or ( $ccnum =~ /^62[24-68]\d{13,16}$/ and $country ne 'CN' ) # China Unionpay
or ( $ccnum =~ /^35(?:2[89]|[3-8]\d)\d{10}$/ and $country eq 'US' ) # JCB
)
{ return 'discover' }
@@ -498,12 +499,6 @@ sub guess_cc_type {
elsif ($ccnum =~ /^3[47]\d{13}$/)
{ return 'amex' }
- elsif ($ccnum =~ /^3(?:6\d{12}|0[0-5]\d{11})$/)
- { return 'dinersclub' }
-
- elsif ($ccnum =~ /^38\d{12}$/)
- { return 'carteblanche' }
-
elsif ($ccnum =~ /^2(?:014|149)\d{11}$/)
{ return 'enroute' }
@@ -517,6 +512,9 @@ sub guess_cc_type {
)
{ return 'switch' }
+ elsif ($ccnum =~ /^4\d{12,18}$/) # catch 49* that's not Switch
+ { return 'visa' }
+
elsif ($ccnum =~ /^56(?:10\d\d|022[1-5])\d{10}$/)
{ return 'bankcard' }
@@ -529,6 +527,9 @@ sub guess_cc_type {
elsif ($ccnum =~ /^6(?:304|7(?:06|09|71))\d{12,15}$/)
{ return 'laser' }
+ elsif ($ccnum =~ /^\d{8,9}$/)
+ { return 'isracard' }
+
else
{ return $::Variable->{MV_PAYMENT_OTHER_CARD} || 'other' }
}
diff --git a/t/credit_cards.t b/t/credit_cards.t
index 437a788..362a898 100644
--- a/t/credit_cards.t
+++ b/t/credit_cards.t
@@ -8,6 +8,7 @@ is( Vend::Order::guess_cc_type(''), '', 'credit card: blank' );
is( Vend::Order::guess_cc_type('4123456789012'), 'visa', 'credit card: visa 13' );
is( Vend::Order::guess_cc_type('4123456789012345'), 'visa', 'credit card: visa 16' );
+is( Vend::Order::guess_cc_type('4823456789012345678'), 'visa', 'credit card: visa 19' );
is( Vend::Order::guess_cc_type('5123456789012345'), 'mc', 'credit card: mc, 51xx' );
is( Vend::Order::guess_cc_type('5512345678901234'), 'mc', 'credit card: mc, 55xx' );
@@ -15,13 +16,15 @@ is( Vend::Order::guess_cc_type('2221001234567890'), 'mc', 'credit card: mc BIN-2
is( Vend::Order::guess_cc_type('2720991234567890'), 'mc', 'credit card: mc BIN-2 #2' );
is( Vend::Order::guess_cc_type('2700991234567890'), 'mc', 'credit card: mc BIN-2 #3' );
-is( Vend::Order::guess_cc_type('5012341234123412'), 'other', 'non-mc similarity #1');
-is( Vend::Order::guess_cc_type('2121001234567890'), 'other', 'non-mc similarity #2');
-is( Vend::Order::guess_cc_type('2820991234567890'), 'other', 'non-mc similarity #3');
+is( Vend::Order::guess_cc_type('5012341234123412'), 'other', 'non-mc similarity #1' );
+is( Vend::Order::guess_cc_type('2121001234567890'), 'other', 'non-mc similarity #2' );
+is( Vend::Order::guess_cc_type('2820991234567890'), 'other', 'non-mc similarity #3' );
is( Vend::Order::guess_cc_type('3001234567890112'), 'discover', 'credit card: discover diners club 300xx' );
is( Vend::Order::guess_cc_type('3095123456789012'), 'discover', 'credit card: discover diners club 3095xx' );
is( Vend::Order::guess_cc_type('3612345678901212'), 'discover', 'credit card: discover diners club 36xx' );
+is( Vend::Order::guess_cc_type('3812345678901212'), 'discover', 'credit card: discover diners club 38xx' );
+is( Vend::Order::guess_cc_type('391234567890121234'), 'discover', 'credit card: discover diners club 39xx' );
is( Vend::Order::guess_cc_type('6011123456789012'), 'discover', 'credit card: discover 6011xx' );
is( Vend::Order::guess_cc_type('6441234567890123'), 'discover', 'credit card: discover 644xx' );
is( Vend::Order::guess_cc_type('6512345678901234'), 'discover', 'credit card: discover 65xx' );
@@ -32,11 +35,6 @@ is( Vend::Order::guess_cc_type('6251234567890123'), 'discover', 'credit card: di
is( Vend::Order::guess_cc_type('341234567890123'), 'amex', 'credit card: amex 34xx' );
is( Vend::Order::guess_cc_type('371234567890123'), 'amex', 'credit card: amex 37xx' );
-# defunct
-#is( Vend::Order::guess_cc_type('36123456789012'), 'dinersclub', 'credit card: dinersclub 36' );
-#is( Vend::Order::guess_cc_type('30012345678901'), 'dinersclub', 'credit card: dinersclub 300' );
-#is( Vend::Order::guess_cc_type('38123456789012'), 'carteblanche', 'credit card: carteblanche' );
-
is( Vend::Order::guess_cc_type('201412345678901'), 'enroute', 'credit card: enroute 2014xx' );
is( Vend::Order::guess_cc_type('214912345678901'), 'enroute', 'credit card: enroute 2149xx' );
@@ -49,6 +47,8 @@ is( Vend::Order::guess_cc_type('564182123456789012'), 'switch', 'credit card: s
is( Vend::Order::guess_cc_type('633300123456789012'), 'switch', 'credit card: switch 63300xx' );
is( Vend::Order::guess_cc_type('675900123456789012'), 'switch', 'credit card: switch 675900xx' );
+is( Vend::Order::guess_cc_type('4912345678901'), 'visa', 'credit card: visa 49 not switch' );
+
is( Vend::Order::guess_cc_type('5610001234567890'), 'bankcard', 'credit card: bankcard 5610xx' );
is( Vend::Order::guess_cc_type('5602211234567890'), 'bankcard', 'credit card: bankcard 56022xx' );
@@ -58,7 +58,38 @@ is( Vend::Order::guess_cc_type('676700123456789012'), 'solo', 'credit card: solo
is( Vend::Order::guess_cc_type('630409123456789012'), 'laser', 'credit card: laser 630409xx' );
is( Vend::Order::guess_cc_type('6771123456789012'), 'laser', 'credit card: laser 6771xx' );
+is( Vend::Order::guess_cc_type('12345678'), 'isracard', 'credit card: isracard 8' );
+is( Vend::Order::guess_cc_type('123456789'), 'isracard', 'credit card: isracard 9' );
is( Vend::Order::guess_cc_type('123'), 'other', 'credit card: other' );
+# Business::CreditCard test numbers (changed 'x's to 0, skipping their 6000 test)
+is( Vend::Order::guess_cc_type('6599000000000000'), 'discover', 'credit card: discover' );
+is( Vend::Order::guess_cc_type('5610000000000000'), 'bankcard', 'credit card: bankcard' );
+is( Vend::Order::guess_cc_type('3123456789012345'), 'jcb', 'credit card: jcb' );
+is( Vend::Order::guess_cc_type('6250000000000000'), 'discover', 'credit card: discover, china union pay' );
+is( Vend::Order::guess_cc_type('5212345678901234'), 'mc', 'credit card: mc' );
+is( Vend::Order::guess_cc_type('123456780'), 'isracard', 'credit card: isracard' );
+is( Vend::Order::guess_cc_type('12345678'), 'isracard', 'credit card: isracard' );
+is( Vend::Order::guess_cc_type('180012345678901'), 'jcb', 'credit card: jcb' );
+is( Vend::Order::guess_cc_type('2512345678901234'), 'mc', 'credit card: mc' );
+is( Vend::Order::guess_cc_type('371234567890123'), 'amex', 'credit card: amex' );
+is( Vend::Order::guess_cc_type('6499000000000000'), 'discover', 'credit card: discover' );
+is( Vend::Order::guess_cc_type('213112345678901'), 'jcb', 'credit card: jcb' );
+is( Vend::Order::guess_cc_type('312345678901234'), 'other', 'credit card: other' );
+is( Vend::Order::guess_cc_type('6304980000000000004'), 'laser', 'credit card: laser' );
+is( Vend::Order::guess_cc_type('5512345678901234'), 'mc', 'credit card: mc' );
+is( Vend::Order::guess_cc_type('1800123456789012'), 'other', 'credit card: other' );
+is( Vend::Order::guess_cc_type('214912345678901'), 'enroute', 'credit card: enroute' );
+is( Vend::Order::guess_cc_type('6222000000000000'), 'discover', 'credit card: discover, china union pay' );
+is( Vend::Order::guess_cc_type('4512345678901234'), 'visa', 'credit card: visa' );
+is( Vend::Order::guess_cc_type('4929492492497'), 'visa', 'credit card: visa' );
+is( Vend::Order::guess_cc_type('6280000000000000'), 'discover', 'credit card: discover, china union pay' );
+is( Vend::Order::guess_cc_type('36123456789012'), 'discover', 'credit card: discover' );
+is( Vend::Order::guess_cc_type('4123456789012'), 'visa', 'credit card: visa' );
+is( Vend::Order::guess_cc_type('341234567890123'), 'amex', 'credit card: amex' );
+is( Vend::Order::guess_cc_type('4111000000000000'), 'visa', 'credit card: visa' );
+is( Vend::Order::guess_cc_type('6011123456789012'), 'discover', 'credit card: discover' );
+is( Vend::Order::guess_cc_type('201412345678901'), 'enroute', 'credit card: enroute' );
+
done_testing();
More information about the interchange-cvs
mailing list