Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update credit card type detection
Most important are the changes to Discover and Diners Club updates, but
some other minor ones matter too.

Discover's changes are documented here:

https://www.discovernetworkvar.com/common/pdf/var/10-1_VAR_ALERT_April_2010.pdf

Some code borrowed from Business::CreditCard again.
  • Loading branch information
jonjensen committed Oct 14, 2011
1 parent 22a3c7f commit cbe37a8
Showing 1 changed file with 42 additions and 29 deletions.
71 changes: 42 additions & 29 deletions lib/Vend/Order.pm
Expand Up @@ -455,7 +455,7 @@ sub guess_cc_type {
my ($ccnum) = @_;
$ccnum =~ s/\D+//g;

my $country = $::Values->{$::Variable->{MV_COUNTRY_FIELD} || 'country'} || '';
my $country = uc($::Values->{$::Variable->{MV_COUNTRY_FIELD} || 'country'} || '');

if(my $subname = $Vend::Cfg->{SpecialSub}{guess_cc_type}) {
my $sub = $Vend::Cfg->{Sub}{$subname} || $Global::GlobalSub->{$subname};
Expand All @@ -466,53 +466,66 @@ sub guess_cc_type {
}

# based on logic from Business::CreditCard
if ($ccnum eq '') { '' }
elsif (
$ccnum =~ /^4(?:\d{12}|\d{15})$/
)
{
return 'visa';
}
elsif (
$ccnum =~ /^5[1-5]\d{14}$/
or
( $ccnum =~ /^36\d{12}/ && $country =~ /^(US|CA)$/oi )
)
if ($ccnum eq '')
{ return '' }

elsif ($ccnum =~ /^4(?:\d{12}|\d{15})$/)
{ return 'visa' }

elsif ($ccnum =~ /^5[1-5]\d{14}$/)
{ return 'mc' }
elsif (
$ccnum =~ /^6011\d{12}$/
or
$ccnum =~ /^65\d{14}$/o
or
( $ccnum =~ /^622\d{13}$/o && $country !~ /^CN$/i )

)
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 =~ /^35(?:2[89]|[3-8]\d)\d{10}$/ and $country eq 'US' ) # JCB
)
{ return 'discover' }
elsif ($ccnum =~ /^3[47]\d{10,13}$/)

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' }

elsif ($ccnum =~ /^(?:3\d{15}|2131\d{11}|1800\d{11})$/)
{ return 'jcb' }
elsif (
$ccnum =~ /^49(03(0[2-9]|3[5-9])|11(0[1-2]|7[4-9]|8[1-2])|36[0-9]{2})\d{10}(\d{2,3})?$/
or $ccnum =~ /^564182\d{10}(\d{2,3})?$/
or $ccnum =~ /^6(3(33[0-4][0-9])|759[0-9]{2})\d{10}(\d{2,3})?$/)

elsif (
$ccnum =~ /^49(?:03(?:0[2-9]|3[5-9])|11(?:0[1-2]|7[4-9]|8[1-2])|36[0-9]{2})\d{10}(?:\d{2,3})?$/
or $ccnum =~ /^564182\d{10}(?:\d{2,3})?$/
or $ccnum =~ /^6(?:3(?:33[0-4][0-9])|759[0-9]{2})\d{10}(?:\d{2,3})?$/
)
{ return 'switch' }
elsif ($ccnum =~ /^56\d{14}$/)

elsif ($ccnum =~ /^56(?:10\d\d|022[1-5])\d{10}$/)
{ return 'bankcard' }
elsif ($ccnum =~ /^6(3(34[5-9][0-9])|767[0-9]{2})\d{10}(\d{2,3})?$/)

elsif ($ccnum =~ /^6(?:3(?:34[5-9][0-9])|767[0-9]{2})\d{10}(?:\d{2,3})?$/)
{ return 'solo' }
elsif ($ccnum =~ /^622\d{13}$/)

elsif ($ccnum =~ /^62[24-68]\d{13}$/)
{ return 'chinaunionpay' }

else { return $::Variable->{MV_PAYMENT_OTHER_CARD} || 'other' }
elsif ($ccnum =~ /^6(?:304|7(?:06|09|71))\d{12,15}$/)
{ return 'laser' }

else
{ return $::Variable->{MV_PAYMENT_OTHER_CARD} || 'other' }
}


# Takes a reference to a hash (usually %CGI::values) that contains
# the following:
#
Expand Down

0 comments on commit cbe37a8

Please sign in to comment.