invoice_lines() fix
[freeside.git] / FS / FS / cust_bill.pm
index 708b997..23e8731 100644 (file)
@@ -627,7 +627,7 @@ for supported processors.
 sub realtime_ach {
   my $self = shift;
   $self->realtime_bop(
-    'CHECK',
+    'ECHECK',
     $ach_processor,
     $ach_login,
     $ach_password,
@@ -637,6 +637,28 @@ sub realtime_ach {
   );
 }
 
+=item realtime_lec
+
+Attempts to pay this invoice with phone bill (LEC) payment via a
+Business::OnlinePayment realtime gateway.  See
+http://search.cpan.org/search?mode=module&query=Business%3A%3AOnlinePayment
+for supported processors.
+
+=cut
+
+sub realtime_lec {
+  my $self = shift;
+  $self->realtime_bop(
+    'LEC',
+    $bop_processor,
+    $bop_login,
+    $bop_password,
+    $bop_action,
+    \@bop_options,
+    @_
+  );
+}
+
 sub realtime_bop {
   my( $self, $method, $processor, $login, $password, $action, $options ) = @_;
   my $cust_main = $self->cust_main;
@@ -646,7 +668,7 @@ sub realtime_bop {
   $address .= ", ". $cust_main->address2 if $cust_main->address2;
 
   my($payname, $payfirst, $paylast);
-  if ( $cust_main->payname && $method ne 'CHECK' ) {
+  if ( $cust_main->payname && $method ne 'ECHECK' ) {
     $payname = $cust_main->payname;
     $payname =~ /^\s*([\w \,\.\-\']*)?\s+([\w\,\.\-\']+)\s*$/
       or do {
@@ -690,17 +712,18 @@ sub realtime_bop {
     $content{card_number} = $cust_main->payinfo;
     $cust_main->paydate =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
     $content{expiration} = "$2/$1";
-  } elsif ( $method eq 'CHECK' ) {
+  } elsif ( $method eq 'ECHECK' ) {
     my($account_number,$routing_code) = $cust_main->payinfo;
     ( $content{account_number}, $content{routing_code} ) =
       split('@', $cust_main->payinfo);
     $content{bank_name} = $cust_main->payname;
+  } elsif ( $method eq 'LEC' ) {
+    $content{phone} = $cust_main->payinfo;
   }
   
   my $transaction =
     new Business::OnlinePayment( $processor, @$options );
   $transaction->content(
-    %content,
     'type'           => $method,
     'login'          => $login,
     'password'       => $password,
@@ -720,6 +743,7 @@ sub realtime_bop {
     'referer'        => 'http://cleanwhisker.420.am/',
     'email'          => $email,
     'phone'          => $cust_main->daytime || $cust_main->night,
+    %content, #after
   );
   $transaction->submit();
 
@@ -769,8 +793,9 @@ sub realtime_bop {
   if ( $transaction->is_success() ) {
 
     my %method2payby = (
-      'CC'    => 'CARD',
-      'CHECK' => 'CHEK',
+      'CC'     => 'CARD',
+      'ECHECK' => 'CHEK',
+      'LEC'    => 'LECB',
     );
 
     my $cust_pay = new FS::cust_pay ( {
@@ -1007,9 +1032,9 @@ sub print_text {
   or die "cannot load config file $templatefile";
   $invoice_lines = 0;
   my $wasfunc = 0;
-  foreach ( grep /invoice_lines\(\d+\)/, @invoice_template ) { #kludgy
-    /invoice_lines\((\d+)\)/;
-    $invoice_lines += $1;
+  foreach ( grep /invoice_lines\(\d*\)/, @invoice_template ) { #kludgy
+    /invoice_lines\((\d*)\)/;
+    $invoice_lines += $1 || scalar(@buf);
     $wasfunc=1;
   }
   die "no invoice_lines() functions in template?" unless $wasfunc;
@@ -1067,16 +1092,14 @@ sub print_text {
        #  );
 
   #and subroutine for the template
-
   sub FS::cust_bill::_template::invoice_lines {
-    my $lines = shift or return @buf;
+    my $lines = shift || scalar(@buf);
     map { 
       scalar(@buf) ? shift @buf : [ '', '' ];
     }
     ( 1 .. $lines );
   }
 
-
   #and fill it in
   $FS::cust_bill::_template::page = 1;
   my $lines;
@@ -1096,7 +1119,7 @@ sub print_text {
 
 =head1 VERSION
 
-$Id: cust_bill.pm,v 1.51 2002-11-16 10:33:16 ivan Exp $
+$Id: cust_bill.pm,v 1.57 2002-12-17 21:31:20 ivan Exp $
 
 =head1 BUGS