better vitelity error messages, just depend on Net::Vitelity, RT#75901
[freeside.git] / FS / FS / part_export / vitelity.pm
index fe56ce2..8d802b1 100644 (file)
@@ -4,6 +4,7 @@ use base qw( FS::part_export );
 use vars qw( %info );
 use Tie::IxHash;
 use Geo::StreetAddress::US;
+use Net::Vitelity;
 use FS::Record qw( qsearch dbh );
 use FS::phone_avail;
 use FS::svc_phone;
@@ -32,10 +33,6 @@ tie my %options, 'Tie::IxHash',
   'options'    => \%options,
   'no_machine' => 1,
   'notes'      => <<'END'
-Requires installation of
-<a href="http://search.cpan.org/dist/Net-Vitelity">Net::Vitelity</a>
-from CPAN.
-<br><br>
 routesip - optional Vitelity sub-account to which newly ordered DIDs will be routed
 <br>type - optional DID type (perminute, unlimited, or your-pri)
 END
@@ -45,6 +42,7 @@ sub rebless { shift; }
 
 sub can_get_dids { 1; }
 sub get_dids_can_tollfree { 1; };
+sub can_lnp { 1; }
 
 sub get_dids {
   my $self = shift;
@@ -59,7 +57,7 @@ sub get_dids {
     return [] if ( $tollfree[0] eq 'noneavailable' || $tollfree[0] eq 'none');
 
     foreach my $did ( @tollfree ) {
-        $did =~ /^(\d{3})(\d{3})(\d{4})/ or die "unparsable did $did\n";
+        $did =~ /^(\d{3})(\d{3})(\d{4})/ or die "unparsable toll-free did $did\n";
         push @ret, $did;
     }
 
@@ -99,7 +97,7 @@ sub get_dids {
     die "missingdata error running Vitelity API" if $dids[0] eq 'missingdata';
 
     foreach my $did ( @dids ) {
-      $did =~ /^(\d{3})(\d{3})(\d{4})/ or die "unparsable did $did\n";
+      $did =~ /^(\d{3})(\d{3})(\d{4})/ or die "unparsable (state and ratecenter) did $did\n";
       my($npa, $nxx, $station) = ($1, $2, $3);
 
       my $phone_avail = new FS::phone_avail {
@@ -209,7 +207,7 @@ sub get_dids {
       }
 
       foreach my $did ( @dids ) {
-        $did =~ /^(\d{3})(\d{3})(\d{4})/ or die "unparsable did $did\n";
+        $did =~ /^(\d{3})(\d{3})(\d{4})/ or die "unparsable (state) did $did\n";
         my($npa, $nxx, $station) = ($1, $2, $3);
         $npa{$npa}++;
 
@@ -247,9 +245,6 @@ sub get_dids {
 sub vitelity_command {
   my( $self, $command, @args ) = @_;
 
-  eval "use Net::Vitelity;";
-  die $@ if $@;
-
   my $vitelity = Net::Vitelity->new(
     'login' => $self->option('login'),
     'pass'  => $self->option('pass'),
@@ -263,9 +258,6 @@ sub vitelity_command {
 sub vitelity_lnp_command {
   my( $self, $command, @args ) = @_;
 
-  eval "use Net::Vitelity 0.04;";
-  die $@ if $@;
-
   my $vitelity = Net::Vitelity->new(
     'login'   => $self->option('login'),
     'pass'    => $self->option('pass'),
@@ -473,10 +465,14 @@ sub _export_unsuspend {
 sub check_lnp {
   my $self = shift;
 
-  my $in_svcpart = 'IN ('. join( ',', map $_->svcpart, $self->export_svc). ')';
+  my @export_svc = $self->export_svc;
+  return unless @export_svc;
+
+  my $in_svcpart = 'IN ('. join( ',', map $_->svcpart, @export_svc). ')';
 
   foreach my $svc_phone (
     qsearch({ 'table'     => 'svc_phone',
+              'addl_from' => 'LEFT JOIN cust_svc USING (svcnum)',
               'hashref'   => {lnp_status=>'portingin'},
               'extra_sql' => "AND svcpart $in_svcpart",
            })
@@ -486,9 +482,7 @@ sub check_lnp {
                                                'portid'=>$svc_phone->lnp_portid,
                                             );
 
-    #XXX what $result values mean the port is done?
-
-    if ( $result =~ /^complete$/ ) { #"complete"?  nfi
+    if ( $result =~ /^Complete/i ) {
 
       $svc_phone->lnp_status('portedin');
       my $error = $self->_export_insert($svc_phone);
@@ -502,6 +496,12 @@ sub check_lnp {
         warn "ERROR setting lnp_status for DID ". $svc_phone->phonenum. ": $error" if $error;
       }
 
+    } elsif ( $result ne $svc_phone->lnp_reject_reason ) {
+      $svc_phone->lnp_reject_reason($result);
+      $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;
+
     }
 
   }