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;
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;
+ my $packet = shift;
my $conf = new FS::Conf;
'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
+ passwords_dont_match invalid_card unknown_card_type not_a empty_password
) },
'statedefault' => $conf->config('statedefault') || 'CA',
};
- 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 FS::ClientAPI_SessionCache( {
+ '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;
+ $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'};
+ #}
+
+ 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;
+ }
}
#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 FS::ClientAPI_SessionCache( {
+ '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'),
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 referral_custnum comments
+ )
} );
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,
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;
}
+ if ( $reg_code ) {
+ $error = $reg_code->delete;
+ return { 'error' => $error } if $error;
+ }
+
$error = $placeholder->delete;
return { 'error' => $error } if $error;