1 package FS::part_export::northern_911;
2 use base 'FS::part_export';
5 use vars qw(@ISA %info);
7 use FS::Record qw(qsearch dbh);
8 use WebService::Northern911;
11 tie my %options, 'Tie::IxHash',
12 'vendor_code' => { label=>'Northern 911 vendor code' },
13 'password' => { label=>'API passcode' },
14 'test_mode' => { label=>'Test mode',
16 'debug' => { label=>'Enable debugging',
22 'desc' => 'Provision E911 to Northern 911',
23 'options' => \%options,
32 if (!$self->get('client')) {
34 WebService::Northern911->new(
35 vendor_code => $self->option('vendor_code'),
36 password => $self->option('password'),
37 live => ( $self->option('test_mode') ? 0 : 1),
42 return $self->get('client');
46 my( $self, $svc_phone ) = (shift, shift);
48 my %location_hash = $svc_phone->location_hash;
49 $location_hash{address1} =~ /^(\w+) +(.*)$/;
52 'PHONE_NUMBER' => $svc_phone->phonenum,
53 'STREET_NUMBER' => $1,
55 'CITY' => $location_hash{city},
56 'PROVINCE_STATE' => $location_hash{state},
57 'POSTAL_CODE_ZIP' => $location_hash{zip},
58 'OTHER_ADDRESS_INFO' => $location_hash{address2},
60 my $phone_name = $svc_phone->phone_name;
62 # could be a personal name or a business...
63 if ( $svc_phone->e911_class and
64 grep { $_ eq $svc_phone->e911_class }
65 ( 2, 4, 5, 6, 7, 0, 'A', 'D', 'E', 'K')
68 # one of the "Business" classes, Centrex, a payphone, or
69 # VoIP Enterprise class
70 $customer{'LAST_NAME'} = $phone_name;
72 # assume residential, and try (inaccurately) to make a first/last
74 @customer{'FIRST_NAME', 'LAST_NAME'} = split(' ', $phone_name, 2);
77 my $cust_main = $svc_phone->cust_svc->cust_pkg->cust_main;
78 if ($cust_main->company) {
79 $customer{'LAST_NAME'} = $cust_main->company;
81 $customer{'LAST_NAME'} = $cust_main->last;
82 $customer{'FIRST_NAME'} = $cust_main->first;
86 if ($self->option('debug')) {
87 warn "\nAddorUpdateCustomer:\n".Dumper(\%customer)."\n\n";
89 my $response = $self->client->AddorUpdateCustomer(%customer);
90 if (!$response->is_success) {
91 return $response->error_message;
97 my( $self, $new, $old ) = (shift, shift, shift);
99 # except when changing the phone number, exactly like export_insert;
100 if ($new->phonenum ne $old->phonenum) {
101 my $error = $self->export_delete($old);
102 return $error if $error;
104 $self->export_insert($new);
108 my ($self, $svc_phone) = (shift, shift);
110 if ($self->option('debug')) {
111 warn "\nDeleteCustomer:\n".$svc_phone->phonenum."\n\n";
113 my $response = $self->client->DeleteCustomer($svc_phone->phonenum);
114 if (!$response->is_success) {
115 return $response->error_message;
120 # export_suspend and _unsuspend do nothing
122 sub export_relocate {
123 my ($self, $svc_phone) = (shift, shift);
124 $self->export_insert($svc_phone);