X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FClientAPI%2FSignup.pm;h=765ce404ecf4f52605eca8ee31bdfce07cc9e7f4;hb=6af1b1bfa25e5ececef5e0dcd38b55917121cee2;hp=dc627e9bd038c2d97f29da64810a21475cb32caa;hpb=f7fd2a3e34da751cbc02bbf215e99c6dc89adc15;p=freeside.git diff --git a/FS/FS/ClientAPI/Signup.pm b/FS/FS/ClientAPI/Signup.pm index dc627e9bd..765ce404e 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; @@ -93,7 +89,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'}); @@ -105,7 +101,22 @@ sub signup_info { } $signup_info->{'part_pkg'} = []; - if ( $packet->{'promo_code'} ) { + + 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') } @@ -154,7 +165,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'}); @@ -186,7 +197,12 @@ sub new_customer { ship_city ship_county ship_state ship_zip ship_country ship_daytime ship_night ship_fax - payby payinfo paycvv paydate payname referral_custnum comments + payby + payinfo paycvv paydate payname + paystart_month paystart_year payissue + payip + + referral_custnum comments ) } ); @@ -209,10 +225,18 @@ 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'}, 'promo_code' => $packet->{'promo_code'}, + 'reg_code' => $packet->{'reg_code'}, } ); #my $error = $cust_pkg->check; #return { 'error' => $error } if $error; @@ -278,7 +302,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; @@ -305,6 +329,11 @@ sub new_customer { } + if ( $reg_code ) { + $error = $reg_code->delete; + return { 'error' => $error } if $error; + } + $error = $placeholder->delete; return { 'error' => $error } if $error;