add edit_info to selfservice API
authorivan <ivan>
Tue, 23 Dec 2003 00:51:42 +0000 (00:51 +0000)
committerivan <ivan>
Tue, 23 Dec 2003 00:51:42 +0000 (00:51 +0000)
FS/FS/ClientAPI/MyAccount.pm
fs_selfservice/FS-SelfService/SelfService.pm

index 8ac1b8d..421a082 100644 (file)
@@ -18,6 +18,7 @@ use FS::ClientAPI; #hmm
 FS::ClientAPI->register_handlers(
   'MyAccount/login'            => \&login,
   'MyAccount/customer_info'    => \&customer_info,
+  'MyAccount/edit_info'        => \&edit_info,
   'MyAccount/invoice'          => \&invoice,
   'MyAccount/cancel'           => \&cancel,
   'MyAccount/list_pkgs'        => \&list_pkgs,
@@ -25,6 +26,14 @@ FS::ClientAPI->register_handlers(
   'MyAccount/cancel_pkg'       => \&cancel_pkg,
 );
 
+use vars qw( @cust_main_editable_fields );
+@cust_main_editable_fields = qw(
+  first last company address1 address2 city
+    county state zip country daytime night fax
+  ship_first ship_last ship_company ship_address1 ship_address2 ship_city
+    ship_state ship_zip ship_country ship_daytime ship_night ship_fax
+);
+
 #store in db?
 my $cache = new Cache::SharedMemoryCache();
 
@@ -100,6 +109,10 @@ sub customer_info {
 
     $return{name} = $cust_main->first. ' '. $cust_main->get('last');
 
+    for (@cust_main_editable_fields) {
+      $return{$_} = $cust_main->get($_);
+    }
+
   } else { #no customer record
 
     my $svc_acct = qsearchs('svc_acct', { 'svcnum' => $session->{'svcnum'} } )
@@ -116,6 +129,27 @@ sub customer_info {
 
 }
 
+sub edit_info {
+  my $p = shift;
+  my $session = $cache->get($p->{'session_id'})
+    or return { 'error' => "Can't resume session" }; #better error message
+
+  my $custnum = $session->{'custnum'}
+    or return { 'error' => "no customer record" };
+
+  my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+    or return { 'error' => "unknown custnum $custnum" };
+
+  my $new = new FS::cust_main { $cust_main->hash };
+  $new->set( $_ => $p->{$_} )
+    foreach grep { exists $p->{$_} } @cust_main_editable_fields;
+  my $error = $new->replace($cust_main);
+  return { 'error' => $error } if $error;
+  #$cust_main = $new;
+  
+  return { 'error' => '' };
+}
+
 sub invoice {
   my $p = shift;
   my $session = $cache->get($p->{'session_id'})
index fae26ba..0697ab9 100644 (file)
@@ -23,6 +23,7 @@ $socket .= '.'.$tag if defined $tag && length($tag);
   'chsh'            => 'passwd/passwd',
   'login'           => 'MyAccount/login',
   'customer_info'   => 'MyAccount/customer_info',
+  'edit_info'       => 'MyAccount/edit_info',
   'invoice'         => 'MyAccount/invoice',
   'cancel'          => 'MyAccount/cancel',
   'list_pkgs'       => 'MyAccount/list_pkgs',
@@ -111,7 +112,7 @@ FS::SelfService - Freeside self-service API
   my $customer_info = customer_info( { 'session_id' => $session_id } );
 
   #payment_info and process_payment are available in 1.5+ only
-  my $payment_info = payment_info) { 'session_id' => $session_id } );
+  my $payment_info = payment_info( { 'session_id' => $session_id } );
 
   #!!! process_payment example
 
@@ -242,8 +243,23 @@ the following keys: invnum, date, owed
 
 An HTML fragment containing shipping and billing addresses.
 
+=item The following fields are also returned: first last company address1 address2 city county state zip country daytime night fax ship_first ship_last ship_company ship_address1 ship_address2 ship_city ship_state ship_zip ship_country ship_daytime ship_night ship_fax
+
 =back
 
+=item edit_info HASHREF
+
+Takes a hash reference as parameter with any of the following keys:
+
+first last company address1 address2 city county state zip country daytime night fax ship_first ship_last ship_company ship_address1 ship_address2 ship_city ship_state ship_zip ship_country ship_daytime ship_night ship_fax
+
+If a field exists, the customer record is updated with the new value of that
+field.  If a field does not exist, that field is not changed on the customer
+record.
+
+Returns a hash reference with a single key, B<error>, empty on success, or an
+error message on errors
+
 =item invoice HASHREF
 
 Returns an invoice.  Takes a hash reference as parameter with two keys: