- unless ( $svc_acct ) { print $writer "Incorrect password.\n"; next; }
-
- my(%hash)=$svc_acct->hash;
- my($new_svc_acct) = new FS::svc_acct ( \%hash );
- $new_svc_acct->setfield('_password',$new_password)
- if $new_password && $new_password ne $old_password;
- $new_svc_acct->setfield('finger',$new_gecos) if $new_gecos;
- $new_svc_acct->setfield('shell',$new_shell) if $new_shell;
- my($error)=$new_svc_acct->replace($svc_acct);
- print $writer $error,"\n";
+
+ $error ||= "Illegal payment type"
+ unless grep { $_ eq $signup_data->{'payby'} } @payby;
+
+ my @invoicing_list = split( /\s*\,\s*/, $signup_data->{'invoicing_list'} );
+
+ my $part_pkg =
+ qsearchs( 'part_pkg', { 'pkgpart' => $signup_data->{'pkgpart'} } )
+ or $error ||= "WARNING: unknown pkgpart ". $signup_data->{pkgpart};
+ my $svcpart = $part_pkg->svcpart unless $error;
+
+ # this should wind up in FS::cust_pkg!
+ my $agent = qsearchs( 'agent', { 'agentnum' => $agentnum } );
+ #my $pkgpart_href = $agent->pkgpart_hashref;
+ $error ||= "WARNING: agent $agentnum can't purchase pkgpart ".
+ $signup_data->{pkgpart}
+ unless $pkgpart_href->{ $signup_data->{pkgpart} };
+
+ my $cust_pkg = new FS::cust_pkg ( {
+ #later#'custnum' => $custnum,
+ 'pkgpart' => $signup_data->{'pkgpart'},
+ } );
+ $error ||= $cust_pkg->check;
+
+ my $svc_acct = new FS::svc_acct ( {
+ 'svcpart' => $svcpart,
+ map { $_ => $signup_data->{$_} }
+ qw( username _password sec_phrase popnum ),
+ } );
+
+ my $y = $svc_acct->setdefault; # arguably should be in new method
+ $error ||= $y unless ref($y);
+
+ $error ||= $svc_acct->check;
+
+ use Tie::RefHash;
+ tie my %hash, 'Tie::RefHash';
+ %hash = ( $cust_pkg => [ $svc_acct ] );
+ $error ||= $cust_main->insert( \%hash, \@invoicing_list );
+
+ warn "[fs_signup_server] Sending results...\n" if $Debug;
+ print $writer $error, "\n";
+