1 package FS::part_export::voip_innovations3;
3 use vars qw(@ISA %info);
5 use FS::Record qw(qsearch dbh);
10 @ISA = qw(FS::part_export);
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 'e911' => { label=>'Provision E911 data',
19 'no_did_provision' => { label=>'Disable DID provisioning',
22 'dry_run' => { label=>"Test mode - don't actually provision",
29 'desc' => 'Provision phone numbers / E911 to VoIP Innovations (API 3.0)',
30 'options' => \%options,
33 Requires installation of
34 <a href="http://search.cpan.org/dist/Net-VoIP_Innovations">Net::VoIP_Innovations</a>
39 sub rebless { shift; }
41 sub can_get_dids { 0; } #with API 3.0? not yet
44 my( $self, $command, @args ) = @_;
46 eval "use Net::VoIP_Innovations 3.00;";
52 my $gp = Net::VoIP_Innovations->new(
53 'login' => $self->option('login'),
54 'password' => $self->option('password'),
63 my( $self, $svc_phone ) = (shift, shift);
65 return '' if $self->option('dry_run');
67 #we want to provision and catch errors now, not queue
69 unless ( $self->option('no_provision_did') ) {
75 my $r = $self->vi_command('reserveDID',
76 'did' => $svc_phone->phonenum,
78 'endpointgroup' => $self->option('endpointgroup'),
83 if ( $rdid->{'statuscode'} != 100 ) {
84 return "Error running VoIP Innovations reserveDID: ".
85 $rdid->{'statuscode'}. ': '. $rdid->{'status'};
92 my $a = $self->vi_command('assignDID',
93 'did' => $svc_phone->phonenum,
94 'endpointgroup' => $self->option('endpointgroup'),
101 if ( $adid->{'statuscode'} != 100 ) {
102 return "Error running VoIP Innovations assignDID: ".
103 $adid->{'statuscode'}. ': '. $adid->{'status'};
112 if ( $self->option('e911') ) {
114 my %location_hash = $svc_phone->location_hash;
115 my( $zip, $plus4 ) = split('-', $location_hash->{zip});
116 my $e = $self->vi_command('911Insert',
117 'did' => $svc_phone->phonenum,
118 'Address1' => $location_hash{address1},
119 'Address2' => $location_hash{address2},
120 'City' => $location_hash{city},
121 'State' => $location_hash{state},
123 'PlusFour' => $plus4,
125 $svc_phone->phone_name
126 || $svc_phone->cust_svc->cust_pkg->cust_main->contact_firstlast,
129 my $edid = $e->{did};
131 if ( $edid->{'statuscode'} != 100 ) {
132 return "Error running VoIP Innovations 911Insert: ".
133 $edid->{'statuscode'}. ': '. $edid->{'status'};
141 sub _export_replace {
142 my( $self, $new, $old ) = (shift, shift, shift);
144 #hmm, anything to change besides E911 data?
150 if ( $self->option('e911') ) {
152 my %location_hash = $svc_phone->location_hash;
153 my( $zip, $plus4 ) = split('-', $location_hash->{zip});
154 my $e = $self->vi_command('911Update',
155 'did' => $svc_phone->phonenum,
156 'Address1' => $location_hash{address1},
157 'Address2' => $location_hash{address2},
158 'City' => $location_hash{city},
159 'State' => $location_hash{state},
161 'PlusFour' => $plus4,
163 $svc_phone->phone_name
164 || $svc_phone->cust_svc->cust_pkg->cust_main->contact_firstlast,
167 my $edid = $e->{did};
169 if ( $edid->{'statuscode'} != 100 ) {
170 return "Error running VoIP Innovations 911Update: ".
171 $edid->{'statuscode'}. ': '. $edid->{'status'};
180 my( $self, $svc_phone ) = (shift, shift);
182 return '' if $self->option('dry_run')
183 || $self->option('no_provision_did');
185 #probably okay to queue the deletion...?
186 #but hell, let's do it inline anyway, who wants phone numbers hanging around
188 my $r = $self->vi_command('releaseDID',
189 'did' => $svc_phone->phonenum,
192 my $rdid = $r->{did};
194 if ( $rdid->{'statuscode'} != 100 ) {
195 return "Error running VoIP Innovations releaseDID: ".
196 $rdid->{'statuscode'}. ': '. $rdid->{'status'};
199 #delete e911 information? assuming release clears all that
204 sub _export_suspend {
205 my( $self, $svc_phone ) = (shift, shift);
210 sub _export_unsuspend {
211 my( $self, $svc_phone ) = (shift, shift);