X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2FClientAPI%2FSignup.pm;h=bdcd2fbf13460cfbd6c9ddb05b31dcfcff00bd4e;hp=60639b132fb5186753dd266a7dd9a4f61af33094;hb=0cbeb01df08457b056a7ae775b4924c266b4228b;hpb=9ae101389f2fe652575c6ab314a5e95c2283b72e diff --git a/FS/FS/ClientAPI/Signup.pm b/FS/FS/ClientAPI/Signup.pm index 60639b132..bdcd2fbf1 100644 --- a/FS/FS/ClientAPI/Signup.pm +++ b/FS/FS/ClientAPI/Signup.pm @@ -4,6 +4,7 @@ use strict; use Tie::RefHash; use FS::Conf; use FS::Record qw(qsearch qsearchs dbdef); +use FS::Msgcat qw(gettext); use FS::agent; use FS::cust_main_county; use FS::part_pkg; @@ -12,7 +13,7 @@ use FS::cust_main; use FS::cust_pkg; use FS::svc_acct; use FS::acct_snarf; -use FS::Msgcat qw(gettext); +use FS::queue; use FS::ClientAPI; #hmm FS::ClientAPI->register_handlers( @@ -21,7 +22,7 @@ FS::ClientAPI->register_handlers( ); sub signup_info { - #my $packet = shift; + my $packet = shift; my $conf = new FS::Conf; @@ -40,6 +41,16 @@ sub signup_info { ) ], + 'part_referral' => + [ + map { $_->hashref } + qsearch('part_referral', + dbdef->table('part_referral')->column('disabled') + ? { 'disabled' => '' } + : {} + ) + ], + 'agentnum2part_pkg' => { map { @@ -65,33 +76,46 @@ 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', 'countrydefault' => $conf->config('countrydefault') || 'US', + 'refnum' => $conf->config('signup_server-default_refnum'), + }; - 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; + } } @@ -104,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'), @@ -159,7 +198,8 @@ sub new_customer { my @acct_snarf; my $snarfnum = 1; - while ( length($packet->{"snarf_machine$snarfnum"}) ) { + while ( exists($packet->{"snarf_machine$snarfnum"}) + && length($packet->{"snarf_machine$snarfnum"}) ) { my $acct_snarf = new FS::acct_snarf ( { 'machine' => $packet->{"snarf_machine$snarfnum"}, 'protocol' => $packet->{"snarf_protocol$snarfnum"}, @@ -177,12 +217,28 @@ sub new_customer { $error = $svc_acct->check; return { 'error' => $error } if $error; + #setup a job dependancy to delay provisioning + my $placeholder = new FS::queue ( { + 'job' => 'FS::ClientAPI::Signup::__placeholder', + 'status' => 'locked', + } ); + $error = $placeholder->insert; + return { 'error' => $error } if $error; + use Tie::RefHash; tie my %hash, 'Tie::RefHash'; %hash = ( $cust_pkg => [ $svc_acct ] ); #msgcat - $error = $cust_main->insert( \%hash, \@invoicing_list, 'noexport' => 1 ); - return { 'error' => $error } if $error; + $error = $cust_main->insert( + \%hash, + \@invoicing_list, + 'depend_jobnum' => $placeholder->jobnum, + ); + if ( $error ) { + my $perror = $placeholder->delete; + $error .= " (Additionally, error removing placeholder: $perror)" if $perror; + return { 'error' => $error }; + } if ( $conf->exists('signup_server-realtime') ) { @@ -210,11 +266,20 @@ sub new_customer { local $FS::svc_Common::noexport_hack = 1; $cust_main->cancel('quiet'=>1); + my $perror = $placeholder->depended_delete; + warn "error removing provisioning jobs after decline: $perror" if $perror; + unless ( $perror ) { + $perror = $placeholder->delete; + warn "error removing placeholder after decline: $perror" if $perror; + } + return { 'error' => '_decline' }; } } - $cust_main->reexport; + + $error = $placeholder->delete; + return { 'error' => $error } if $error; return { error => '' };