order package from self-service
authorjeff <jeff>
Mon, 27 Nov 2006 07:11:53 +0000 (07:11 +0000)
committerjeff <jeff>
Mon, 27 Nov 2006 07:11:53 +0000 (07:11 +0000)
FS/FS/ClientAPI/Signup.pm
fs_selfservice/FS-SelfService/cgi/customer_order_pkg.html [new file with mode: 0755]
fs_selfservice/FS-SelfService/cgi/myaccount_menu.html
fs_selfservice/FS-SelfService/cgi/process_order_pkg.html [new file with mode: 0755]
fs_selfservice/FS-SelfService/cgi/selfservice.cgi

index 3daab9d..8eeab1a 100644 (file)
@@ -119,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'} = [];
@@ -159,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'};
diff --git a/fs_selfservice/FS-SelfService/cgi/customer_order_pkg.html b/fs_selfservice/FS-SelfService/cgi/customer_order_pkg.html
new file mode 100755 (executable)
index 0000000..c01b6b3
--- /dev/null
@@ -0,0 +1,10 @@
+<HTML><HEAD><TITLE>MyAccount</TITLE></HEAD>
+<BODY BGCOLOR="#eeeeee"><FONT SIZE=5>MyAccount</FONT><BR><BR>
+<%= $url = "$selfurl?session=$session_id;action="; ''; %>
+<%= include('myaccount_menu') %>
+<TD VALIGN="top">
+<%= include('order_pkg') %>
+</TD></TR></TABLE>
+<HR>
+<FONT SIZE="-2">powered by <a href="http://www.sisd.com/freeside">freeside</a></FONT>
+</BODY></HTML>
index 6dacc3e..aa24f5d 100644 (file)
@@ -12,7 +12,8 @@ my @menu = (
 { title=>' ' },
 
 { title=>'Purchase', size=>'+1', },
-#  { title=>'Purchase additional package*', url=>'order', 'indent'=>2 },
+  { title=>'Purchase additional package*',
+    url=>'customer_order_pkg', 'indent'=>2 },
 );
 
 if ( 1 ) { #XXXFIXME "enable selfservice prepay features" flag or something, eventually per-pkg or something really fancy
diff --git a/fs_selfservice/FS-SelfService/cgi/process_order_pkg.html b/fs_selfservice/FS-SelfService/cgi/process_order_pkg.html
new file mode 100755 (executable)
index 0000000..79be5eb
--- /dev/null
@@ -0,0 +1,13 @@
+<HTML><HEAD><TITLE>MyAccount</TITLE></HEAD>
+<BODY BGCOLOR="#eeeeee"><FONT SIZE=5>MyAccount</FONT><BR><BR>
+<%= $url = "$selfurl?session=$session_id;action="; ''; %>
+<%= include('myaccount_menu') %>
+<TD VALIGN="top">
+
+<FONT SIZE=4>Package order successful.</FONT>
+
+</TD></TR></TABLE>
+<HR>
+<FONT SIZE="-2">powered by <a href="http://www.sisd.com/freeside">freeside</a></FONT>
+</BODY></HTML>
+
index ed6d623..0f8979c 100644 (file)
@@ -1,4 +1,3 @@
-#!/usr/bin/perl -T
 #!/usr/bin/perl -Tw
 
 use strict;
@@ -11,7 +10,7 @@ use HTML::Entities;
 use FS::SelfService qw( login customer_info invoice
                         payment_info process_payment 
                         process_prepay
-                        list_pkgs
+                        list_pkgs order_pkg signup_info
                         part_svc_info provision_acct provision_external
                         unprovision_svc
                         list_svcs myaccount_passwd
@@ -66,7 +65,7 @@ $session_id = $cgi->param('session');
 
 #order|pw_list XXX ???
 $cgi->param('action') =~
-    /^(myaccount|view_invoice|make_payment|payment_results|recharge_prepay|recharge_results|logout|change_bill|change_ship|provision|provision_svc|process_svc_acct|process_svc_external|delete_svc|change_password|process_change_password)$/
+    /^(myaccount|view_invoice|make_payment|payment_results|recharge_prepay|recharge_results|logout|change_bill|change_ship|customer_order_pkg|process_order_pkg|provision|provision_svc|process_svc_acct|process_svc_external|delete_svc|change_password|process_change_password)$/
   or die "unknown action ". $cgi->param('action');
 my $action = $1;
 
@@ -76,7 +75,9 @@ $FS::SelfService::DEBUG = $DEBUG;
 my $result = eval "&$action();";
 die $@ if $@;
 
-if ( $result->{error} eq "Can't resume session" ) { #ick
+if ( $result->{error} eq "Can't resume session"
+  || $result->{error} eq "Expired session" ) { #ick
+
   do_template('login',{});
   exit;
 }
@@ -107,6 +108,58 @@ sub view_invoice {
 
 }
 
+sub customer_order_pkg {
+  my $init_data = signup_info( 'customer_session_id' => $session_id );
+  return $init_data if ( $init_data->{'error'} );
+
+  my $customer_info = customer_info( 'session_id' => $session_id );
+  return $customer_info if ( $customer_info->{'error'} );
+
+  return {
+    ( map { $_ => $init_data->{$_} }
+          qw( part_pkg security_phrase svc_acct_pop ),
+    ),
+    %$customer_info,
+  };
+}
+
+sub process_order_pkg {
+
+  my $results = '';
+
+  unless ( length($cgi->param('_password')) ) {
+    my $init_data = signup_info( 'customer_session_id' => $session_id );
+    $results = { 'error' => $init_data->{msgcat}{empty_password} };
+    $results = { 'error' => $init_data->{error} } if($init_data->{error});
+  }
+  if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
+    my $init_data = signup_info( 'customer_session_id' => $session_id );
+    $results = { 'error' => $init_data->{msgcat}{passwords_dont_match} };
+    $results = { 'error' => $init_data->{error} } if($init_data->{error});
+    $cgi->param('_password', '');
+    $cgi->param('_password2', '');
+  }
+
+  $results ||= order_pkg (
+    'session_id' => $session_id,
+    map { $_ => $cgi->param($_) }
+        qw( custnum pkgpart username _password _password2 sec_phrase popnum )
+  );
+
+
+  if ( $results->{'error'} ) {
+    $action = 'customer_order_pkg';
+    return {
+      $cgi->Vars,
+      %{customer_order_pkg()},
+      'error' => '<FONT COLOR="#FF0000">'. $results->{'error'}. '</FONT>',
+    };
+  } else {
+    return $results;
+  }
+
+}
+
 sub make_payment {
   payment_info( 'session_id' => $session_id );
 }