X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fvitelity.pm;h=fe56ce247bb54b3f98d36a37ebe2bf562f472863;hb=0e17979577dacf0277de470ca7ee724f68a56cd5;hp=12c3a7fcef87a95c77dbda56dca8c3be1c1dafc1;hpb=fb4ab1073f0d15d660c6cdc4e07afebf68ef3924;p=freeside.git diff --git a/FS/FS/part_export/vitelity.pm b/FS/FS/part_export/vitelity.pm index 12c3a7fce..fe56ce247 100644 --- a/FS/FS/part_export/vitelity.pm +++ b/FS/FS/part_export/vitelity.pm @@ -1,32 +1,37 @@ package FS::part_export::vitelity; +use base qw( FS::part_export ); -use vars qw(@ISA %info); +use vars qw( %info ); use Tie::IxHash; -use FS::Record qw(qsearch dbh); -use FS::part_export; +use Geo::StreetAddress::US; +use FS::Record qw( qsearch dbh ); use FS::phone_avail; - -@ISA = qw(FS::part_export); +use FS::svc_phone; tie my %options, 'Tie::IxHash', - 'login' => { label=>'Vitelity API login' }, - 'pass' => { label=>'Vitelity API password' }, - 'dry_run' => { label=>"Test mode - don't actually provision" }, - 'routesip' => { label=>'routesip (optional sub-account)' }, - 'type' => { label=>'type (optional DID type to order)' }, - 'fax' => { label=>'vfax service', type=>'checkbox' }, - 'restrict_selection' => { type=>'select', - label=>'Restrict DID Selection', - options=>[ '', 'tollfree', 'non-tollfree' ], - } - + 'login' => { label=>'Vitelity API login' }, + 'pass' => { label=>'Vitelity API password' }, + 'routesip' => { label=>'routesip (optional sub-account)' }, + 'type' => { label=>'type (optional DID type to order)' }, + 'fax' => { label=>'vfax service', type=>'checkbox' }, + 'restrict_selection' => { type => 'select', + label => 'Restrict DID Selection', + options => [ '', 'tollfree', 'non-tollfree' ], + }, + 'dry_run' => { label => "Test mode - don't actually provision", + type => 'checkbox', + }, + 'disable_e911' => { label => "Disable E911 provisioning", + type => 'checkbox', + }, ; %info = ( - 'svc' => 'svc_phone', - 'desc' => 'Provision phone numbers to Vitelity', - 'options' => \%options, - 'notes' => <<'END' + 'svc' => 'svc_phone', + 'desc' => 'Provision phone numbers to Vitelity', + 'options' => \%options, + 'no_machine' => 1, + 'notes' => <<'END' Requires installation of Net::Vitelity from CPAN. @@ -38,6 +43,9 @@ END sub rebless { shift; } +sub can_get_dids { 1; } +sub get_dids_can_tollfree { 1; }; + sub get_dids { my $self = shift; my %opt = ref($_[0]) ? %{$_[0]} : @_; @@ -51,8 +59,8 @@ 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"; - push @ret, $did; + $did =~ /^(\d{3})(\d{3})(\d{4})/ or die "unparsable did $did\n"; + push @ret, $did; } my @sorted_ret = sort @ret; @@ -61,9 +69,9 @@ sub get_dids { } elsif ( $opt{'ratecenter'} && $opt{'state'} ) { my %flushopts = ( 'state' => $opt{'state'}, - 'ratecenter' => $opt{'ratecenter'}, - 'exportnum' => $self->exportnum - ); + 'ratecenter' => $opt{'ratecenter'}, + 'exportnum' => $self->exportnum + ); FS::phone_avail::flush( \%flushopts ); local $SIG{HUP} = 'IGNORE'; @@ -120,7 +128,7 @@ sub get_dids { 'hashref' => { 'exportnum' => $self->exportnum, 'countrycode' => '1', # vitelity is US/CA only now 'name' => $opt{'ratecenter'}, - 'state' => $opt{'state'}, + 'state' => $opt{'state'}, }, 'order_by' => 'ORDER BY npa, nxx, station', }) @@ -201,7 +209,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 did $did\n"; my($npa, $nxx, $station) = ($1, $2, $3); $npa{$npa}++; @@ -252,6 +260,22 @@ sub vitelity_command { $vitelity->$command(@args); } +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'), + 'apitype' => 'lnp', + #'debug' => $debug, + ); + + $vitelity->$command(@args); +} + sub _export_insert { my( $self, $svc_phone ) = (shift, shift); @@ -259,6 +283,51 @@ 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 %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' => $svc_phone->cust_svc->cust_pkg->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}. ' '. $street{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' => $svc_phone->cust_svc->cust_pkg->cust_main->daytime, + ); + + 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; + return $svc_phone->replace; + } else { + return "Error initiating Vitelity port: $result"; + } + + } + + ### + # 1. provision the DID + ### + my %vparams = ( 'did' => $svc_phone->phonenum ); $vparams{'routesip'} = $self->option('routesip') if defined $self->option('routesip'); @@ -271,9 +340,9 @@ sub _export_insert { # this is OK as Vitelity for now is US/CA only; it's not a hack $command = 'gettollfree' if $vparams{'did'} =~ /^800|^888|^877|^866|^855/; - if($self->option('fax')) { - $command = 'getdid'; - $success = 'ok'; + if ($self->option('fax')) { + $command = 'getdid'; + $success = 'ok'; } my $result = $self->vitelity_command($command,%vparams); @@ -282,35 +351,88 @@ sub _export_insert { return "Error running Vitelity $command: $result"; } + ### + # 2. Provision CNAM + ### + + my $cnam_result = $self->vitelity_command('cnamenable', + 'did'=>$svc_phone->phonenum, + ); + if ( $result ne 'ok' ) { + #we already provisioned the DID, so... + warn "Vitelity error enabling CNAM for ". $svc_phone->phonenum. ": $result"; + } + + ### + # 3. Provision E911 + ### + + my $e911_error = $self->e911_send($svc_phone); + + if ( $e911_error =~ /^(missingdata|invalid)/i ) { + #but we already provisioned the DID, so: + $self->vitelity_command('removedid', 'did'=> $svc_phone->phonenum,); + #and check the results? if it failed, then what? + + return $e911_error; + } + ''; } +sub e911send { + my($self, $svc_phone) = (shift, shift); + + return '' if $self->option('disable_e911'); + + 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 ( $location{address2} =~ /^\s*(\w+)\W*(\d+)\s*$/ ) { + $e911send{'unittype'} = $1; + $e911send{'unitnumber'} = $2; + } + + my $e911_result = $self->vitelity_command('e911send', %e911send); + + return '' unless $result =~ /^(missingdata|invalid)/i; + + return "Vitelity error provisioning E911 for". $svc_phone->phonenum. + ": $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', + 'did' => $old->phonenum, + 'forward' => $new->forwarddst ? $new->forwarddst : 'none', ); if ( $result ne 'ok' ) { - return "Error running Vitelity callfw: $result"; + return "Error running Vitelity callfw: $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 : '', + 'did' => $old->phonenum, + 'emails' => $new->email ? $new->email : '', ); if ( $result ne 'ok' ) { - return "Error running Vitelity changeemail: $result"; + return "Error running Vitelity changeemail: $result"; } } - ''; + $self->e911_send($new); } sub _export_delete { @@ -331,6 +453,8 @@ sub _export_delete { return "Error running Vitelity removedid: $result"; } + return '' if $self->option('disable_e911'); + ''; } @@ -346,5 +470,43 @@ sub _export_unsuspend { ''; } +sub check_lnp { + my $self = shift; + + my $in_svcpart = 'IN ('. join( ',', map $_->svcpart, $self->export_svc). ')'; + + foreach my $svc_phone ( + qsearch({ 'table' => 'svc_phone', + 'hashref' => {lnp_status=>'portingin'}, + 'extra_sql' => "AND svcpart $in_svcpart", + }) + ) { + + my $result = $self->vitelity_lnp_command('checkstatus', + 'portid'=>$svc_phone->lnp_portid, + ); + + #XXX what $result values mean the port is done? + + if ( $result =~ /^complete$/ ) { #"complete"? nfi + + $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 { + $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; + } + + } + + } + +} + 1;