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',
24 'options' => \%options,
27 sub rebless { shift; }
30 my($self, $svc_phone) = (shift, shift);
31 return 'invalid phonenum' unless $svc_phone->phonenum;
33 my $opts = { map{ $_ => $self->option($_) } keys %options };
34 $opts->{wantreturn} = 1;
36 my %location_hash = $svc_phone->location_hash;
38 'address1' => $location_hash{address1},
39 'address2' => $location_hash{address2},
40 'community' => $location_hash{city},
41 'state' => $location_hash{state},
42 'postalcode' => $location_hash{zip},
46 dash_command($opts, 'validateLocation', { 'location' => $location } );
47 return $error_or_ref unless ref($error_or_ref);
49 my $status = $error_or_ref->get_Location->get_status; # hate
50 return $status->get_description unless $status->get_code eq 'GEOCODED';
52 my $cust_pkg = $svc_phone->cust_svc->cust_pkg;
53 my $cust_main = $cust_pkg->cust_main if $cust_pkg;
54 my $caller_name = $cust_main ? $cust_main->name_short : 'unknown';
58 'uri' => 'tel:'. $svc_phone->countrycode. $svc_phone->phonenum,
59 'callername' => $caller_name,
61 'location' => $location,
64 $error_or_ref = dash_command($opts, 'addLocation', $arg );
65 return $error_or_ref unless ref($error_or_ref);
67 my $id = $error_or_ref->get_Location->get_locationid;
68 $self->_export_command('provisionLocation', { 'locationid' => $id });
72 my($self, $svc_phone) = (shift, shift);
73 return '' unless $svc_phone->phonenum;
75 my $arg = { 'uri' => 'tel:'. $svc_phone->countrycode. $svc_phone->phonenum };
76 $self->_export_queue('removeURI', $arg);
84 sub _export_unsuspend {
92 my $opts = { map{ $_ => $self->option($_) } keys %options };
94 dash_command($opts, @_);
99 my($self, $new, $old ) = (shift, shift, shift);
101 # this could succeed in unprovision but fail to provision
102 my $arg = { 'uri' => 'tel:'. $old->countrycode. $old->phonenum };
103 $self->_export_command('removeURI', $arg) || $self->_export_insert($new);
106 #a good idea to queue anything that could fail or take any time
110 my $opts = { map{ $_ => $self->option($_) } keys %options };
112 my $queue = new FS::queue {
113 'job' => "FS::part_export::dashcs_e911::dash_command",
115 $queue->insert( $opts, @_ );
119 my ( $opt, $method, $arg ) = (shift, shift, shift);
121 warn "$me: dash_command called with method $method\n" if $DEBUG;
124 Net::DashCS::Interfaces::EmergencyProvisioningService::EmergencyProvisioningPort
128 foreach my $module ( @module ) {
133 local *SOAP::Transport::HTTP::Client::get_basic_credentials = sub {
134 return ($opt->{'username'}, $opt->{'_password'});
137 my $service = new Net::DashCS::Interfaces::EmergencyProvisioningService::EmergencyProvisioningPort(
138 { deserializer_args => { strict => 0 } }
141 $service->set_proxy('https://staging-service.dashcs.com/dash-api/soap/emergencyprovisioning/v1')
142 if $opt->{'staging'};
144 my $result = $service->$method($arg);
147 warn "returning fault: ". $result->get_faultstring if $DEBUG;
148 return ''.$result->get_faultstring;
151 warn "returning ok: $result\n" if $DEBUG;
152 return $result if $opt->{wantreturn};