X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FClientAPI%2FSignup.pm;h=bdcd2fbf13460cfbd6c9ddb05b31dcfcff00bd4e;hb=2041a9143fac20b79ead4a1ae01224dedf5b27c2;hp=4655b0984d79722d86b7570ff84265428bf8fff3;hpb=c65b166b6e2ebdac5c2eb2e8336ebd1a4087f77c;p=freeside.git diff --git a/FS/FS/ClientAPI/Signup.pm b/FS/FS/ClientAPI/Signup.pm index 4655b0984..bdcd2fbf1 100644 --- a/FS/FS/ClientAPI/Signup.pm +++ b/FS/FS/ClientAPI/Signup.pm @@ -22,7 +22,7 @@ FS::ClientAPI->register_handlers( ); sub signup_info { - #my $packet = shift; + my $packet = shift; my $conf = new FS::Conf; @@ -76,7 +76,7 @@ sub signup_info { 'cvv_enabled' => defined dbdef->table('cust_main')->column('paycvv'), 'msgcat' => { map { $_=>gettext($_) } qw( - passwords_dont_match invalid_card unknown_card_type not_a + passwords_dont_match invalid_card unknown_card_type not_a empty_password ) }, 'statedefault' => $conf->config('statedefault') || 'CA', @@ -87,24 +87,35 @@ sub signup_info { }; - if ( - $conf->config('signup_server-default_agentnum') - && !exists $signup_info->{'part_pkg'} #cache for performance - ) { - my $agentnum = $conf->config('signup_server-default_agentnum'); - my $agent = qsearchs( 'agent', { 'agentnum' => $agentnum } ) - or die "fatal: signup_server-default_agentnum $agentnum not found\n"; - my $pkgpart_href = $agent->pkgpart_hashref; - - $signup_info->{'part_pkg'} = [ - #map { $_->hashref } - map { { 'payby' => [ $_->payby ], %{$_->hashref} } } - grep { $_->svcpart('svc_acct') && $pkgpart_href->{ $_->pkgpart } } - qsearch( 'part_pkg', { 'disabled' => '' } ) - ]; + my $agentnum = $conf->config('signup_server-default_agentnum'); + + my $session = ''; + if ( exists $packet->{'session_id'} ) { + my $cache = new Cache::SharedMemoryCache( { + 'namespace' => 'FS::ClientAPI::Agent', + } ); + $session = $cache->get($packet->{'session_id'}); + if ( $session ) { + $agentnum = $session->{'agentnum'}; + } else { + return { 'error' => "Can't resume session" }; #better error message + } } - $signup_info; + if ( $agentnum ) { + $signup_info->{'part_pkg'} = $signup_info->{'agentnum2part_pkg'}{$agentnum}; + } else { + delete $signup_info->{'part_pkg'}; + } + + if ( $session ) { + my $agent_signup_info = { %$signup_info }; + delete $agent_signup_info->{agentnum2part_pkg}; + $agent_signup_info->{'agent'} = $session->{'agent'}; + $agent_signup_info; + } else { + $signup_info; + } } @@ -117,17 +128,32 @@ sub new_customer { #return "Passwords don't match" # if $hashref->{'_password'} ne $hashref->{'_password2'} return { 'error' => gettext('empty_password') } - unless $packet->{'_password'}; + unless length($packet->{'_password'}); # a bit inefficient for large numbers of pops return { 'error' => gettext('no_access_number_selected') } unless $packet->{'popnum'} || !scalar(qsearch('svc_acct_pop',{} )); + my $agentnum; + if ( exists $packet->{'session_id'} ) { + my $cache = new Cache::SharedMemoryCache( { + 'namespace' => 'FS::ClientAPI::Agent', + } ); + my $session = $cache->get($packet->{'session_id'}); + if ( $session ) { + $agentnum = $session->{'agentnum'}; + } else { + return { 'error' => "Can't resume session" }; #better error message + } + } else { + $agentnum = $packet->{agentnum} + || $conf->config('signup_server-default_agentnum'); + } + #shares some stuff with htdocs/edit/process/cust_main.cgi... take any # common that are still here and library them. my $cust_main = new FS::cust_main ( { #'custnum' => '', - 'agentnum' => $packet->{agentnum} - || $conf->config('signup_server-default_agentnum'), + 'agentnum' => $agentnum, 'refnum' => $packet->{refnum} || $conf->config('signup_server-default_refnum'),