X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fvitelity.pm;h=4dd9caa5eb8fbbf0a0b056501b8a106ddf1b9e39;hb=575dbfc4c5acb1dd2c04e17fd045351b240db218;hp=51731260ecd6800767e86115ef727d0357695894;hpb=492d9aec5230e9c562a7d1a78f4f24d7a27aceb8;p=freeside.git diff --git a/FS/FS/part_export/vitelity.pm b/FS/FS/part_export/vitelity.pm index 51731260e..4dd9caa5e 100644 --- a/FS/FS/part_export/vitelity.pm +++ b/FS/FS/part_export/vitelity.pm @@ -1,10 +1,15 @@ package FS::part_export::vitelity; use base qw( FS::part_export ); +use strict; use vars qw( %info ); use Tie::IxHash; +use Data::Dumper; +use Geo::StreetAddress::US; +use Net::Vitelity 0.05; use FS::Record qw( qsearch dbh ); use FS::phone_avail; +use FS::svc_phone; tie my %options, 'Tie::IxHash', 'login' => { label=>'Vitelity API login' }, @@ -22,6 +27,10 @@ tie my %options, 'Tie::IxHash', 'disable_e911' => { label => "Disable E911 provisioning", type => 'checkbox', }, + 'debug' => { label => 'Enable debugging', + type => 'checkbox', + value => 1, + }, ; %info = ( @@ -30,10 +39,6 @@ tie my %options, 'Tie::IxHash', 'options' => \%options, 'no_machine' => 1, 'notes' => <<'END' -Requires installation of -Net::Vitelity -from CPAN. -

routesip - optional Vitelity sub-account to which newly ordered DIDs will be routed
type - optional DID type (perminute, unlimited, or your-pri) END @@ -43,6 +48,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; @@ -57,7 +63,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; } @@ -97,7 +103,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 { @@ -207,7 +213,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}++; @@ -245,14 +251,24 @@ 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'), + 'apitype' => $self->option('fax') ? 'fax' : 'api', + 'debug' => $self->option('debug'), + ); + + $vitelity->$command(@args); +} + +sub vitelity_lnp_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' => 'lnp', + 'debug' => $self->option('debug'), ); $vitelity->$command(@args); @@ -265,6 +281,63 @@ sub _export_insert { #we want to provision and catch errors now, not queue + #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'} ); + + my $result = $self->vitelity_lnp_command('addport', + 'portnumber' => $svc_phone->phonenum, + 'partial' => 'no', + 'wireless' => 'no', + 'carrier' => $svc_phone->lnp_other_provider, + 'company' => $cust_main->company, + 'accnumber' => $svc_phone->lnp_other_provider_account, + 'name' => $svc_phone->phone_name_or_cust, + 'streetnumber' => $sa->{number}, + 'streetprefix' => $sa->{prefix}, + 'streetname' => $sa->{street}. ' '. $sa->{type}, + 'streetsuffix' => $sa->{suffix}, + 'unit' => ( $sa->{sec_unit_num} + ? $sa->{sec_unit_type}. ' '. $sa->{sec_unit_num} + : '' + ), + 'city' => $location{'city'}, + 'state' => $location{'state'}, + 'zip' => $location{'zip'}, + 'billnumber' => $svc_phone->phonenum, #?? do we need a new field for this? + 'contactnumber' => $cust_main->daytime, + ); + warn "Vitelity response: $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"; + } + + } + ### # 1. provision the DID ### @@ -290,6 +363,8 @@ sub _export_insert { if ( $result ne $success ) { return "Error running Vitelity $command: $result"; + } elsif ( $self->option('debug') ) { + warn "Vitelity response: $result"; } ### @@ -302,6 +377,8 @@ sub _export_insert { if ( $result ne 'ok' ) { #we already provisioned the DID, so... warn "Vitelity error enabling CNAM for ". $svc_phone->phonenum. ": $result"; + } elsif ( $self->option('debug') ) { + warn "Vitelity response: $result"; } ### @@ -321,7 +398,7 @@ sub _export_insert { ''; } -sub e911send { +sub e911_send { my($self, $svc_phone) = (shift, shift); return '' if $self->option('disable_e911'); @@ -329,18 +406,12 @@ sub e911send { my %location = $svc_phone->location_hash; my %e911send = ( 'did' => $svc_phone->phonenum, + 'name' => $svc_phone->phone_name_or_cust, 'address' => $location{'address1'}, 'city' => $location{'city'}, 'state' => $location{'state'}, 'zip' => $location{'zip'}, ); - if ( $svc_phone->phone_name ) { - $e911send{'name'} = $svc_phone->phone_name; - } else { - my $cust_main = $svc_phone->cust_svc->cust_pkg->cust_main; - $e911send{'name'} = $cust_main->company || $cust_main->first. ' '. - $cust_main->get('last'); - } if ( $location{address2} =~ /^\s*(\w+)\W*(\d+)\s*$/ ) { $e911send{'unittype'} = $1; $e911send{'unitnumber'} = $2; @@ -348,35 +419,42 @@ sub e911send { my $e911_result = $self->vitelity_command('e911send', %e911send); - return '' unless $result =~ /^(missingdata|invalid)/i; + unless ( $e911_result =~ /^(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); @@ -398,10 +476,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'); - ''; } @@ -417,5 +495,53 @@ sub _export_unsuspend { ''; } +sub check_lnp { + my $self = shift; + + 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", + }) + ) { + + my $result = $self->vitelity_lnp_command('checkstatus', + 'portid'=>$svc_phone->lnp_portid, + ); + + if ( $result =~ /^Complete/i ) { + + $svc_phone->lnp_status('portedin'); + my $error = $self->_export_insert($svc_phone); + if ( $error ) { + #XXX log this using our internal log instead, so we can alert on it + # 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; + } + + } elsif ( $result ne $svc_phone->lnp_reject_reason ) { + $svc_phone->lnp_reject_reason($result); + local($FS::svc_Common::noexport_hack) = 1; + 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; + + } + + } + +} + 1;