From 5d1f486c543c2e61cea6c050bed86c0c9815085e Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Thu, 3 Oct 2013 17:29:21 -0700 Subject: [PATCH] clean up some cust_payby upgrade issues, #23741 --- FS/FS/Conf.pm | 7 +++++++ FS/FS/cust_main.pm | 13 +++++++++---- FS/FS/cust_payby.pm | 10 ++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 4d5b6bf7c..f0f2b4696 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -5520,6 +5520,13 @@ and customer address. Include units.', 'type' => 'text', }, + { + 'key' => 'allow_invalid_cards', + 'section' => '', + 'description' => 'Accept invalid credit card numbers. Useful for testing with fictitious customers. There is no good reason to enable this in production.', + 'type' => 'checkbox', + }, + { key => "apacheroot", section => "deprecated", description => "DEPRECATED", type => "text" }, { key => "apachemachine", section => "deprecated", description => "DEPRECATED", type => "text" }, { key => "apachemachines", section => "deprecated", description => "DEPRECATED", type => "text" }, diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 13b0150cf..3403dc418 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -17,6 +17,7 @@ use vars qw( $DEBUG $me $conf @encrypted_fields $import $ignore_expired_card $ignore_banned_card $ignore_illegal_zip + $ignore_invalid_card $skip_fuzzyfiles @paytypes ); @@ -89,6 +90,7 @@ $me = '[FS::cust_main]'; $import = 0; $ignore_expired_card = 0; $ignore_banned_card = 0; +$ignore_invalid_card = 0; $skip_fuzzyfiles = 0; @@ -102,6 +104,7 @@ sub nohistory_fields { ('payinfo', 'paycvv'); } install_callback FS::UID sub { $conf = new FS::Conf; #yes, need it for stuff below (prolly should be cached) + $ignore_invalid_card = $conf->exists('allow_invalid_cards'); }; sub _cache { @@ -1826,7 +1829,8 @@ sub check { # Need some kind of global flag to accept invalid cards, for testing # on scrubbed data. - if ( !$import && $check_payinfo && $self->payby =~ /^(CARD|DCRD)$/ ) { + if ( !$import && !$ignore_invalid_card && $check_payinfo && + $self->payby =~ /^(CARD|DCRD)$/ ) { my $payinfo = $self->payinfo; $payinfo =~ s/\D//g; @@ -1898,7 +1902,8 @@ sub check { $self->payissue(''); } - } elsif ( $check_payinfo && $self->payby =~ /^(CHEK|DCHK)$/ ) { + } elsif ( !$ignore_invalid_card && $check_payinfo && + $self->payby =~ /^(CHEK|DCHK)$/ ) { my $payinfo = $self->payinfo; $payinfo =~ s/[^\d\@\.]//g; @@ -5125,13 +5130,13 @@ sub _upgrade_data { #class method die $error if $error; $cust_main->setfield($_, '') foreach @payfields; - $DEBUG = 2; + #$DEBUG = 2; $error = $cust_main->replace; die $error if $error; }; - FS::upgrade_journal->set_done('cust_main__trimspaces'); + FS::upgrade_journal->set_done('cust_main__cust_payby'); } $class->_upgrade_otaker(%opts); diff --git a/FS/FS/cust_payby.pm b/FS/FS/cust_payby.pm index 5914ab5c5..d78c574e4 100644 --- a/FS/FS/cust_payby.pm +++ b/FS/FS/cust_payby.pm @@ -7,9 +7,11 @@ use FS::Record qw( qsearchs ); #qsearch; use FS::payby; use FS::cust_main; use Business::CreditCard qw( validate cardtype ); +use FS::Msgcat qw( gettext ); use vars qw( $conf @encrypted_fields $ignore_expired_card $ignore_banned_card + $ignore_invalid_card ); @encrypted_fields = ('payinfo', 'paycvv'); @@ -17,10 +19,12 @@ sub nohistory_fields { ('payinfo', 'paycvv'); } $ignore_expired_card = 0; $ignore_banned_card = 0; +$ignore_invalid_card = 0; install_callback FS::UID sub { $conf = new FS::Conf; #yes, need it for stuff below (prolly should be cached) + $ignore_invalid_card = $conf->exists('allow_invalid_cards'); }; =head1 NAME @@ -197,7 +201,8 @@ sub check { # Need some kind of global flag to accept invalid cards, for testing # on scrubbed data. #XXX if ( !$import && $check_payinfo && $self->payby =~ /^(CARD|DCRD)$/ ) { - if ( $check_payinfo && $self->payby =~ /^(CARD|DCRD)$/ ) { + if ( !$ignore_invalid_card && + $check_payinfo && $self->payby =~ /^(CARD|DCRD)$/ ) { my $payinfo = $self->payinfo; $payinfo =~ s/\D//g; @@ -269,7 +274,8 @@ sub check { $self->payissue(''); } - } elsif ( $check_payinfo && $self->payby =~ /^(CHEK|DCHK)$/ ) { + } elsif ( !$ignore_invalid_card && + $check_payinfo && $self->payby =~ /^(CHEK|DCHK)$/ ) { my $payinfo = $self->payinfo; $payinfo =~ s/[^\d\@\.]//g; -- 2.11.0