1 package FS::part_export::dashcs_e911;
4 use vars qw(@ISA %info $me $DEBUG);
9 $me = '['.__PACKAGE__.']';
11 @ISA = qw(FS::part_export);
13 tie my %options, 'Tie::IxHash',
14 'username' => { label=>'Dash username', },
15 '_password' => { label=>'Dash password', },
16 'staging' => { label=>'Staging (test mode)', type=>'checkbox', },
21 'desc' => 'Provision e911 services via Dash Carrier Services',
22 'notes' => 'Provision e911 services via Dash Carrier Services',
23 'options' => \%options,
26 sub rebless { shift; }
29 my($self, $svc_phone) = (shift, shift);
30 return 'invalid phonenum' unless $svc_phone->phonenum;
32 my $opts = { map{ $_ => $self->option($_) } keys %options };
33 $opts->{wantreturn} = 1;
35 my %location_hash = $svc_phone->location_hash;
37 'address1' => $location_hash{address1},
38 'address2' => $location_hash{address2},
39 'community' => $location_hash{city},
40 'state' => $location_hash{state},
41 'postalcode' => $location_hash{zip},
45 dash_command($opts, 'validateLocation', { 'location' => $location } );
46 return $error_or_ref unless ref($error_or_ref);
48 my $status = $error_or_ref->get_Location->get_status; # hate
49 return $status->get_description unless $status->get_code eq 'GEOCODED';
51 my $cust_pkg = $svc_phone->cust_svc->cust_pkg;
52 my $cust_main = $cust_pkg->cust_main if $cust_pkg;
53 my $caller_name = $cust_main ? $cust_main->name_short : 'unknown';
57 'uri' => 'tel:'. $svc_phone->countrycode. $svc_phone->phonenum,
58 'callername' => $caller_name,
60 'location' => $location,
63 $error_or_ref = dash_command($opts, 'addLocation', $arg );
64 return $error_or_ref unless ref($error_or_ref);
66 my $id = $error_or_ref->get_Location->get_locationid;
67 $self->_export_command('provisionLocation', { 'locationid' => $id });
71 my($self, $svc_phone) = (shift, shift);
72 return '' unless $svc_phone->phonenum;
74 my $arg = { 'uri' => 'tel:'. $svc_phone->countrycode. $svc_phone->phonenum };
75 $self->_export_queue('removeURI', $arg);
83 sub _export_unsuspend {
91 my $opts = { map{ $_ => $self->option($_) } keys %options };
93 dash_command($opts, @_);
98 my($self, $new, $old ) = (shift, shift, shift);
100 # this could succeed in unprovision but fail to provision
101 my $arg = { 'uri' => 'tel:'. $old->countrycode. $old->phonenum };
102 $self->_export_command('removeURI', $arg) || $self->_export_insert($new);
105 #a good idea to queue anything that could fail or take any time
109 my $opts = { map{ $_ => $self->option($_) } keys %options };
111 my $queue = new FS::queue {
112 'job' => "FS::part_export::dashcs_e911::dash_command",
114 $queue->insert( $opts, @_ );
118 my ( $opt, $method, $arg ) = (shift, shift, shift);
120 warn "$me: dash_command called with method $method\n" if $DEBUG;
123 Net::DashCS::Interfaces::EmergencyProvisioningService::EmergencyProvisioningPort
127 foreach my $module ( @module ) {
132 local *SOAP::Transport::HTTP::Client::get_basic_credentials = sub {
133 return ($opt->{'username'}, $opt->{'_password'});
136 my $service = new Net::DashCS::Interfaces::EmergencyProvisioningService::EmergencyProvisioningPort(
137 { deserializer_args => { strict => 0 } }
140 $service->set_proxy('https://staging-service.dashcs.com/dash-api/soap/emergencyprovisioning/v1')
141 if $opt->{'staging'};
143 my $result = $service->$method($arg);
146 warn "returning fault: ". $result->get_faultstring if $DEBUG;
147 return ''.$result->get_faultstring;
150 warn "returning ok: $result\n" if $DEBUG;
151 return $result if $opt->{wantreturn};