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 $vi = 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') ) {
71 return "can't yet provision to VoIP Innovations v3 API"; #XXX
77 my $r = $self->vi_command('reserveDID',
78 'did' => $svc_phone->phonenum,
80 'endpointgroup' => $self->option('endpointgroup'),
85 if ( $rdid->{'statuscode'} != 100 ) {
86 return "Error running VoIP Innovations reserveDID: ".
87 $rdid->{'statuscode'}. ': '. $rdid->{'status'};
94 my $a = $self->vi_command('assignDID',
95 'did' => $svc_phone->phonenum,
96 'endpointgroup' => $self->option('endpointgroup'),
101 my $adid = $a->{did};
103 if ( $adid->{'statuscode'} != 100 ) {
104 return "Error running VoIP Innovations assignDID: ".
105 $adid->{'statuscode'}. ': '. $adid->{'status'};
114 if ( $self->option('e911') ) {
116 my %location_hash = $svc_phone->location_hash;
117 my( $zip, $plus4 ) = split('-', $location_hash->{zip});
118 my $resp = $self->vi_command('insert911',
119 'did' => $svc_phone->phonenum,
120 'address1' => $location_hash{address1},
121 'address2' => $location_hash{address2},
122 'city' => $location_hash{city},
123 'state' => $location_hash{state},
125 'plusFour' => $plus4,
127 $svc_phone->phone_name
128 || $svc_phone->cust_svc->cust_pkg->cust_main->contact_firstlast,
131 if ( $resp->{'responseCode'} != 100 ) {
132 return "Error running VoIP Innovations insert911: ".
133 $resp->{'responseCode'}. ': '. $resp->{'responseMessage'};
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 = $new->location_hash;
153 my( $zip, $plus4 ) = split('-', $location_hash->{zip});
154 my $resp = $self->vi_command('update911',
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 if ( $resp->{'responseCode'} != 100 ) {
168 return "Error running VoIP Innovations update911: ".
169 $resp->{'responseCode'}. ': '. $resp->{'responseMessage'};
178 my( $self, $svc_phone ) = (shift, shift);
180 return '' if $self->option('dry_run');
186 unless ( $self->option('no_provision_did') ) {
188 return "can't yet provision to VoIP Innovations v3 API"; #XXX
190 #probably okay to queue the deletion...?
191 #but hell, let's do it inline anyway, who wants phone numbers hanging around
193 my $r = $self->vi_command('releaseDID',
194 'did' => $svc_phone->phonenum,
197 my $rdid = $r->{did};
199 if ( $rdid->{'statuscode'} != 100 ) {
200 return "Error running VoIP Innovations releaseDID: ".
201 $rdid->{'statuscode'}. ': '. $rdid->{'status'};
210 if ( $self->option('e911') ) {
212 my $resp = $self->vi_command('remove911',
213 'did' => $svc_phone->phonenum,
216 if ( $resp->{'responseCode'} != 100 ) {
217 return "Error running VoIP Innovations remove911: ".
218 $resp->{'responseCode'}. ': '. $resp->{'responseMessage'};
226 sub _export_suspend {
227 my( $self, $svc_phone ) = (shift, shift);
232 sub _export_unsuspend {
233 my( $self, $svc_phone ) = (shift, shift);