order package from self-service
[freeside.git] / FS / FS / ClientAPI / Signup.pm
index 4947a64..8eeab1a 100644 (file)
@@ -5,6 +5,8 @@ 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;
 use FS::part_pkg;
@@ -23,7 +25,6 @@ sub signup_info {
 
   use vars qw($signup_info); #cache for performance;
   $signup_info ||= {
-
     'cust_main_county' =>
       [ map { $_->hashref } qsearch('cust_main_county', {}) ],
 
@@ -64,16 +65,20 @@ 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') ],
 
+    'card_types' => card_types(),
+
     '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',
@@ -82,13 +87,30 @@ 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 );
+
+  if ( grep { $conf->exists($_) } @addl ) {
+  
+    $signup_info->{optional_packages} = [];
+
+    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 $agentnum = $conf->config('signup_server-default_agentnum');
 
   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'});
@@ -97,6 +119,19 @@ 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'} = [];
@@ -137,7 +172,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'};
@@ -164,7 +199,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'});
@@ -196,7 +231,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
     )
 
   } );
@@ -296,7 +336,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;