This commit was manufactured by cvs2svn to create tag 'freeside_2_1_1'.
[freeside.git] / FS / FS / ClientAPI / Signup.pm
index a4032f3..ec45e79 100644 (file)
@@ -26,6 +26,15 @@ use FS::payby;
 $DEBUG = 0;
 $me = '[FS::ClientAPI::Signup]';
 
+sub clear_cache {
+  warn "$me clear_cache called\n" if $DEBUG;
+  my $cache = new FS::ClientAPI_SessionCache( {
+      'namespace' => 'FS::ClientAPI::Signup',
+  } );
+  $cache->clear();
+  return {};
+}
+
 sub signup_info {
   my $packet = shift;
 
@@ -90,7 +99,7 @@ sub signup_info {
                             ],
 
       'agent' => [ map { my $agent = $_;
-                        +{ map { $_ => $agent->get($_) } @agent_fields }
+                         +{ map { $_ => $agent->get($_) } @agent_fields }
                        }
                        qsearch('agent', { 'disabled' => '' } )
                  ],
@@ -386,9 +395,14 @@ sub signup_info {
     my $agent_signup_info = { %$signup_info };
     delete $agent_signup_info->{agentnum2part_pkg};
     $agent_signup_info->{'agent'} = $session->{'agent'};
-    $agent_signup_info;
-  } else {
-    $signup_info;
+    return $agent_signup_info;
+  } 
+  elsif ( exists $packet->{'keys'} ) {
+    my @keys = @{ $packet->{'keys'} };
+    return { map { $_ => $signup_info->{$_} } @keys };
+  }
+  else {
+    return $signup_info;
   }
 
 }
@@ -437,6 +451,9 @@ sub new_customer {
       unless $packet->{'popnum'} || !scalar(qsearch('svc_acct_pop',{} ));
 
   }
+  elsif ( $svc_x eq 'svc_pbx' ) {
+    #possibly some validation will be needed
+  }
 
   my $agentnum;
   if ( exists $packet->{'session_id'} ) {
@@ -571,18 +588,23 @@ sub new_customer {
     }
     $svc->child_objects( \@acct_snarf );
 
-    push @svc, $svc;
 
   } elsif ( $svc_x eq 'svc_phone' ) {
 
-    my $svc = new FS::svc_phone ( {
+    push @svc, new FS::svc_phone ( {
       'svcpart' => $svcpart,
        map { $_ => $packet->{$_} }
          qw( countrycode phonenum sip_password pin ),
     } );
 
-    push @svc, $svc;
+  } elsif ( $svc_x eq 'svc_pbx' ) {
 
+    push @svc, new FS::svc_pbx ( {
+        'svcpart' => $svcpart,
+        map { $_ => $packet->{$_} } 
+          qw( id title ),
+        } );
+  
   } else {
     die "unknown signup service $svc_x";
   }
@@ -641,14 +663,14 @@ sub new_customer {
 
   if ( $conf->exists('signup_server-realtime') ) {
 
-    #warn "[fs_signup_server] Billing customer...\n" if $Debug;
+    #warn "$me Billing customer...\n" if $Debug;
 
     my $bill_error = $cust_main->bill;
-    #warn "[fs_signup_server] error billing new customer: $bill_error"
+    #warn "$me error billing new customer: $bill_error"
     #  if $bill_error;
 
     $bill_error = $cust_main->apply_payments_and_credits;
-    #warn "[fs_signup_server] error applying payments and credits for".
+    #warn "$me error applying payments and credits for".
     #     " new customer: $bill_error"
     #  if $bill_error;
 
@@ -656,7 +678,7 @@ sub new_customer {
        method        => FS::payby->payby2bop( $packet->{payby} ),
        depend_jobnum => $placeholder->jobnum,
     );
-    #warn "[fs_signup_server] error collecting from new customer: $bill_error"
+    #warn "$me error collecting from new customer: $bill_error"
     #  if $bill_error;
 
     if ($bill_error && ref($bill_error) eq 'HASH') {
@@ -668,6 +690,11 @@ sub new_customer {
              };
     }
 
+    $bill_error = $cust_main->apply_payments_and_credits;
+    #warn "$me error applying payments and credits for".
+    #     " new customer: $bill_error"
+    #  if $bill_error;
+
     if ( $cust_main->balance > 0 ) {
 
       #this makes sense.  credit is "un-doing" the invoice
@@ -703,14 +730,20 @@ sub new_customer {
 
   my %return = ( 'error'          => '',
                  'signup_service' => $svc_x,
+                 'svcnum'         => $svc[0]->svcnum,
+                 'custnum'        => $cust_main->custnum,
                );
 
   if ( $svc_x eq 'svc_acct' ) {
     $return{$_} = $svc[0]->$_() for qw( username _password );
   } elsif ( $svc_x eq 'svc_phone' ) {
     $return{$_} = $svc[0]->$_() for qw( countrycode phonenum sip_password pin );
+  } elsif ( $svc_x eq 'svc_pbx' ) {
+    #$return{$_} = $svc[0]->$_() for qw( ) #nothing yet
   } else {
-    die "unknown signup service $svc_x";
+    return { 'error' => "configuration error: unknown signup service $svc_x" };
+    #die "unknown signup service $svc_x";
+    # return an error that's visible to someone somewhere
   }
 
   return \%return;