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_provision_did' => { label=>'Disable DID provisioning',
22 #not particularly useful unless we can_get_dids
23 # 'dry_run' => { label=>"Test mode - don't actually provision",
26 'sandbox' => { label=>'Communicatino with the VoIP Innovations sandbox'.
27 ' instead of the live server',
34 'desc' => 'Provision phone numbers / E911 to VoIP Innovations (API 3.0)',
35 'options' => \%options,
38 Requires installation of
39 <a href="http://search.cpan.org/dist/Net-VoIP_Innovations">Net::VoIP_Innovations</a>
44 sub rebless { shift; }
46 sub can_get_dids { 0; } #with API 3.0? not yet
49 my( $self, $command, @args ) = @_;
51 eval "use Net::VoIP_Innovations 3.00;";
57 my $vi = Net::VoIP_Innovations->new(
58 'login' => $self->option('login'),
59 'password' => $self->option('password'),
60 'sandbox' => $self->option('sandbox'),
68 my( $self, $svc_phone ) = (shift, shift);
70 return '' if $self->option('dry_run');
72 #we want to provision and catch errors now, not queue
74 unless ( $self->option('no_provision_did') ) {
76 return "can't yet provision to VoIP Innovations v3 API"; #XXX
82 my $r = $self->vi_command('reserveDID',
83 'did' => $svc_phone->phonenum,
85 'endpointgroup' => $self->option('endpointgroup'),
90 if ( $rdid->{'statuscode'} != 100 ) {
91 return "Error running VoIP Innovations reserveDID: ".
92 $rdid->{'statuscode'}. ': '. $rdid->{'status'};
99 my $a = $self->vi_command('assignDID',
100 'did' => $svc_phone->phonenum,
101 'endpointgroup' => $self->option('endpointgroup'),
106 my $adid = $a->{did};
108 if ( $adid->{'statuscode'} != 100 ) {
109 return "Error running VoIP Innovations assignDID: ".
110 $adid->{'statuscode'}. ': '. $adid->{'status'};
119 if ( $self->option('e911') ) {
121 my %location_hash = $svc_phone->location_hash;
122 my( $zip, $plus4 ) = split('-', $location_hash->{zip});
123 my $resp = $self->vi_command('insert911',
124 'did' => $svc_phone->phonenum,
125 'address1' => $location_hash{address1},
126 'address2' => $location_hash{address2},
127 'city' => $location_hash{city},
128 'state' => $location_hash{state},
130 'plusFour' => $plus4,
132 $svc_phone->phone_name
133 || $svc_phone->cust_svc->cust_pkg->cust_main->contact_firstlast,
136 if ( $resp->{'responseCode'} != 100 ) {
137 return "Error running VoIP Innovations insert911: ".
138 $resp->{'responseCode'}. ': '. $resp->{'responseMessage'};
146 sub _export_replace {
147 my( $self, $new, $old ) = (shift, shift, shift);
149 #hmm, anything to change besides E911 data?
155 if ( $self->option('e911') ) {
157 my %location_hash = $new->location_hash;
158 my( $zip, $plus4 ) = split('-', $location_hash->{zip});
159 my $resp = $self->vi_command('update911',
160 'did' => $svc_phone->phonenum,
161 'address1' => $location_hash{address1},
162 'address2' => $location_hash{address2},
163 'city' => $location_hash{city},
164 'state' => $location_hash{state},
166 'plusFour' => $plus4,
168 $svc_phone->phone_name
169 || $svc_phone->cust_svc->cust_pkg->cust_main->contact_firstlast,
172 if ( $resp->{'responseCode'} != 100 ) {
173 return "Error running VoIP Innovations update911: ".
174 $resp->{'responseCode'}. ': '. $resp->{'responseMessage'};
183 my( $self, $svc_phone ) = (shift, shift);
185 return '' if $self->option('dry_run');
191 unless ( $self->option('no_provision_did') ) {
193 return "can't yet provision to VoIP Innovations v3 API"; #XXX
195 #probably okay to queue the deletion...?
196 #but hell, let's do it inline anyway, who wants phone numbers hanging around
198 my $r = $self->vi_command('releaseDID',
199 'did' => $svc_phone->phonenum,
202 my $rdid = $r->{did};
204 if ( $rdid->{'statuscode'} != 100 ) {
205 return "Error running VoIP Innovations releaseDID: ".
206 $rdid->{'statuscode'}. ': '. $rdid->{'status'};
215 if ( $self->option('e911') ) {
217 my $resp = $self->vi_command('remove911',
218 'did' => $svc_phone->phonenum,
221 if ( $resp->{'responseCode'} != 100 ) {
222 return "Error running VoIP Innovations remove911: ".
223 $resp->{'responseCode'}. ': '. $resp->{'responseMessage'};
231 sub _export_suspend {
232 my( $self, $svc_phone ) = (shift, shift);
237 sub _export_unsuspend {
238 my( $self, $svc_phone ) = (shift, shift);