X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2FClientAPI%2FSignup.pm;h=375958b9cb4f9b8409468bf2ad6ecaaa96337d02;hp=0272909be76c266d8bea9b85040f58bc785ce841;hb=e58b9fa1cdf0693f29d0d3db9c861cf4ecd7a77c;hpb=decc019bce51f72bb44ab44cfeec4321c5c760b1 diff --git a/FS/FS/ClientAPI/Signup.pm b/FS/FS/ClientAPI/Signup.pm index 0272909be..375958b9c 100644 --- a/FS/FS/ClientAPI/Signup.pm +++ b/FS/FS/ClientAPI/Signup.pm @@ -3,13 +3,15 @@ package FS::ClientAPI::Signup; use strict; use Tie::RefHash; use FS::Conf; -use FS::Record qw(qsearch qsearchs); +use FS::Record qw(qsearch qsearchs dbdef); use FS::agent; use FS::cust_main_county; use FS::part_pkg; use FS::svc_acct_pop; use FS::cust_main; use FS::cust_pkg; +use FS::svc_acct; +use FS::acct_snarf; use FS::Msgcat qw(gettext); use FS::ClientAPI; #hmm @@ -23,11 +25,31 @@ sub signup_info { my $conf = new FS::Conf; - my $signup_info = { + use vars qw($signup_info); #cache for performance; + $signup_info ||= { 'cust_main_county' => [ map { $_->hashref } qsearch('cust_main_county', {}) ], + 'agent' => + [ + map { $_->hashref } + qsearch('agent', dbdef->table('agent')->column('disabled') + ? { 'disabled' => '' } + : {} + ) + ], + + 'part_referral' => + [ + map { $_->hashref } + qsearch('part_referral', + dbdef->table('part_referral')->column('disabled') + ? { 'disabled' => '' } + : {} + ) + ], + 'agentnum2part_pkg' => { map { @@ -38,7 +60,10 @@ sub signup_info { grep { $_->svcpart('svc_acct') && $href->{ $_->pkgpart } } qsearch( 'part_pkg', { 'disabled' => '' } ) ]; - } qsearch('agent', {} ) + } qsearch('agent', dbdef->table('agent')->column('disabled') + ? { 'disabled' => '' } + : {} + ) }, 'svc_acct_pop' => [ map { $_->hashref } qsearch('svc_acct_pop',{} ) ], @@ -47,6 +72,8 @@ sub signup_info { 'payby' => [ $conf->config('signup_server-payby') ], + 'cvv_enabled' => defined dbdef->table('cust_main')->column('paycvv'), + 'msgcat' => { map { $_=>gettext($_) } qw( passwords_dont_match invalid_card unknown_card_type not_a ) }, @@ -55,9 +82,14 @@ sub signup_info { 'countrydefault' => $conf->config('countrydefault') || 'US', + 'refnum' => $conf->config('signup_server-default_refnum'), + }; - if ( $conf->config('signup_server-default_agentnum') ) { + 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"; @@ -79,14 +111,14 @@ sub new_customer { my $packet = shift; my $conf = new FS::Conf; - my $error = ''; #things that aren't necessary in base class, but are for signup server #return "Passwords don't match" # if $hashref->{'_password'} ne $hashref->{'_password2'} - $error ||= gettext('empty_password') unless $packet->{'_password'}; + return { 'error' => gettext('empty_password') } + unless $packet->{'_password'}; # a bit inefficient for large numbers of pops - $error ||= gettext('no_access_number_selected') + return { 'error' => gettext('no_access_number_selected') } unless $packet->{'popnum'} || !scalar(qsearch('svc_acct_pop',{} )); #shares some stuff with htdocs/edit/process/cust_main.cgi... take any @@ -100,12 +132,13 @@ sub new_customer { map { $_ => $packet->{$_} } qw( last first ss company address1 address2 city county state zip country - daytime night fax payby payinfo paydate payname referral_custnum comments + daytime night fax payby payinfo paycvv paydate payname referral_custnum + comments ), } ); - $error ||= "Illegal payment type" + return { 'error' => "Illegal payment type" } unless grep { $_ eq $packet->{'payby'} } $conf->config('signup_server-payby'); @@ -116,17 +149,19 @@ sub new_customer { $packet->{'pkgpart'} =~ /^(\d+)$/ or '' =~ /^()$/; my $pkgpart = $1; + return { 'error' => 'Please select a package' } unless $pkgpart; #msgcat my $part_pkg = qsearchs( 'part_pkg', { 'pkgpart' => $pkgpart } ) - or $error ||= "WARNING: unknown pkgpart: $pkgpart"; - my $svcpart = $part_pkg->svcpart('svc_acct') unless $error; + or return { 'error' => "WARNING: unknown pkgpart: $pkgpart" }; + my $svcpart = $part_pkg->svcpart('svc_acct'); my $cust_pkg = new FS::cust_pkg ( { #later#'custnum' => $custnum, 'pkgpart' => $packet->{'pkgpart'}, } ); - $error ||= $cust_pkg->check; + my $error = $cust_pkg->check; + return { 'error' => $error } if $error; my $svc_acct = new FS::svc_acct ( { 'svcpart' => $svcpart, @@ -134,18 +169,34 @@ sub new_customer { qw( username _password sec_phrase popnum ), } ); + my @acct_snarf; + my $snarfnum = 1; + while ( length($packet->{"snarf_machine$snarfnum"}) ) { + my $acct_snarf = new FS::acct_snarf ( { + 'machine' => $packet->{"snarf_machine$snarfnum"}, + 'protocol' => $packet->{"snarf_protocol$snarfnum"}, + 'username' => $packet->{"snarf_username$snarfnum"}, + '_password' => $packet->{"snarf_password$snarfnum"}, + } ); + $snarfnum++; + push @acct_snarf, $acct_snarf; + } + $svc_acct->child_objects( \@acct_snarf ); + my $y = $svc_acct->setdefault; # arguably should be in new method - $error ||= $y unless ref($y); + return { 'error' => $y } if $y && !ref($y); - $error ||= $svc_acct->check; + $error = $svc_acct->check; + 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 ); + $error = $cust_main->insert( \%hash, \@invoicing_list, 'noexport' => 1 ); + return { 'error' => $error } if $error; - if ( ! $error && $conf->exists('signup_server-realtime') ) { + if ( $conf->exists('signup_server-realtime') ) { #warn "[fs_signup_server] Billing customer...\n" if $Debug; @@ -171,13 +222,14 @@ sub new_customer { local $FS::svc_Common::noexport_hack = 1; $cust_main->cancel('quiet'=>1); - $error = '_decline'; + return { 'error' => '_decline' }; } } - $cust_main->reexport unless $error; + $cust_main->reexport; - return { error => $error }; + return { error => '' }; } +1;