X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FClientAPI%2FSignup.pm;h=5d6eb0e24e736f946fdd190a7f8ddca4be8dcc14;hb=0e8a3725a0843c6e38fd5c430d6f1bc4a67d1419;hp=bdcd2fbf13460cfbd6c9ddb05b31dcfcff00bd4e;hpb=2041a9143fac20b79ead4a1ae01224dedf5b27c2;p=freeside.git diff --git a/FS/FS/ClientAPI/Signup.pm b/FS/FS/ClientAPI/Signup.pm index bdcd2fbf1..5d6eb0e24 100644 --- a/FS/FS/ClientAPI/Signup.pm +++ b/FS/FS/ClientAPI/Signup.pm @@ -5,6 +5,7 @@ use Tie::RefHash; use FS::Conf; use FS::Record qw(qsearch qsearchs dbdef); use FS::Msgcat qw(gettext); +use FS::ClientAPI_SessionCache; use FS::agent; use FS::cust_main_county; use FS::part_pkg; @@ -14,12 +15,7 @@ use FS::cust_pkg; use FS::svc_acct; use FS::acct_snarf; use FS::queue; - -use FS::ClientAPI; #hmm -FS::ClientAPI->register_handlers( - 'Signup/signup_info' => \&signup_info, - 'Signup/new_customer' => \&new_customer, -); +use FS::reg_code; sub signup_info { my $packet = shift; @@ -28,7 +24,6 @@ sub signup_info { use vars qw($signup_info); #cache for performance; $signup_info ||= { - 'cust_main_county' => [ map { $_->hashref } qsearch('cust_main_county', {}) ], @@ -69,14 +64,18 @@ sub signup_info { 'svc_acct_pop' => [ map { $_->hashref } qsearch('svc_acct_pop',{} ) ], + 'emailinvoiceonly' => $conf->exists('emailinvoiceonly'), + 'security_phrase' => $conf->exists('security_phrase'), 'payby' => [ $conf->config('signup_server-payby') ], 'cvv_enabled' => defined dbdef->table('cust_main')->column('paycvv'), + 'ship_enabled' => defined dbdef->table('cust_main')->column('ship_last'), + 'msgcat' => { map { $_=>gettext($_) } qw( - passwords_dont_match invalid_card unknown_card_type not_a empty_password + passwords_dont_match invalid_card unknown_card_type not_a empty_password illegal_or_empty_text ) }, 'statedefault' => $conf->config('statedefault') || 'CA', @@ -91,7 +90,7 @@ sub signup_info { my $session = ''; if ( exists $packet->{'session_id'} ) { - my $cache = new Cache::SharedMemoryCache( { + my $cache = new FS::ClientAPI_SessionCache( { 'namespace' => 'FS::ClientAPI::Agent', } ); $session = $cache->get($packet->{'session_id'}); @@ -102,11 +101,43 @@ sub signup_info { } } - if ( $agentnum ) { + $signup_info->{'part_pkg'} = []; + + if ( $packet->{'reg_code'} ) { + $signup_info->{'part_pkg'} = + [ map { { 'payby' => [ $_->payby ], %{$_->hashref} } } + grep { $_->svcpart('svc_acct') } + map { $_->part_pkg } + qsearchs( 'reg_code', { 'code' => $packet->{'reg_code'}, + 'agentnum' => $agentnum, } ) + + ]; + + $signup_info->{'error'} = 'Unknown registration code' + unless @{ $signup_info->{'part_pkg'} }; + + } elsif ( $packet->{'promo_code'} ) { + + $signup_info->{'part_pkg'} = + [ map { { 'payby' => [ $_->payby ], %{$_->hashref} } } + grep { $_->svcpart('svc_acct') } + qsearch( 'part_pkg', { 'promo_code' => { + op=>'ILIKE', + value=>$packet->{'promo_code'} + }, + 'disabled' => '', } ) + ]; + + $signup_info->{'error'} = 'Unknown promotional code' + unless @{ $signup_info->{'part_pkg'} }; + } + + if ( $agentnum && ! @{ $signup_info->{'part_pkg'} } ) { $signup_info->{'part_pkg'} = $signup_info->{'agentnum2part_pkg'}{$agentnum}; - } else { - delete $signup_info->{'part_pkg'}; } + # else { + # delete $signup_info->{'part_pkg'}; + #} if ( $session ) { my $agent_signup_info = { %$signup_info }; @@ -135,7 +166,7 @@ sub new_customer { my $agentnum; if ( exists $packet->{'session_id'} ) { - my $cache = new Cache::SharedMemoryCache( { + my $cache = new FS::ClientAPI_SessionCache( { 'namespace' => 'FS::ClientAPI::Agent', } ); my $session = $cache->get($packet->{'session_id'}); @@ -158,10 +189,22 @@ sub new_customer { || $conf->config('signup_server-default_refnum'), map { $_ => $packet->{$_} } qw( - last first ss company address1 address2 city county state zip country - daytime night fax payby payinfo paycvv paydate payname referral_custnum - comments - ), + + last first ss company address1 address2 + city county state zip country + daytime night fax + + ship_last ship_first ship_ss ship_company ship_address1 ship_address2 + ship_city ship_county ship_state ship_zip ship_country + ship_daytime ship_night ship_fax + + payby + payinfo paycvv paydate payname + paystart_month paystart_year payissue + payip + + referral_custnum comments + ) } ); @@ -183,12 +226,21 @@ sub new_customer { or return { 'error' => "WARNING: unknown pkgpart: $pkgpart" }; my $svcpart = $part_pkg->svcpart('svc_acct'); + my $reg_code = ''; + if ( $packet->{'reg_code'} ) { + $reg_code = qsearchs( 'reg_code', { 'code' => $packet->{'reg_code'}, + 'agentnum' => $agentnum, } ) + or return { 'error' => 'Unknown registration code' }; + } + my $cust_pkg = new FS::cust_pkg ( { #later#'custnum' => $custnum, - 'pkgpart' => $packet->{'pkgpart'}, + 'pkgpart' => $packet->{'pkgpart'}, + 'promo_code' => $packet->{'promo_code'}, + 'reg_code' => $packet->{'reg_code'}, } ); - my $error = $cust_pkg->check; - return { 'error' => $error } if $error; + #my $error = $cust_pkg->check; + #return { 'error' => $error } if $error; my $svc_acct = new FS::svc_acct ( { 'svcpart' => $svcpart, @@ -214,15 +266,15 @@ sub new_customer { my $y = $svc_acct->setdefault; # arguably should be in new method return { 'error' => $y } if $y && !ref($y); - $error = $svc_acct->check; - return { 'error' => $error } if $error; + #$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; + my $error = $placeholder->insert; return { 'error' => $error } if $error; use Tie::RefHash; @@ -251,7 +303,7 @@ sub new_customer { $cust_main->apply_payments; $cust_main->apply_credits; - $bill_error = $cust_main->collect; + $bill_error = $cust_main->collect('realtime' => 1); #warn "[fs_signup_server] error collecting from new customer: $bill_error" # if $bill_error; @@ -278,6 +330,11 @@ sub new_customer { } + if ( $reg_code ) { + $error = $reg_code->delete; + return { 'error' => $error } if $error; + } + $error = $placeholder->delete; return { 'error' => $error } if $error;