improve echeck validation for canada, deprecate echeck-nonus and cust_main-require...
authorivan <ivan>
Sat, 14 Jan 2012 07:05:18 +0000 (07:05 +0000)
committerivan <ivan>
Sat, 14 Jan 2012 07:05:18 +0000 (07:05 +0000)
FS/FS/Conf.pm
FS/FS/Upgrade.pm
FS/FS/cust_main.pm
conf/echeck-country [new file with mode: 0644]
httemplate/edit/cust_main/billing.html
httemplate/edit/process/cust_main.cgi
httemplate/misc/payment.cgi
httemplate/misc/process/payment.cgi
httemplate/view/cust_main/billing.html

index 37adffb..c588493 100644 (file)
@@ -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.',
index 3134b8c..cf61580 100644 (file)
@@ -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', {});
   
index eaf70cf..3b572fa 100644 (file)
@@ -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 (file)
index 0000000..f4cd62e
--- /dev/null
@@ -0,0 +1 @@
+US
index fd078c5..78fac6c 100644 (file)
 %  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"';
 %  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' =>
 %            join('', map { qq!<OPTION VALUE="$_" !.($paytype eq $_ ? 'SELECTED' : '').">$_</OPTION>" } @FS::cust_main::paytypes).
 %          qq!</SELECT></TD></TR>!.
 %
-%        qq!<TR><TD ALIGN="right" WIDTH="200">${r}!.emt('ABA/Routing number').qq! </TD>!.
-%          qq!<TD COLSPAN="3" WIDTH="408"><INPUT TYPE="text" SIZE=10 MAXLENGTH=9 NAME="CHEK_payinfo2" VALUE="!. ( $payby =~ /^(CHEK|DCHK)$/ ? $aba : '' ). qq!" SIZE=10 MAXLENGTH=9> !.
+%        qq!<TR><TD ALIGN="right" WIDTH="200">${r}!.emt($routing_label).qq! </TD>!.
+%          qq!<TD COLSPAN="3" WIDTH="408"><INPUT TYPE="text" SIZE=$routing_size MAXLENGTH=$routing_maxlength NAME="CHEK_payinfo2" VALUE="!. ( $payby =~ /^(CHEK|DCHK)$/ ? $aba : '' ). qq!"> !.
 %          qq!(<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('../docs/ach.html', 380, 240, 'ach_popup' ), CAPTION, 'ACH Help', STICKY, AUTOSTATUSCAP, CLOSECLICK, DRAGGABLE ); return false;">!.emt('help').qq!</A>)!.
 %          qq!</TD></TR>!.
 %
 %        qq!<INPUT TYPE="hidden" NAME="CHEK_exp_month" VALUE="12">!.
 %        qq!<INPUT TYPE="hidden" NAME="CHEK_exp_year" VALUE="2037">!.
 %
-%        ( $conf->exists('cust_main-require-bank-branch') ? 
+%        ( $conf->config('echeck-country') eq 'CA' ? 
 %               qq!<TR><TD ALIGN="right">$r !.emt('Branch number').qq!</TD><TD COLSPAN="3">
-%                   <INPUT TYPE="text" name="CHEK_payinfo3" VALUE=$branch></TD></TR>! : '' ).
+%                   <INPUT TYPE="text" name="CHEK_payinfo3" VALUE="$branch" SIZE=6 MAXLENGTH=5></TD></TR>! : '' ).
 %   
 %        qq!<TR><TD ALIGN="right" WIDTH="200">${r}!.emt('Bank name').qq! </TD>!.
 %          qq!<TD COLSPAN="3" WIDTH="408"><INPUT TYPE="text" NAME="CHEK_payname" VALUE="!. ( $payby =~ /^(CHEK|DCHK)$/ ? $cust_main->payname : '' ). qq!"></TD></TR>!.
index df6cec9..f75e2a6 100755 (executable)
@@ -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);
   }
index 4a867d2..093494a 100644 (file)
 %       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');
 %     $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;
 
     <INPUT TYPE="hidden" NAME="month" VALUE="12">
     <INPUT TYPE="hidden" NAME="year" VALUE="2037">
       <TD><SELECT NAME="paytype"><% join('', map { qq!<OPTION VALUE="$_" !.($paytype eq $_ ? 'SELECTED' : '').">$_</OPTION>" } @FS::cust_main::paytypes) %></SELECT></TD>
     </TR>
     <TR>
-      <TD ALIGN="right"><% mt('ABA/Routing number') |h %></TD>
+      <TD ALIGN="right"><% mt($routing_label) |h %></TD>
       <TD>
-        <INPUT TYPE="text" SIZE=10 MAXLENGTH=9 NAME="payinfo2" VALUE="<%$aba%>">
+        <INPUT TYPE="text" SIZE="<% $routing_size %>" MAXLENGTH="<% $routing_maxlength %>" NAME="payinfo2" VALUE="<%$aba%>">
         (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('../docs/ach.html', 380, 240, 'ach_popup' ), CAPTION, 'ACH Help', STICKY, AUTOSTATUSCAP, CLOSECLICK, DRAGGABLE ); return false;"><% mt('help') |h %></A>)
       </TD>
     </TR>
-%   if ( $conf->exists('cust_main-require-bank-branch') ) {
+%   if ( $conf->config('echeck-country') eq 'CA' ) {
       <TR>
         <TD ALIGN="right"><% mt('Branch number') |h %></TD>
         <TD>
-          <INPUT TYPE="text" NAME="payinfo3" VALUE="<%$branch%>">
+          <INPUT TYPE="text" NAME="payinfo3" VALUE="<%$branch%>" SIZE=6 MAXLENGTH=5>
         </TD>
       </TR>
 %   }
index f4f9561..506e266 100644 (file)
@@ -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";
     }
index 6e36e99..f1add6f 100644 (file)
@@ -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';
   </TD>
 </TR>
 
+%  #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';
+
 <TR>
-  <TD ALIGN="right"><% mt('ABA/Routing code') |h %></TD>
+  <TD ALIGN="right"><% mt($routing_label) |h %></TD>
   <TD BGCOLOR="#ffffff"><% $aba %></TD>
 </TR>
 
-% if ( $conf->exists('cust_main-require-bank-branch') ) {
+% if ( $conf->config('echeck-country') eq 'CA' ) {
 <TR>
   <TD ALIGN="right"><% mt('Branch number') |h %></TD>
   <TD BGCOLOR="#ffffff"><% $branch %></TD>