refactor giant cust_main.pm a little in preparation of adding API methods for maestro...
[freeside.git] / FS / FS / ClientAPI / Agent.pm
index daede59..e1624b9 100644 (file)
@@ -9,7 +9,7 @@ use Digest::MD5 qw(md5_hex);
 use FS::Record qw(qsearchs); # qsearch dbdef dbh);
 use FS::ClientAPI_SessionCache;
 use FS::agent;
-use FS::cust_main qw(smart_search);
+use FS::cust_main::Search qw(smart_search);
 
 sub _cache {
   $cache ||= new FS::ClientAPI_SessionCache( {
@@ -17,6 +17,31 @@ sub _cache {
              } );
 }
 
+sub new_agent {
+  my $p = shift;
+
+  my $conf = new FS::Conf;
+  return { error=>'Disabled' } unless $conf->exists('selfservice-agent_signup');
+
+  #add a customer record and set agent_custnum?
+
+  my $agent = new FS::agent {
+    'typenum'   => $conf->config('selfservice-agent_signup-agent_type'),
+    'agent'     => $p->{'agent'},
+    'username'  => $p->{'username'},
+    '_password' => $p->{'password'},
+    #
+  };
+
+  my $error = $agent->insert;
+  
+  return { 'error' => $error } if $error;
+
+  agent_login({ 'username' => $p->{'username'},
+                'password' => $p->{'password'},
+             });
+}
+
 sub agent_login {
   my $p = shift;