1 package FS::part_export::northern_911;
4 use vars qw(@ISA %info);
6 use FS::Record qw(qsearch dbh);
7 use base 'FS::part_export';
10 tie my %options, 'Tie::IxHash',
11 'vendor_code' => { label=>'Northern 911 vendor code' },
12 'password' => { label=>'API passcode' },
13 'test_mode' => { label=>'Test mode',
15 'debug' => { label=>'Enable debugging',
21 'desc' => 'Provision E911 to Northern 911',
22 'options' => \%options,
25 Requires installation of
26 <a href="http://search.cpan.org/dist/WebService-Northern911">WebService::Northern911</a>
34 if (!$self->get('client')) {
36 eval "use WebService::Northern911";
37 return "error loading WebService::Northern911 ($@)" if $@;
39 WebService::Northern911->new(
40 vendor_code => $self->option('vendor_code'),
41 password => $self->option('password'),
42 live => ( $self->option('test_mode') ? 0 : 1),
47 return $self->get('client');
51 my( $self, $svc_phone ) = (shift, shift);
53 my %location_hash = $svc_phone->location_hash;
54 $location_hash{address1} =~ /^(\w+) +(.*)$/;
57 'PHONE_NUMBER' => $svc_phone->phonenum,
58 'STREET_NUMBER' => $1,
60 'CITY' => $location_hash{city},
61 'PROVINCE_STATE' => $location_hash{state},
62 'POSTAL_CODE_ZIP' => $location_hash{zip},
63 'OTHER_ADDRESS_INFO' => $location_hash{address2},
65 my $phone_name = $svc_phone->phone_name;
67 # could be a personal name or a business...
68 if ( $svc_phone->e911_class and
69 grep { $_ eq $svc_phone->e911_class }
70 ( 2, 4, 5, 6, 7, 0, 'A', 'D', 'E', 'K')
73 # one of the "Business" classes, Centrex, a payphone, or
74 # VoIP Enterprise class
75 $customer{'LAST_NAME'} = $phone_name;
77 # assume residential, and try (inaccurately) to make a first/last
79 @customer{'FIRST_NAME', 'LAST_NAME'} = split(' ', $phone_name, 2);
82 my $cust_main = $svc_phone->cust_svc->cust_pkg->cust_main;
83 if ($cust_main->company) {
84 $customer{'LAST_NAME'} = $cust_main->company;
86 $customer{'LAST_NAME'} = $cust_main->last;
87 $customer{'FIRST_NAME'} = $cust_main->first;
91 if ($self->option('debug')) {
92 warn "\nAddorUpdateCustomer:\n".Dumper(\%customer)."\n\n";
94 my $response = $self->client->AddorUpdateCustomer(%customer);
95 if (!$response->is_success) {
96 return $response->error_message;
102 my( $self, $new, $old ) = (shift, shift, shift);
104 # except when changing the phone number, exactly like export_insert;
105 if ($new->phonenum ne $old->phonenum) {
106 my $error = $self->export_delete($old);
107 return $error if $error;
109 $self->export_insert($new);
113 my ($self, $svc_phone) = (shift, shift);
115 if ($self->option('debug')) {
116 warn "\nDeleteCustomer:\n".$svc_phone->phonenum."\n\n";
118 my $response = $self->client->DeleteCustomer($svc_phone->phonenum);
119 if (!$response->is_success) {
120 return $response->error_message;
125 # export_suspend and _unsuspend do nothing
127 sub export_relocate {
128 my ($self, $svc_phone) = (shift, shift);
129 $self->export_insert($svc_phone);