freeside night to infostreet faxNumber (? dunno, what noment wants)
[freeside.git] / FS / FS / part_export / infostreet.pm
index c2386ad..40dee48 100644 (file)
@@ -1,16 +1,43 @@
 package FS::part_export::infostreet;
 
-use vars qw(@ISA);
+use vars qw(@ISA %infostreet2cust_main);
 use FS::part_export;
 
 @ISA = qw(FS::part_export);
 
+%infostreet2cust_main = (
+  'firstName'   => 'first',
+  'lastName'    => 'last',
+  'address1'    => 'address1',
+  'address2'    => 'address2',
+  'city'        => 'city',
+  'state'       => 'state',
+  'zipCode'     => 'zip',
+  'country'     => 'country',
+  'phoneNumber' => 'daytime',
+  'faxNumber'   => 'night',
+);
+
 sub rebless { shift; }
 
 sub _export_insert {
   my( $self, $svc_acct ) = (shift, shift);
+  my $cust_main = $svc_acct->cust_svc->cust_pkg->cust_main;
+  my $accountID = $self->infostreet_queue( $svc_acct->svcnum,
+    'createUser', $svc_acct->username, $svc_acct->_password );
+  foreach my $infostreet_field ( keys %infostreet2cust_main ) {
+    my $error = $self->infostreet_queue( $svc_acct->svcnum,
+      'setContactField', $accountID, $infostreet_field,
+        $cust_main->getfield( $infostreet2cust_main{$infostreet_field} ) );
+    return $error if $error;
+  }
+
   $self->infostreet_queue( $svc_acct->svcnum,
-    'createUser', $svc_acct->username, $svc_acct->password );
+    'setContactField', $accountID, 'email', $cust_main->invoicing_list )
+  #this one is kinda noment-specific
+  || $self->infostreet_queue( $svc_acct->svcnum,
+         'setContactField', $accountID, 'title', $cust_main->agent->agent );
+
 }
 
 sub _export_replace {
@@ -19,7 +46,7 @@ sub _export_replace {
     if $old->username ne $new->username;
   return '' unless $old->_password ne $new->_password;
   $self->infostreet_queue( $new->svcnum,
-    'passwd', $new->username, $new->password );
+    'passwd', $new->username, $new->_password );
 }
 
 sub _export_delete {
@@ -28,6 +55,18 @@ sub _export_delete {
     'purgeAccount,releaseUsername', $svc_acct->username );
 }
 
+sub _export_suspend {
+  my( $self, $svc_acct ) = (shift, shift);
+  $self->infostreet_queue( $svc_acct->svcnum,
+    'setStatus', $svc_acct->username, 'DISABLED' );
+}
+
+sub _export_unsuspend {
+  my( $self, $svc_acct ) = (shift, shift);
+  $self->infostreet_queue( $svc_acct->svcnum,
+    'setStatus', $svc_acct->username, 'ACTIVE' );
+}
+
 sub infostreet_queue {
   my( $self, $svcnum, $method ) = (shift, shift, shift);
   my $queue = new FS::queue {
@@ -63,12 +102,22 @@ sub infostreet_command { #subroutine, not method
   die $key_result{error} unless $key_result{success};
   my $key = $key_result{data};
 
-  my $result = $conn->call($method, $key, @args);
+  #my $result = $conn->call($method, $key, @args);
+  my $result = $conn->call($method, $key, map { $conn->string($_) } @args);
   my %result = _infostreet_parse($result);
   die $result{error} unless $result{success};
 
+  $result->{data};
+
 }
 
+#sub infostreet_command_byid { #subroutine, not method;
+#  my($url, $username, $password, $groupID, $method, @args ) = @_;
+#
+#  infostreet_command
+#
+#}
+
 sub _infostreet_parse { #subroutine, not method
   my $arg = shift;
   map {