From 074464a707b2c8b83cc50cd0bb067660ef4d0f9f Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 14 Jan 2012 07:05:18 +0000 Subject: [PATCH] improve echeck validation for canada, deprecate echeck-nonus and cust_main-require-bank-branch config in favor of echeck-country, RT#15982 --- FS/FS/Conf.pm | 18 +++++++++++------- FS/FS/Upgrade.pm | 10 ++++++++++ FS/FS/cust_main.pm | 11 ++++++----- conf/echeck-country | 1 + httemplate/edit/cust_main/billing.html | 18 +++++++++++++----- httemplate/edit/process/cust_main.cgi | 2 +- httemplate/misc/payment.cgi | 17 ++++++++++++----- httemplate/misc/process/payment.cgi | 4 ++-- httemplate/view/cust_main/billing.html | 11 ++++++++--- 9 files changed, 64 insertions(+), 28 deletions(-) create mode 100644 conf/echeck-country diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 37adffb36..c588493aa 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -3068,6 +3068,17 @@ and customer address. Include units.', }, { + 'key' => 'echeck-country', + 'section' => 'billing', + 'description' => 'Format electronic check information for the specified country.', + 'type' => 'select', + 'select_hash' => [ 'US' => 'United States', + 'CA' => 'Canada (enables branch)', + 'XX' => 'Other', + ], + }, + + { 'key' => 'voip-cust_accountcode_cdr', 'section' => 'telephony', 'description' => 'Enable the per-customer option for CDR breakdown by accountcode.', @@ -4717,13 +4728,6 @@ and customer address. Include units.', }, { - 'key' => 'cust_main-require-bank-branch', - 'section' => 'UI', - 'description' => 'An alternate DCHK/CHEK format; require entry of bank branch number.', - 'type' => 'checkbox', - }, - - { 'key' => 'cust-edit-alt-field-order', 'section' => 'UI', 'description' => 'An alternate ordering of fields for the New Customer and Edit Customer screens.', diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm index 3134b8c61..cf6158031 100644 --- a/FS/FS/Upgrade.pm +++ b/FS/FS/Upgrade.pm @@ -50,6 +50,16 @@ sub upgrade_config { $conf->touch('geocode-require_nw_coordinates') if $conf->exists('svc_broadband-require-nw-coordinates'); + unless ( $conf->config('echeck-country') ) { + if ( $conf->exists('cust_main-require-bank-branch') ) { + $conf->set('echeck-country', 'CA'); + } elsif ( $conf->exists('echeck-nonus') ) { + $conf->set('echeck-country', 'XX'); + } else { + $conf->set('echeck-country', 'US'); + } + } + upgrade_overlimit_groups($conf); map { upgrade_overlimit_groups($conf,$_->agentnum) } qsearch('agent', {}); diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index eaf70cf64..3b572fad7 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -2032,14 +2032,15 @@ sub check { my $payinfo = $self->payinfo; $payinfo =~ s/[^\d\@\.]//g; - if ( $conf->exists('cust_main-require-bank-branch') ) { - $payinfo =~ /^(\d+)\@(\d+)\.(\d+)$/ or return 'invalid echeck account@branch.bank'; + if ( $conf->config('echeck-country') eq 'CA' ) { + $payinfo =~ /^(\d+)\@(\d{5})\.(\d{3})$/ + or return 'invalid echeck account@branch.bank'; $payinfo = "$1\@$2.$3"; - } elsif ( $conf->exists('echeck-nonus') ) { - $payinfo =~ /^(\d+)\@(\d+)$/ or return 'invalid echeck account@aba'; + } elsif ( $conf->config('echeck-country') eq 'US' ) { + $payinfo =~ /^(\d+)\@(\d{9})$/ or return 'invalid echeck account@aba'; $payinfo = "$1\@$2"; } else { - $payinfo =~ /^(\d+)\@(\d{9})$/ or return 'invalid echeck account@aba'; + $payinfo =~ /^(\d+)\@(\d+)$/ or return 'invalid echeck account@routing'; $payinfo = "$1\@$2"; } $self->payinfo($payinfo); diff --git a/conf/echeck-country b/conf/echeck-country new file mode 100644 index 000000000..f4cd62e01 --- /dev/null +++ b/conf/echeck-country @@ -0,0 +1 @@ +US diff --git a/httemplate/edit/cust_main/billing.html b/httemplate/edit/cust_main/billing.html index fd078c5da..78fac6c22 100644 --- a/httemplate/edit/cust_main/billing.html +++ b/httemplate/edit/cust_main/billing.html @@ -127,7 +127,7 @@ % my( $account, $aba ) = split('@', $payinfo); % my $branch = ''; % ($branch,$aba) = split('\.',$aba) -% if $conf->exists('cust_main-require-bank-branch'); +% if $conf->config('echeck-country') eq 'CA'; % % my $disabled = 'DISABLED style="background-color: #dddddd"'; % my $text_disabled = 'style="color: #999999"'; @@ -161,6 +161,14 @@ % my $card_billday_select_disabled = $payby eq 'CARD' ? '' : 'DISABLED'; % my $chek_billday_select_disabled = $payby eq 'CHEK' ? '' : 'DISABLED'; % +% #false laziness w/view/cust_main/billing.html and misc/payment.cgi +% my $routing_label = $conf->config('echeck-country') eq 'US' +% ? 'ABA/Routing number' +% : 'Routing number'; +% my $routing_size = $conf->config('echeck-country') eq 'CA' ? 4 : 10; +% my $routing_maxlength = $conf->config('echeck-country') eq 'CA' ? 3 : 9; +% +% % my %payby = ( % % 'CARD' => @@ -235,17 +243,17 @@ % join('', map { qq!" } @FS::cust_main::paytypes). % qq!!. % -% qq!${r}!.emt('ABA/Routing number').qq! !. -% qq! !. +% qq!${r}!.emt($routing_label).qq! !. +% qq! !. % qq!(!.emt('help').qq!)!. % qq!!. % % qq!!. % qq!!. % -% ( $conf->exists('cust_main-require-bank-branch') ? +% ( $conf->config('echeck-country') eq 'CA' ? % qq!$r !.emt('Branch number').qq! -% ! : '' ). +% ! : '' ). % % qq!${r}!.emt('Bank name').qq! !. % qq!!. diff --git a/httemplate/edit/process/cust_main.cgi b/httemplate/edit/process/cust_main.cgi index df6cec9df..f75e2a6ae 100755 --- a/httemplate/edit/process/cust_main.cgi +++ b/httemplate/edit/process/cust_main.cgi @@ -44,7 +44,7 @@ if ( $payby ) { if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) { my $payinfo = $cgi->param('payinfo1'). '@'; $payinfo .= $cgi->param('payinfo3').'.' - if $conf->exists('cust_main-require-bank-branch'); + if $conf->config('echeck-country') eq 'CA'; $payinfo .= $cgi->param('payinfo2'); $cgi->param('payinfo',$payinfo); } diff --git a/httemplate/misc/payment.cgi b/httemplate/misc/payment.cgi index 4a867d28d..093494a06 100644 --- a/httemplate/misc/payment.cgi +++ b/httemplate/misc/payment.cgi @@ -140,7 +140,7 @@ % or die "unparsable payinfo ". $cust_main->payinfo; % ($account, $aba) = ($1, $2); % ($branch,$aba) = split('\.',$aba) -% if $conf->exists('cust_main-require-bank-branch'); +% if $conf->config('echeck-country') eq 'CA'; % $payname = $cust_main->payname; % $ss = $cust_main->ss; % $paytype = $cust_main->getfield('paytype'); @@ -148,6 +148,13 @@ % $stateid = $cust_main->getfield('stateid'); % $stateid_state = $cust_main->getfield('stateid_state'); % } +% +% #false laziness w/{edit,view}/cust_main/billing.html +% my $routing_label = $conf->config('echeck-country') eq 'US' +% ? 'ABA/Routing number' +% : 'Routing number'; +% my $routing_size = $conf->config('echeck-country') eq 'CA' ? 4 : 10; +% my $routing_maxlength = $conf->config('echeck-country') eq 'CA' ? 3 : 9; @@ -158,17 +165,17 @@ - <% mt('ABA/Routing number') |h %> + <% mt($routing_label) |h %> - + (<% mt('help') |h %>) -% if ( $conf->exists('cust_main-require-bank-branch') ) { +% if ( $conf->config('echeck-country') eq 'CA' ) { <% mt('Branch number') |h %> - + % } diff --git a/httemplate/misc/process/payment.cgi b/httemplate/misc/process/payment.cgi index f4f9561dc..506e26684 100644 --- a/httemplate/misc/process/payment.cgi +++ b/httemplate/misc/process/payment.cgi @@ -86,8 +86,8 @@ if ( $payby eq 'CHEK' ) { $cgi->param('payinfo2') =~ /^(\d+)$/ or errorpage("Illegal ABA/routing number ". $cgi->param('payinfo2')); my $payinfo2 = $1; - if ( $conf->exists('cust_main-require-bank-branch') ) { - $cgi->param('payinfo3') =~ /^(\d+)$/ + if ( $conf->config('echeck-country') eq 'CA' ) { + $cgi->param('payinfo3') =~ /^(\d{5})$/ or errorpage("Illegal branch number ". $cgi->param('payinfo2')); $payinfo2 = "$1.$payinfo2"; } diff --git a/httemplate/view/cust_main/billing.html b/httemplate/view/cust_main/billing.html index 6e36e99e8..f1add6fcc 100644 --- a/httemplate/view/cust_main/billing.html +++ b/httemplate/view/cust_main/billing.html @@ -85,7 +85,7 @@ % } elsif ( $cust_main->payby eq 'CHEK' || $cust_main->payby eq 'DCHK') { % my( $account, $aba ) = split('@', $cust_main->paymask ); % my $branch = ''; -% ($branch,$aba) = split('\.',$aba) if $conf->exists('cust_main-require-bank-branch'); +% ($branch,$aba) = split('\.',$aba) if $conf->config('echeck-country') eq 'CA'; % my $autodemand = $cust_main->payby eq 'CHEK' ? 'automatic' : 'on-demand'; @@ -93,12 +93,17 @@ +% #false laziness w/edit/cust_main/billing.html and misc/payment.cgi +% my $routing_label = $conf->config('echeck-country') eq 'US' +% ? 'ABA/Routing number' +% : 'Routing number'; + - <% mt('ABA/Routing code') |h %> + <% mt($routing_label) |h %> <% $aba %> -% if ( $conf->exists('cust_main-require-bank-branch') ) { +% if ( $conf->config('echeck-country') eq 'CA' ) { <% mt('Branch number') |h %> <% $branch %> -- 2.11.0