add e911 to vitelity integration, RT#73618, RT#76262
[freeside.git] / FS / FS / part_export / vitelity.pm
index 8d802b1..e53f7b7 100644 (file)
@@ -3,8 +3,9 @@ use base qw( FS::part_export );
 
 use vars qw( %info );
 use Tie::IxHash;
+use Data::Dumper;
 use Geo::StreetAddress::US;
-use Net::Vitelity;
+use Net::Vitelity 0.05;
 use FS::Record qw( qsearch dbh );
 use FS::phone_avail;
 use FS::svc_phone;
@@ -25,6 +26,10 @@ tie my %options, 'Tie::IxHash',
   'disable_e911'       => { label => "Disable E911 provisioning",
                             type  => 'checkbox',
                           },
+  'debug'              => { label  => 'Enable debugging',
+                             type  => 'checkbox',
+                             value => 1,
+                          },
 ;
 
 %info = (
@@ -246,10 +251,10 @@ sub vitelity_command {
   my( $self, $command, @args ) = @_;
 
   my $vitelity = Net::Vitelity->new(
-    'login' => $self->option('login'),
-    'pass'  => $self->option('pass'),
-    'apitype' => $self->option('fax') ? 'fax' : 'api',
-    #'debug'    => $debug,
+    'login'    => $self->option('login'),
+    'pass'     => $self->option('pass'),
+    'apitype'  => $self->option('fax') ? 'fax' : 'api',
+    'debug'    => $self->option('debug'),
   );
 
   $vitelity->$command(@args);
@@ -259,10 +264,10 @@ sub vitelity_lnp_command {
   my( $self, $command, @args ) = @_;
 
   my $vitelity = Net::Vitelity->new(
-    'login'   => $self->option('login'),
-    'pass'    => $self->option('pass'),
-    'apitype' => 'lnp',
-    #'debug'   => $debug,
+    'login'    => $self->option('login'),
+    'pass'     => $self->option('pass'),
+    'apitype'  => 'lnp',
+    'debug'    => $self->option('debug'),
   );
 
   $vitelity->$command(@args);
@@ -278,6 +283,20 @@ sub _export_insert {
   #porting a number in?  different code path
   if ( $svc_phone->lnp_status eq 'portingin' ) {
 
+    my $cust_main = $svc_phone->cust_svc->cust_pkg->cust_main;
+
+    return 'Customer company is required'
+      unless $cust_main->company;
+
+    return 'Customer day phone (for contact, not porting) is required'
+      unless $cust_main->daytime;
+
+    return 'LNP Other Provider is required'
+      unless $svc_phone->lnp_other_provider;
+
+    return 'LNP Other Provider Account # is required'
+      unless $svc_phone->lnp_other_provider_account;
+
     my %location = $svc_phone->location_hash;
     my $sa = Geo::StreetAddress::US->parse_location( $location{'address1'} );
 
@@ -286,7 +305,7 @@ sub _export_insert {
       'partial'       => 'no',
       'wireless'      => 'no',
       'carrier'       => $svc_phone->lnp_other_provider,
-      'company'       => $svc_phone->cust_svc->cust_pkg->cust_main->company,
+      'company'       => $cust_main->company,
       'accnumber'     => $svc_phone->lnp_other_provider_account,
       'name'          => $svc_phone->phone_name_or_cust,
       'streetnumber'  => $sa->{number},
@@ -301,14 +320,17 @@ sub _export_insert {
       'state'         => $location{'state'},
       'zip'           => $location{'zip'},
       'billnumber'    => $svc_phone->phonenum, #?? do we need a new field for this?
-      'contactnumber' => $svc_phone->cust_svc->cust_pkg->cust_main->daytime,
+      'contactnumber' => $cust_main->daytime,
     );
 
+    warn "Vitelity reponse: $result" if $self->option('debug');
+
     if ( $result =~ /^ok:/i ) {
       my($ok, $portid, $sig, $bill) = split(':', $result);
       $svc_phone->lnp_portid($portid);
       $svc_phone->lnp_signature('Y') if $sig  =~ /y/i;
       $svc_phone->lnp_bill('Y')      if $bill =~ /y/i;
+      local($FS::svc_Common::noexport_hack) = 1;
       return $svc_phone->replace;
     } else {
       return "Error initiating Vitelity port: $result";
@@ -372,7 +394,7 @@ sub _export_insert {
   '';
 }
 
-sub e911send {
+sub e911_send {
   my($self, $svc_phone) = (shift, shift);
 
   return '' if $self->option('disable_e911');
@@ -491,6 +513,7 @@ sub check_lnp {
         # properly
         warn "ERROR provisioning ported-in DID ". $svc_phone->phonenum. ": $error";
       } else {
+        local($FS::svc_Common::noexport_hack) = 1;
         $error = $svc_phone->replace; #to set the lnp_status
         #XXX log this using our internal log instead, so we can alert on it
         warn "ERROR setting lnp_status for DID ". $svc_phone->phonenum. ": $error" if $error;
@@ -498,6 +521,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;
       #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;