add blacklist/whitelist settings to self-service API, RT#20896
[freeside.git] / FS / FS / ClientAPI / MyAccount.pm
index 3fd6214..92fcd0c 100644 (file)
@@ -14,6 +14,7 @@ use Business::CreditCard;
 use HTML::Entities;
 use Text::CSV_XS;
 use Spreadsheet::WriteExcel;
+use OLE::Storage_Lite;
 use FS::UI::Web::small_custview qw(small_custview); #less doh
 use FS::UI::Web;
 use FS::UI::bytecount qw( display_bytecount );
@@ -390,12 +391,13 @@ sub customer_info {
       $return{balance} = $cust_main->balance;
       $return{next_bill_date} = $cust_main->next_bill_date;
       $return{next_bill_date_pretty} =
-        time2str('%m/%d/%Y', $return{next_bill_date} );
+        $return{next_bill_date} ? time2str('%m/%d/%Y', $return{next_bill_date} )
+                                : '(none)';
     }
 
     my @tickets = $cust_main->tickets;
     # unavoidable false laziness w/ httemplate/view/cust_main/tickets.html
-    if ( FS::TicketSystem->selfservice_priority ) {
+    if ( $FS::TicketSystem::system && FS::TicketSystem->selfservice_priority ) {
       my $dir = $conf->exists('ticket_system-priority_reverse') ? -1 : 1;
       $return{tickets} = [ 
         sort { 
@@ -620,7 +622,8 @@ sub billing_history {
   $return{balance} = $cust_main->balance;
   $return{next_bill_date} = $cust_main->next_bill_date;
   $return{next_bill_date_pretty} =
-    time2str('%m/%d/%Y', $return{next_bill_date} );
+    $return{next_bill_date} ? time2str('%m/%d/%Y', $return{next_bill_date} )
+                            : '(none)';
 
   my @history = ();
 
@@ -929,8 +932,13 @@ sub validate_payment {
   #changing the hidden form values
   my $conf = new FS::Conf;
   my $fee_display = $conf->config('selfservice_process-display') || 'add';
-  my $fee_pkgpart = $conf->config('selfservice_process-pkgpart');
-  if ( $fee_display eq 'add' && $fee_pkgpart ) {
+  my $fee_pkgpart = $conf->config('selfservice_process-pkgpart', $cust_main->agentnum);
+  my $fee_skip_first = $conf->exists('selfservice_process-skip_first');
+  if ( $fee_display eq 'add'
+         and $fee_pkgpart
+         and ! $fee_skip_first || scalar($cust_main->cust_pay)
+     )
+  {
     my $fee_pkg = qsearchs('part_pkg', { pkgpart=>$fee_pkgpart } );
     $amount = sprintf('%.2f', $amount + $fee_pkg->option('setup_fee') );
   }
@@ -1096,8 +1104,10 @@ sub do_process_payment {
 
   #no error, so order the fee package if applicable...
   my $conf = new FS::Conf;
-  my $fee_pkgpart = $conf->config('selfservice_process-pkgpart');
-  if ( $fee_pkgpart ) {
+  my $fee_pkgpart = $conf->config('selfservice_process-pkgpart', $cust_main->agentnum);
+  my $fee_skip_first = $conf->exists('selfservice_process-skip_first');
+  
+  if ( $fee_pkgpart and ! $fee_skip_first || scalar($cust_main->cust_pay) ) {
 
     my $cust_pkg = new FS::cust_pkg { 'pkgpart' => $fee_pkgpart };
 
@@ -1791,6 +1801,44 @@ sub set_svc_status_hash {
 
 }
 
+sub set_svc_status_listadd {
+  my $p = shift;
+
+  my($context, $session, $custnum) = _custoragent_session_custnum($p);
+  return { 'error' => $session } if $context eq 'error';
+
+  #XXX only svc_acct for now
+  my $svc_x = _customer_svc_x( $custnum, $p->{'svcnum'}, 'svc_acct')
+    or return { 'error' => "Service not found" };
+
+  warn "set_svc_status_listadd ". join(' / ', map "$_=>".$p->{$_}, keys %$p )
+    if $DEBUG;
+  my $error = $svc_x->export_setstatus_listadd($p); #$p? returns error?
+  return { 'error' => $error } if $error;
+
+  return {}; #? { 'error' => '' }
+
+}
+
+sub set_svc_status_listdel {
+  my $p = shift;
+
+  my($context, $session, $custnum) = _custoragent_session_custnum($p);
+  return { 'error' => $session } if $context eq 'error';
+
+  #XXX only svc_acct for now
+  my $svc_x = _customer_svc_x( $custnum, $p->{'svcnum'}, 'svc_acct')
+    or return { 'error' => "Service not found" };
+
+  warn "set_svc_status_listdel ". join(' / ', map "$_=>".$p->{$_}, keys %$p )
+    if $DEBUG;
+  my $error = $svc_x->export_setstatus_listdel($p); #$p? returns error?
+  return { 'error' => $error } if $error;
+
+  return {}; #? { 'error' => '' }
+
+}
+
 
 sub acct_forward_info {
   my $p = shift;
@@ -2029,6 +2077,9 @@ sub _usage_details {
     $p->{ending}    = $end;
   }
 
+  die "illegal beginning" if $p->{beginning} !~ /^\d*$/;
+  die "illegal ending"    if $p->{ending}    !~ /^\d*$/;
+
   my (@usage) = &$callback($svc_x, $p->{beginning}, $p->{ending}, 
     %callback_opt
   );