import rt 2.0.14
[freeside.git] / fs_signup / FS-SignupClient / SignupClient.pm
index d656d75..0a6cbfb 100644 (file)
@@ -6,8 +6,9 @@ use Exporter;
 use Socket;
 use FileHandle;
 use IO::Handle;
+use Storable qw(nstore_fd fd_retrieve);
 
-$VERSION = '0.02';
+$VERSION = '0.03';
 
 @ISA = qw( Exporter );
 @EXPORT_OK = qw( signup_info new_customer );
@@ -58,7 +59,9 @@ FS::SignupClient - Freeside signup client API
     'pkgpart'          => $pkgpart,
     'username'         => $username,
     '_password'        => $password,
+    'sec_phrase'       => $sec_phrase,
     'popnum'           => $popnum,
+    'agentnum'         => $agentnum, #optional
   } );
 
 =head1 DESCRIPTION
@@ -96,6 +99,8 @@ Each hash reference has the following keys:
   ac
   exch
 
+(Future expansion: fourth argument is the $init_data hash reference)
+
 =cut
 
 sub signup_info {
@@ -104,51 +109,12 @@ sub signup_info {
   print SOCK "signup_info\n";
   SOCK->flush;
 
-  chop ( my $n_cust_main_county = <SOCK> );
-  my @cust_main_county = map {
-    chop ( my $taxnum  = <SOCK> ); 
-    chop ( my $state   = <SOCK> ); 
-    chop ( my $county  = <SOCK> ); 
-    chop ( my $country = <SOCK> );
-    {
-      'taxnum'  => $taxnum,
-      'state'   => $state,
-      'county'  => $county,
-      'country' => $country,
-    };
-  } 1 .. $n_cust_main_county;
-
-  chop ( my $n_part_pkg = <SOCK> );
-  my @part_pkg = map {
-    chop ( my $pkgpart = <SOCK> ); 
-    chop ( my $pkg     = <SOCK> ); 
-    {
-      'pkgpart' => $pkgpart,
-      'pkg'     => $pkg,
-    };
-  } 1 .. $n_part_pkg;
-
-  chop ( my $n_svc_acct_pop = <SOCK> );
-  my @svc_acct_pop = map {
-    chop ( my $popnum = <SOCK> ); 
-    chop ( my $city   = <SOCK> ); 
-    chop ( my $state  = <SOCK> ); 
-    chop ( my $ac     = <SOCK> );
-    chop ( my $exch   = <SOCK> );
-    chop ( my $loc    = <SOCK> );
-    {
-      'popnum' => $popnum,
-      'city'   => $city,
-      'state'  => $state,
-      'ac'     => $ac,
-      'exch'   => $exch,
-      'loc'    => $loc,
-    };
-  } 1 .. $n_svc_acct_pop;
-
+  my $init_data = fd_retrieve(\*SOCK);
   close SOCK;
 
-  \@cust_main_county, \@part_pkg, \@svc_acct_pop;
+  (map { $init_data->{$_} } qw( cust_main_county part_pkg svc_acct_pop ) ),
+  $init_data;
+
 }
 
 =item new_customer HASHREF
@@ -178,6 +144,7 @@ a paramater with the following keys:
   pkgpart
   username
   _password
+  sec_phrase
   popnum
 
 Returns a scalar error message, or the empty string for success.
@@ -187,19 +154,19 @@ Returns a scalar error message, or the empty string for success.
 sub new_customer {
   my $hashref = shift;
 
-  #things that aren't necessary in base class, but are for signup server
-  return "Empty password" unless $hashref->{'_password'};
-  return "No POP selected" unless $hashref->{'popnum'};
-
   socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
   connect(SOCK, sockaddr_un($fs_signupd_socket)) or die "connect: $!";
   print SOCK "new_customer\n";
 
-  print SOCK join("\n", map { $hashref->{$_} } qw(
+  my $signup_data = { map { $_ => $hashref->{$_} } qw(
     first last ss company address1 address2 city county state zip country
     daytime night fax payby payinfo paydate payname invoicing_list
-    referral_custnum pkgpart username _password popnum
-  ) ), "\n";
+    referral_custnum pkgpart username _password sec_phrase popnum
+  ) };
+
+  $signup_data->{agentnum} = $hashref->{agentnum} if $hashref->{agentnum};
+
+  nstore_fd($signup_data, \*SOCK) or die "can't send customer signup: $!";
   SOCK->flush;
 
   chop( my $error = <SOCK> );
@@ -212,7 +179,7 @@ sub new_customer {
 
 =head1 SEE ALSO
 
-L<fs_signupd>, L<FS::SignupServer>, L<FS::cust_main>
+L<fs_signupd>, L<FS::cust_main>
 
 =cut