RT 77532 - added contact phone numbers to advanced customer report
[freeside.git] / FS / FS / ClientAPI / MyAccount.pm
index a38bcd6..16c1ccc 100644 (file)
@@ -216,9 +216,9 @@ sub login {
   my $p = shift;
 
   my $conf = new FS::Conf;
-
   my $svc_x = '';
   my $session = {};
+
   if ( $p->{'domain'} eq 'svc_phone'
        && $conf->exists('selfservice_server-phone_login') ) { 
 
@@ -237,9 +237,16 @@ sub login {
     $svc_x = $svc_phone;
 
   } elsif ( $p->{email}
-              && (my $contact = FS::contact->by_selfservice_email($p->{email}))
+              && (my $contact = FS::contact->by_selfservice_email($p->{email},'case_insensitive'))
           )
   {
+    if ($conf->exists('username-uppercase') || $conf->exists('username-uppercase', $contact->cust_main->agentnum)) {
+      $contact = FS::contact->by_selfservice_email_custnum($p->{email}, $contact->custnum);
+    }
+
+    return { error => 'Username '.$p->{email}.' not found!'}
+      unless $contact;
+
     return { error => 'Incorrect contact password.' }
       unless $contact->authenticate_password($p->{'password'});
 
@@ -334,6 +341,7 @@ sub login {
 
   return { 'error'      => '',
            'session_id' => $session_id,
+           %$session,
          };
 }
 
@@ -600,6 +608,8 @@ sub customer_info_short {
     for (@cust_main_editable_fields) {
       $return{$_} = $cust_main->get($_);
     }
+    $return{$_} = $cust_main->masked($_) for qw/ss stateid/;
+
     #maybe a little more expensive, but it should be cached by now
     for (@location_editable_fields) {
       $return{$_} = $cust_main->bill_location->get($_);
@@ -610,6 +620,7 @@ sub customer_info_short {
       $return{payinfo} = $cust_main->paymask;
       @return{'month', 'year'} = $cust_main->paydate_monthyear;
     }
+    else { delete $return{'payinfo'}; }
     
     my @invoicing_list = $cust_main->invoicing_list;
     $return{'invoicing_list'} =
@@ -723,7 +734,7 @@ sub edit_info {
     or return { 'error' => "unknown custnum $custnum" };
 
   my $conf = new FS::Conf;
-  if (($p->{payby} eq "CHEK" || $p->{payby} eq "DCHEK") && $conf->exists('selfservice-ACH_info_readonly')) {
+  if (($p->{payby} eq "CHEK" || $p->{payby} eq "DCHK") && $conf->exists('selfservice-ACH_info_readonly')) {
     return { 'error' => "You do not have authority to add a bank account" };
   }
 
@@ -935,6 +946,7 @@ sub payment_info {
   $return{paybatch} = $return{payunique};  #back compat
 
   $return{credit_card_surcharge_percentage} = $conf->config('credit-card-surcharge-percentage', $cust_main->agentnum);
+  $return{credit_card_surcharge_flatfee} = $conf->config('credit-card-surcharge-flatfee', $cust_main->agentnum);
 
   return { 'error' => '',
            %return,
@@ -1012,17 +1024,11 @@ sub validate_payment {
     my $payinfo2 = $1;
     $payinfo = $payinfo1. '@'. $payinfo2;
 
-    $payinfo = $cust_main->payinfo
-      if $cust_main->paymask eq $payinfo;
-
     my $achonfile = 0;
-    foreach my $cust_payby ($cust_main->cust_payby('CHEK','DCHK')) {
-      if ( $cust_payby->paymask eq $payinfo ) {
-        $payinfo = $cust_payby->payinfo;
+      if ( $cust_main->paymask eq $payinfo ) {
+        $payinfo = $cust_main->payinfo;
         $achonfile = 1;
-        last;
       }
-    }
 
     if ($conf->exists('selfservice-ACH_info_readonly') && !$achonfile) {
       return { 'error' => "You are not allowed to change your payment information." };
@@ -1654,128 +1660,6 @@ sub payment_receipt {
          };
 }
 
-sub list_payby {
-  my $p = shift;
-
-  my($context, $session, $custnum) = _custoragent_session_custnum($p);
-  return { 'error' => $session } if $context eq 'error';
-
-  my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
-    or return { 'error' => "unknown custnum $custnum" };
-
-  return {
-    'payby' => [ map {
-                       my $cust_payby = $_;
-                       +{
-                          map { $_ => $cust_payby->$_ }
-                            qw( custpaybynum weight payby paymask paydate
-                                payname paystate paytype
-                              )
-                        };
-                     }
-                   $cust_main->cust_payby
-               ],
-  };
-}
-
-sub insert_payby {
-  my $p = shift;
-
-  my($context, $session, $custnum) = _custoragent_session_custnum($p);
-  return { 'error' => $session } if $context eq 'error';
-
-  #XXX payinfo1 + payinfo2 for CHEK?
-  #or take the opportunity to use separate, more well- named fields?
-  # my $payinfo;
-  # $p->{'payinfo1'} =~ /^([\dx]+)$/
-  #   or return { 'error' => "illegal account number ". $p->{'payinfo1'} };
-  # my $payinfo1 = $1;
-  #  $p->{'payinfo2'} =~ /^([\dx\.]+)$/ # . turned on by echeck-country CA ?
-  #   or return { 'error' => "illegal ABA/routing number ". $p->{'payinfo2'} };
-  # my $payinfo2 = $1;
-  # $payinfo = $payinfo1. '@'. $payinfo2;
-
-  my $cust_payby = new FS::cust_payby {
-    'custnum' => $custnum,
-    map { $_ => $p->{$_} } qw( weight payby payinfo paycvv paydate payname
-                               paystate paytype payip 
-                             ),
-  };
-
-  my $error = $cust_payby->insert;
-  if ( $error ) {
-    return { 'error' => $error };
-  } else {
-    return { 'custpaybynum' => $cust_payby->custpaybynum };
-  }
-  
-}
-
-sub update_payby {
-  my $p = shift;
-
-  my($context, $session, $custnum) = _custoragent_session_custnum($p);
-  return { 'error' => $session } if $context eq 'error';
-
-  my $cust_payby = qsearchs('cust_payby', {
-                              'custnum'      => $custnum,
-                              'custpaybynum' => $p->{'custpaybynum'},
-                           })
-    or return { 'error' => 'unknown custpaybynum '. $p->{'custpaybynum'} };
-
-  foreach my $field (
-    qw( weight payby payinfo paycvv paydate payname paystate paytype payip )
-  ) {
-    next unless exists($p->{$field});
-    $cust_payby->set($field,$p->{$field});
-  }
-
-  my $error = $cust_payby->replace;
-  if ( $error ) {
-    return { 'error' => $error };
-  } else {
-    return { 'custpaybynum' => $cust_payby->custpaybynum };
-  }
-  
-}
-
-sub verify_payby {
-  my $p = shift;
-
-  my($context, $session, $custnum) = _custoragent_session_custnum($p);
-  return { 'error' => $session } if $context eq 'error';
-
-  my $cust_payby = qsearchs('cust_payby', {
-                              'custnum'      => $custnum,
-                              'custpaybynum' => $p->{'custpaybynum'},
-                           })
-    or return { 'error' => 'unknown custpaybynum '. $p->{'custpaybynum'} };
-
-  return { 'error' => $cust_payby->verify };
-  
-}
-
-sub delete_payby {
-  my $p = shift;
-
-  my($context, $session, $custnum) = _custoragent_session_custnum($p);
-  return { 'error' => $session } if $context eq 'error';
-
-  my $cust_payby = qsearchs('cust_payby', {
-                              'custnum'      => $custnum,
-                              'custpaybynum' => $p->{'custpaybynum'},
-                           })
-    or return { 'error' => 'unknown custpaybynum '. $p->{'custpaybynum'} };
-
-  my $conf = new FS::Conf;
-  if (($cust_payby->payby eq "DCHK" || $cust_payby->payby eq "CHEK") && $conf->exists('selfservice-ACH_info_readonly')) {
-    return { 'error' => "Sorry you do not have permission to delete bank information." };
-  }
-  else {
-    return { 'error' => $cust_payby->delete };
-  }
-}
-
 sub cancel {
   my $p = shift;
   my $session = _cache->get($p->{'session_id'})
@@ -3246,7 +3130,11 @@ sub reset_passwd {
   my $cust_main = '';
   if ( $p->{'email'} ) { #new-style, changes contact and svc_acct
   
-    $contact = FS::contact->by_selfservice_email($p->{'email'});
+    $contact = FS::contact->by_selfservice_email($p->{'email'}, 'case_insensitive');
+
+    if ($conf->exists('username-uppercase') || $conf->exists('username-uppercase', $contact->cust_main->agentnum)) {
+      $contact = FS::contact->by_selfservice_email_custnum($p->{email}, $contact->custnum);
+    }
 
     $cust_main = $contact->cust_main if $contact;
 
@@ -3882,4 +3770,3 @@ sub _custoragent_session_custnum {
 }
 
 1;
-