don't send zip+4 to vitelity e911, RT#76262
[freeside.git] / FS / FS / part_export / vitelity.pm
index 2956326..574592f 100644 (file)
@@ -1,6 +1,7 @@
 package FS::part_export::vitelity;
 use base qw( FS::part_export );
 
+use strict;
 use vars qw( %info );
 use Tie::IxHash;
 use Data::Dumper;
@@ -310,7 +311,7 @@ sub _export_insert {
       'name'          => $svc_phone->phone_name_or_cust,
       'streetnumber'  => $sa->{number},
       'streetprefix'  => $sa->{prefix},
-      'streetname'    => $sa->{street}. ' '. $street{type},
+      'streetname'    => $sa->{street}. ' '. $sa->{type},
       'streetsuffix'  => $sa->{suffix},
       'unit'          => ( $sa->{sec_unit_num}
                              ? $sa->{sec_unit_type}. ' '. $sa->{sec_unit_num}
@@ -322,8 +323,7 @@ sub _export_insert {
       'billnumber'    => $svc_phone->phonenum, #?? do we need a new field for this?
       'contactnumber' => $cust_main->daytime,
     );
-
-    warn "Vitelity reponse: $result" if $self->option('debug');
+    warn "Vitelity response: $result" if $self->option('debug');
 
     if ( $result =~ /^ok:/i ) {
       my($ok, $portid, $sig, $bill) = split(':', $result);
@@ -363,6 +363,8 @@ sub _export_insert {
 
   if ( $result ne $success ) {
     return "Error running Vitelity $command: $result";
+  } elsif ( $self->option('debug') ) {
+    warn "Vitelity response: $result";
   }
 
   ###
@@ -372,9 +374,11 @@ sub _export_insert {
   my $cnam_result = $self->vitelity_command('cnamenable',
                                               'did'=>$svc_phone->phonenum,
                                            );
-  if ( $result ne 'ok' ) {
+  if ( $result !~ /^(ok|success)/i ) {
     #we already provisioned the DID, so...
     warn "Vitelity error enabling CNAM for ". $svc_phone->phonenum. ": $result";
+  } elsif ( $self->option('debug') ) {
+    warn "Vitelity response: $result";
   }
 
   ###
@@ -383,7 +387,13 @@ sub _export_insert {
 
   my $e911_error = $self->e911_send($svc_phone);
 
-  if ( $e911_error =~ /^(missingdata|invalid)/i ) {
+  if ( $e911_error =~ /status=(missingdata|invalid)/i ) {
+
+    my $status = $1;
+    if ( $e911_error =~ /error=(.*)/ ) {
+      $e911_error = "status=$status, error=$1";
+    }
+
     #but we already provisioned the DID, so:
     $self->vitelity_command('removedid', 'did'=> $svc_phone->phonenum,);
     #and check the results?  if it failed, then what?
@@ -394,12 +404,13 @@ sub _export_insert {
   '';
 }
 
-sub e911send {
+sub e911_send {
   my($self, $svc_phone) = (shift, shift);
 
   return '' if $self->option('disable_e911');
 
   my %location = $svc_phone->location_hash;
+  $location{'zip'} =~ s/\-\d{4}$//;
   my %e911send = (
     'did'     => $svc_phone->phonenum,
     'name'    => $svc_phone->phone_name_or_cust,
@@ -415,35 +426,42 @@ sub e911send {
 
   my $e911_result = $self->vitelity_command('e911send', %e911send);
 
-  return '' unless $result =~ /^(missingdata|invalid)/i;
+  unless ( $e911_result =~ /status=(missingdata|invalid)/i ) {
+    warn "Vitelity response: $e911_result" if $self->option('debug');
+    return '';
+  }
 
   return "Vitelity error provisioning E911 for". $svc_phone->phonenum.
-           ": $result";
+           ": $e911_result";
 }
 
 sub _export_replace {
   my( $self, $new, $old ) = (shift, shift, shift);
 
   # Call Forwarding
-  if( $old->forwarddst ne $new->forwarddst ) {
-      my $result = $self->vitelity_command('callfw',
-        'did'           => $old->phonenum,
-        'forward'        => $new->forwarddst ? $new->forwarddst : 'none',
-      );
-      if ( $result ne 'ok' ) {
-        return "Error running Vitelity callfw: $result";
-      }
+  if ( $old->forwarddst ne $new->forwarddst ) {
+    my $result = $self->vitelity_command('callfw',
+      'did'           => $old->phonenum,
+      'forward'        => $new->forwarddst ? $new->forwarddst : 'none',
+    );
+    if ( $result ne 'ok' ) {
+      return "Error running Vitelity callfw: $result";
+    } elsif ( $self->option('debug') ) {
+      warn "Vitelity response: $result";
+    }
   }
 
   # vfax forwarding emails
-  if( $old->email ne $new->email && $self->option('fax') ) {
-      my $result = $self->vitelity_command('changeemail',
-        'did'           => $old->phonenum,
-        'emails'        => $new->email ? $new->email : '',
-      );
-      if ( $result ne 'ok' ) {
-        return "Error running Vitelity changeemail: $result";
-      }
+  if ( $old->email ne $new->email && $self->option('fax') ) {
+    my $result = $self->vitelity_command('changeemail',
+      'did'           => $old->phonenum,
+      'emails'        => $new->email ? $new->email : '',
+    );
+    if ( $result ne 'ok' ) {
+      return "Error running Vitelity changeemail: $result";
+    } elsif ( $self->option('debug') ) {
+      warn "Vitelity response: $result";
+    }
   }
 
   $self->e911_send($new);
@@ -465,10 +483,10 @@ sub _export_delete {
 
   if ( $result ne 'success' ) {
     return "Error running Vitelity removedid: $result";
+  } elsif ( $self->option('debug') ) {
+    warn "Vitelity response: $result";
   }
 
-  return '' if $self->option('disable_e911');
-
   '';
 }
 
@@ -522,7 +540,7 @@ sub check_lnp {
     } elsif ( $result ne $svc_phone->lnp_reject_reason ) {
       $svc_phone->lnp_reject_reason($result);
       local($FS::svc_Common::noexport_hack) = 1;
-      $error = $svc_phone->replace;
+      my $error = $svc_phone->replace;
       #XXX log this using our internal log instead, so we can alert on it
       warn "ERROR setting lnp_reject_reason for DID ". $svc_phone->phonenum. ": $error" if $error;