[ic] [interchange] Update credit card type detection

Grant emailgrant at gmail.com
Fri Oct 28 18:56:26 UTC 2011


This sounds like an important update.  Can anyone tell me if the new
lib/Vend/Order.pm below should drop into a 5.6.3 site without issue?

- Grant


On Thu, Oct 13, 2011 at 10:19 PM, Jon Jensen
<interchange-cvs at icdevgroup.org> wrote:
> commit cbe37a81e6ddda4f0292a39c79f81b9d9344de6e
> Author: Jon Jensen <jon at endpoint.com>
> Date:   Thu Oct 13 14:51:23 2011 -0600
>
>    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.
>
>  lib/Vend/Order.pm |   71 +++++++++++++++++++++++++++++++---------------------
>  1 files changed, 42 insertions(+), 29 deletions(-)
> ---
> diff --git a/lib/Vend/Order.pm b/lib/Vend/Order.pm
> index b0a47bf..4f9f0a4 100644
> --- a/lib/Vend/Order.pm
> +++ b/lib/Vend/Order.pm
> @@ -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};
> @@ -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:
>  #
>
> _______________________________________________
> interchange-cvs mailing list
> interchange-cvs at icdevgroup.org
> http://www.icdevgroup.org/mailman/listinfo/interchange-cvs
>



More information about the interchange-users mailing list