freeside v3 separate export for e911-only provisioning to voip innovations api 2...
[freeside.git] / FS / FS / part_export / voip_innovations2_e911.pm
1 package FS::part_export::voip_innovations2_e911;
2
3 use vars qw(@ISA %info);
4 use Tie::IxHash;
5 use FS::Record qw(qsearch dbh);
6 use FS::part_export;
7 use FS::phone_avail;
8 use Data::Dumper;
9
10 @ISA = qw(FS::part_export);
11
12 tie my %options, 'Tie::IxHash',
13   'login'         => { label=>'VoIP Innovations API login' },
14   'password'      => { label=>'VoIP Innovations API password' },
15   'endpointgroup' => { label=>'VoIP Innovations endpoint group number' },
16   'dry_run'       => { label=>"Test mode - don't actually provision",
17                        type=>'checkbox',
18                      },
19 ;
20
21 %info = (
22   'svc'     => 'svc_phone',
23   'desc'    => 'Provision E911 only to VoIP Innovations (API 2.0)',
24   'options' => \%options,
25   'no_machine' => 1,
26   'notes'   => <<'END'
27 Requires installation of
28 <a href="http://search.cpan.org/dist/Net-VoIP_Innovations">Net::VoIP_Innovations</a>
29 from CPAN.
30 END
31 );
32
33 sub rebless { shift; }
34
35 sub gp_command {
36   my( $self, $command, @args ) = @_;
37
38   eval "use Net::VoIP_Innovations 2.00;";
39   if ( $@ ) {
40     warn $@;
41     die $@;
42   }
43
44   my $gp = Net::VoIP_Innovations->new(
45     'login'    => $self->option('login'),
46     'password' => $self->option('password'),
47     #'debug'    => $debug,
48   );
49
50   $gp->$command(@args);
51 }
52
53
54 sub _export_insert {
55   my( $self, $svc_phone ) = (shift, shift);
56
57   return '' if $self->option('dry_run');
58
59   #we want to provision and catch errors now, not queue
60
61   ###
62   # 911Insert
63   ###
64
65   my %location_hash = $svc_phone->location_hash;
66   my( $zip, $plus4 ) = split('-', $location_hash->{zip});
67   my $e = $self->gp_command('911Insert',
68     'did'        => $svc_phone->phonenum,
69     'Address1'   => $location_hash{address1},
70     'Address2'   => $location_hash{address2},
71     'City'       => $location_hash{city},
72     'State'      => $location_hash{state},
73     'ZipCode'    => $zip,
74     'PlusFour'   => $plus4,
75     'CallerName' =>
76       $svc_phone->phone_name
77         || $svc_phone->cust_svc->cust_pkg->cust_main->contact_firstlast,
78   );
79
80   my $edid = $e->{did};
81
82   if ( $edid->{'statuscode'} != 100 ) {
83     return "Error running VoIP Innovations 911Insert: ".
84            $edid->{'statuscode'}. ': '. $edid->{'status'};
85   }
86
87   '';
88 }
89
90 sub _export_replace {
91   my( $self, $new, $old ) = (shift, shift, shift);
92
93   #hmm, anything to change besides E911 data?
94
95   ###
96   # 911Update
97   ###
98
99   my %location_hash = $svc_phone->location_hash;
100   my( $zip, $plus4 ) = split('-', $location_hash->{zip});
101   my $e = $self->gp_command('911Update',
102     'did'        => $svc_phone->phonenum,
103     'Address1'   => $location_hash{address1},
104     'Address2'   => $location_hash{address2},
105     'City'       => $location_hash{city},
106     'State'      => $location_hash{state},
107     'ZipCode'    => $zip,
108     'PlusFour'   => $plus4,
109     'CallerName' =>
110       $svc_phone->phone_name
111         || $svc_phone->cust_svc->cust_pkg->cust_main->contact_firstlast,
112   );
113
114   my $edid = $e->{did};
115
116   if ( $edid->{'statuscode'} != 100 ) {
117     return "Error running VoIP Innovations 911Update: ".
118            $edid->{'statuscode'}. ': '. $edid->{'status'};
119   }
120
121   '';
122 }
123
124 sub _export_delete {
125   my( $self, $svc_phone ) = (shift, shift);
126
127   return '' if $self->option('dry_run');
128
129   #XXX delete e911 information
130
131   '';
132 }
133
134 sub _export_suspend {
135   my( $self, $svc_phone ) = (shift, shift);
136   #nop for now
137   '';
138 }
139
140 sub _export_unsuspend {
141   my( $self, $svc_phone ) = (shift, shift);
142   #nop for now
143   '';
144 }
145
146 1;
147