X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FClientAPI%2FSignup.pm;h=bd8e1a4be09f80fea972615b6d276b2f60f117b0;hb=5b30406d72c3f723582af30708352f2e671dc07d;hp=b1cc3f08e5884b01e867f0555c4dc544aee8d14e;hpb=2bd722cd60781c197fb5d98dcbb0f5f630bb2a12;p=freeside.git diff --git a/FS/FS/ClientAPI/Signup.pm b/FS/FS/ClientAPI/Signup.pm index b1cc3f08e..bd8e1a4be 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::Misc qw(card_types); use FS::ClientAPI_SessionCache; use FS::agent; use FS::cust_main_county; @@ -52,7 +53,11 @@ sub signup_info { my $href = $_->pkgpart_hashref; $_->agentnum => [ - map { { 'payby' => [ $_->payby ], %{$_->hashref} } } + map { { 'payby' => [ $_->payby ], + 'freq_pretty' => $_->freq_pretty, + 'options' => { $_->options }, + %{$_->hashref} + } } grep { $_->svcpart('svc_acct') && $href->{ $_->pkgpart } } qsearch( 'part_pkg', { 'disabled' => '' } ) ]; @@ -70,6 +75,8 @@ sub signup_info { 'payby' => [ $conf->config('signup_server-payby') ], + 'card_types' => card_types(), + 'cvv_enabled' => defined dbdef->table('cust_main')->column('paycvv'), 'ship_enabled' => defined dbdef->table('cust_main')->column('ship_last'), @@ -84,6 +91,8 @@ sub signup_info { 'refnum' => $conf->config('signup_server-default_refnum'), + 'default_pkgpart' => $conf->config('signup_server-default_pkgpart'), + }; my @addl = qw( signup_server-classnum2 signup_server-classnum3 ); @@ -91,17 +100,23 @@ sub signup_info { if ( grep { $conf->exists($_) } @addl ) { $signup_info->{optional_packages} = []; + $signup_info->{optional_packages_options} = []; foreach my $addl ( @addl ) { my $classnum = $conf->config($addl) or next; my @pkgs = map { $_->hashref } qsearch( 'part_pkg', { classnum => $classnum } ); push @{$signup_info->{optional_packages}}, \@pkgs; + my @options = map { { $_->options, + 'freq_pretty' => $_->freq_pretty + } } @pkgs; + push @{$signup_info->{options_packages_options}}, \@options } } - my $agentnum = $conf->config('signup_server-default_agentnum'); + my $agentnum = $packet->{'agentnum'} + || $conf->config('signup_server-default_agentnum'); my $session = ''; if ( exists $packet->{'session_id'} ) { @@ -114,13 +129,30 @@ sub signup_info { } else { return { 'error' => "Can't resume session" }; #better error message } + }elsif( exists $packet->{'customer_session_id'} ) { + my $cache = new FS::ClientAPI_SessionCache( { + 'namespace' => 'FS::ClientAPI::MyAccount', + } ); + $session = $cache->get($packet->{'customer_session_id'}); + if ( $session ) { + my $custnum = $session->{'custnum'}; + my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum }); + return { 'error' => "Can't find your customer record" } unless $cust_main; + $agentnum = $cust_main->agentnum; + } else { + return { 'error' => "Can't resume session" }; #better error message + } } $signup_info->{'part_pkg'} = []; if ( $packet->{'reg_code'} ) { $signup_info->{'part_pkg'} = - [ map { { 'payby' => [ $_->payby ], %{$_->hashref} } } + [ map { { 'payby' => [ $_->payby ], + 'freq_pretty' => $_->freq_pretty, + 'options' => { $_->options }, + %{$_->hashref} + } } grep { $_->svcpart('svc_acct') } map { $_->part_pkg } qsearchs( 'reg_code', { 'code' => $packet->{'reg_code'}, @@ -134,7 +166,11 @@ sub signup_info { } elsif ( $packet->{'promo_code'} ) { $signup_info->{'part_pkg'} = - [ map { { 'payby' => [ $_->payby ], %{$_->hashref} } } + [ map { { 'payby' => [ $_->payby ], + 'freq_pretty' => $_->freq_pretty, + 'options' => { $_->options }, + %{$_->hashref} + } } grep { $_->svcpart('svc_acct') } qsearch( 'part_pkg', { 'promo_code' => { op=>'ILIKE', @@ -154,7 +190,7 @@ sub signup_info { # delete $signup_info->{'part_pkg'}; #} - if ( $session ) { + if ( exists $packet->{'session_id'} ) { my $agent_signup_info = { %$signup_info }; delete $agent_signup_info->{agentnum2part_pkg}; $agent_signup_info->{'agent'} = $session->{'agent'}; @@ -315,8 +351,7 @@ sub new_customer { #warn "[fs_signup_server] error billing new customer: $bill_error" # if $bill_error; - $cust_main->apply_payments; - $cust_main->apply_credits; + $cust_main->apply_payments_and_credits; $bill_error = $cust_main->collect('realtime' => 1); #warn "[fs_signup_server] error collecting from new customer: $bill_error"