1 package FS::part_export::ikano;
5 use vars qw(@ISA %info %loopType $me);
7 use Date::Format qw( time2str );
8 use Date::Parse qw( str2time );
9 use FS::Record qw(qsearch qsearchs dbh);
14 @ISA = qw(FS::part_export);
15 $me= '[' . __PACKAGE__ . ']';
17 tie my %options, 'Tie::IxHash',
18 'keyid' => { label=>'Ikano keyid' },
19 'username' => { label=>'Ikano username',
22 'password' => { label=>'Ikano password' },
23 'check_networks' => { label => 'Check Networks',
24 default => 'ATT,BELLCA',
26 'debug' => { label => 'Debug Mode', type => 'checkbox' },
31 'desc' => 'Provision DSL to Ikano',
32 'options' => \%options,
34 Requires installation of
35 <a href="http://search.cpan.org/dist/Net-Ikano">Net::Ikano</a> from CPAN.
39 %loopType = ( '' => 'Line-share', '0' => 'Standalone' );
41 sub rebless { shift; }
43 sub external_pkg_map { 1; }
61 sub location_types_parse {
63 my %t = $class->location_types;
66 (map { $_ => $_ } keys %t),
68 'STE' => 'SUIT', #USPS
73 # we distinguish between invalid new data (return error) versus data that
74 # has legitimately changed (may eventually execute hooks; now just update)
75 # if we do add hooks later, we should work on a copy of svc_dsl and pass
76 # the old and new svc_dsl to the hooks so they know what changed
78 # current assumptions of what won't change (from their side):
79 # vendor_order_id, vendor_qual_id, vendor_order_type, pushed, monitored,
80 # last_pull, address (from qual), contact info, ProductCustomId
81 my($self, $svc_dsl, $threshold) = (shift, shift, shift);
82 my $result = $self->valid_order($svc_dsl,'pull');
83 return $result unless $result eq '';
86 if($now - $svc_dsl->last_pull < $threshold) {
87 warn "$me skipping pull since threshold not reached (svcnum="
88 . $svc_dsl->svcnum . ",now=$now,threshold=$threshold,last_pull="
89 . $svc_dsl->last_pull .")" if $self->option('debug');
93 $result = $self->ikano_command('ORDERSTATUS',
94 { OrderId => $svc_dsl->vendor_order_id } );
95 return $result unless ref($result); # scalar (string) is an error
97 # now we're getting an OrderResponse which should have one Order in it
98 warn "$me pull OrderResponse hash:\n".Dumper($result)
99 if $self->option('debug');
101 return 'Invalid order response' unless defined $result->{'Order'};
102 $result = $result->{'Order'};
104 return 'No order id or status returned'
105 unless defined $result->{'Status'} && defined $result->{'OrderId'};
107 local $SIG{HUP} = 'IGNORE';
108 local $SIG{INT} = 'IGNORE';
109 local $SIG{QUIT} = 'IGNORE';
110 local $SIG{TERM} = 'IGNORE';
111 local $SIG{TSTP} = 'IGNORE';
112 local $SIG{PIPE} = 'IGNORE';
114 my $oldAutoCommit = $FS::UID::AutoCommit;
115 local $FS::UID::AutoCommit = 0;
119 my $order_status = grep($_ eq $result->{'Status'}, @Net::Ikano::orderStatus)
120 ? $result->{'Status'} : '';
121 return 'Invalid new status' if $order_status eq '';
122 $svc_dsl->vendor_order_status($order_status)
123 if($svc_dsl->vendor_order_status ne $order_status);
124 $svc_dsl->monitored('')
125 if ($order_status eq 'CANCELLED' || $order_status eq 'COMPLETED');
127 # 2. fields we don't care much about
128 my %justUpdate = ( 'first' => 'FirstName',
129 'last' => 'LastName',
130 'company' => 'CompanyName',
131 'username' => 'Username',
132 'password' => 'Password' );
135 while (($fsf, $ikanof) = each %justUpdate) {
136 $svc_dsl->$fsf($result->{$ikanof})
137 if $result->{$ikanof} ne $svc_dsl->$fsf;
140 # let's look inside the <Product> response element
141 my @product = $result->{'Product'};
142 return 'Invalid number of products on order' if scalar(@product) != 1;
143 my $product = $result->{'Product'}[0];
146 if($svc_dsl->loop_type eq '') { # line-share
147 # TN may change only if sub changes it and New or Change order in Completed status
148 my $tn = $product->{'PhoneNumber'};
149 if($tn ne $svc_dsl->phonenum) {
150 if( ($svc_dsl->vendor_order_type eq 'NEW'
151 || $svc_dsl->vendor_order_type eq 'CHANGE')
152 && $svc_dsl->vendor_order_status eq 'COMPLETED' ) {
153 $svc_dsl->phonenum($tn);
155 else { return 'TN has changed in an invalid state'; }
158 elsif($svc_dsl->loop_type eq '0') { # dry loop
159 # TN may change only if it's assigned while a New or Change order is in progress
160 return 'Invalid PhoneNumber value for a dry loop'
161 if $product->{'PhoneNumber'} ne 'STANDALONE';
162 my $tn = $product->{'VirtualPhoneNumber'};
163 if($tn ne $svc_dsl->phonenum) {
164 if( ($svc_dsl->vendor_order_type eq 'NEW'
165 || $svc_dsl->vendor_order_type eq 'CHANGE')
166 && $svc_dsl->vendor_order_status ne 'COMPLETED'
167 && $svc_dsl->vendor_order_status ne 'CANCELLED') {
168 $svc_dsl->phonenum($tn);
170 else { return 'TN has changed in an invalid state'; }
174 # 4. desired_due_date - may change if manually changed
175 if($svc_dsl->vendor_order_type eq 'NEW'
176 || $svc_dsl->vendor_order_type eq 'CHANGE'){
177 my $f = str2time($product->{'DateToOrder'});
178 return 'Invalid DateToOrder' unless $f;
179 $svc_dsl->desired_due_date($f) if $svc_dsl->desired_due_date ne $f;
180 # XXX: optionally sync back to start_date or whatever...
182 elsif($svc_dsl->vendor_order_type eq 'CANCEL'){
183 my $f = str2time($product->{'DateToDisconnect'});
184 return 'Invalid DateToDisconnect' unless $f;
185 $svc_dsl->desired_due_date($f) if $svc_dsl->desired_due_date ne $f;
186 # XXX: optionally sync back to expire or whatever...
190 if($svc_dsl->vendor_order_type eq 'NEW'
191 || $svc_dsl->vendor_order_type eq 'CHANGE') {
192 my $f = str2time($product->{'ActivationDate'});
193 if($svc_dsl->vendor_order_status ne 'NEW'
194 && $svc_dsl->vendor_order_status ne 'CANCELLED') {
195 return 'Invalid ActivationDate' unless $f;
196 $svc_dsl->due_date($f) if $svc_dsl->due_date ne $f;
199 # Ikano API does not implement the proper disconnect date,
200 # so we can't do anything about it
202 # 6. staticips - for now just comma-separate them
203 my $tstatics = $result->{'StaticIps'};
204 my @istatics = defined $tstatics ? @$tstatics : ();
205 my $ostatics = $svc_dsl->staticips;
206 my @ostatics = split(',',$ostatics);
207 # more horrible search/sync code below...
208 my $staticsChanged = 0;
209 foreach my $istatic ( @istatics ) { # they have, we don't
210 unless ( grep($_ eq $istatic, @ostatics) ) {
211 push @ostatics, $istatic;
215 for(my $i=0; $i < scalar(@ostatics); $i++) {
216 unless ( grep($_ eq $ostatics[$i], @istatics) ) {
217 splice(@ostatics,$i,1);
222 $svc_dsl->staticips(join(',',@ostatics)) if $staticsChanged;
224 # 7. notes - put them into the common format and compare
225 my $tnotes = $result->{'OrderNotes'};
226 my @tnotes = defined $tnotes ? @$tnotes : ();
227 my @inotes = (); # all Ikano OrderNotes as FS::dsl_note objects
228 my $notesChanged = 0;
229 foreach my $tnote ( @tnotes ) {
230 my $inote = $self->ikano2fsnote($tnote,$svc_dsl->svcnum);
231 return 'Cannot parse note' unless ref($inote);
232 push @inotes, $inote;
234 my @onotes = $svc_dsl->notes;
235 # assume notes we already have don't change & no notes added from our side
236 # so using the horrible code below just find what we're missing and add it
238 foreach my $inote ( @inotes ) {
240 foreach my $onote ( @onotes ) {
241 if($onote->date == $inote->date && $onote->note eq $inote->note) {
246 $error = $inote->insert unless ( $found );
248 $dbh->rollback if $oldAutoCommit;
249 return "Cannot add note: $error";
253 $svc_dsl->last_pull((time));
254 local $FS::svc_Common::noexport_hack = 1;
255 $error = $svc_dsl->replace;
257 $dbh->rollback if $oldAutoCommit;
258 return "Cannot update DSL data: $error";
261 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
267 my($self,$n,$svcnum) = (shift,shift,shift);
268 my @ikanoRequired = qw( HighPriority StaffId Date Text CompanyStaffId );
269 return '' unless defined $n->{'HighPriority'}
270 && defined $n->{'StaffId'}
271 && defined $n->{'CompanyStaffId'}
272 && defined $n->{'Date'}
273 && defined $n->{'Text'}
276 $by = "Ikano" if $n->{'CompanyStaffId'} == -1 && $n->{'StaffId'} != -1;
277 $by = "Us" if $n->{'StaffId'} == -1 && $n->{'CompanyStaffId'} != -1;
282 'priority' => $n->{'HighPriority'} eq 'false' ? 'N' : 'H',
283 '_date' => int(str2time($n->{'Date'})),
284 'note' => $n->{'Text'},
288 # address always required for Ikano qual, TN optional (assume dry if not given)
290 my($self,$qual) = (shift,shift);
292 my %location_hash = $qual->location_hash;
293 return 'No address provided' unless keys %location_hash;
295 return 'Location kind is required' unless $location_hash{location_kind};
297 my $svctn = $qual->phonenum;
299 my $result = $self->ikano_command('PREQUAL',
300 { AddressLine1 => $location_hash{address1},
301 AddressUnitType => $location_hash{location_type},
302 AddressUnitValue => $location_hash{location_number},
303 AddressCity => $location_hash{city},
304 AddressState => $location_hash{state},
305 ZipCode => $location_hash{zip},
306 Country => $location_hash{country},
307 LocationType => $location_hash{location_kind},
308 PhoneNumber => length($svctn) > 1 ? $svctn : "STANDALONE",
309 RequestClientIP => '127.0.0.1',
310 CheckNetworks => $self->option('check_networks'),
312 return $result unless ref($result); # error case
313 return 'Invalid prequal response' unless defined $result->{'PrequalId'};
316 # lame data structure traversal...
317 # don't spend much time here, just get TermsId and ProductCustomId
318 my $networks = $result->{'Network'};
319 my @networks = defined $networks ? @$networks : ();
321 foreach my $network ( @networks ) {
322 my $productgroups = $network->{'ProductGroup'};
323 my @productgroups = defined $productgroups ? @$productgroups : ();
325 foreach my $productgroup ( @productgroups ) {
326 my $prefix = "ikano_Network_$netcount"."_ProductGroup_$pgcount"."_";
327 $qoptions->{$prefix."TermsId"} = $productgroup->{'TermsId'};
328 my $products = $productgroup->{'Product'};
329 my @products = defined $products ? @$products : ();
331 foreach my $product ( @products ) {
332 $qoptions->{$prefix."Product_$prodcount"."_ProductCustomId"} = $product->{'ProductCustomId'};
340 { 'vendor_qual_id' => $result->{'PrequalId'},
341 'status' => scalar(@networks) ? 'Q' : 'D',
342 'options' => $qoptions,
347 my($self,$qual) = (shift,shift);
349 my %qual_options = $qual->options;
350 my @externalids = ();
351 my( $optionname, $optionvalue );
352 while (($optionname, $optionvalue) = each %qual_options) {
353 push @externalids, $optionvalue
354 if ( $optionname =~ /^ikano_Network_(\d+)_ProductGroup_(\d+)_Product_(\d+)_ProductCustomId$/
355 && $optionvalue ne '' );
360 my @part_pkgs = qsearch( 'part_pkg', { 'disabled' => '' } );
361 foreach my $part_pkg ( @part_pkgs ) {
362 my %vendor_pkg_ids = $part_pkg->vendor_pkg_ids;
363 my $externalid = $vendor_pkg_ids{$self->exportnum}
364 if defined $vendor_pkg_ids{$self->exportnum};
365 if ( $externalid && grep { $_ eq $externalid } @externalids ) {
366 $pkglist{$part_pkg->pkgpart} = $part_pkg->pkg_comment;
367 $found{$externalid}++;
372 foreach my $externalid ( grep !$found{$_}, @externalids ) {
373 $not_avail{$externalid} = $externalid; #a better label?
376 { 'header' => 'Qualifying Packages',
377 'pkglist' => \%pkglist,
378 'not_avail' => \%not_avail,
382 sub quals_by_cust_and_pkg {
383 my($self, $custnum, $pkgpart) = (shift,shift,shift);
385 die "invalid custnum or pkgpart"
386 unless ($custnum =~ /^\d+$/ && $pkgpart =~ /^\d+$/);
388 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } );
389 die "no part_pkg found" unless $part_pkg;
390 my %vendor_pkg_ids = $part_pkg->vendor_pkg_ids;
391 my $external_id = $vendor_pkg_ids{$self->exportnum};
392 die "no vendor package id defined on this package" unless $external_id;
394 my $extra_sql = "where custnum = $custnum or locationnum in (select "
395 . "locationnum from cust_location where custnum = $custnum)";
396 my @quals = qsearch( { 'table' => 'qual', 'extra_sql' => $extra_sql, } );
399 foreach my $qual ( @quals ) {
400 my %qual_options = $qual->options;
401 my( $optionname, $optionvalue );
402 while (($optionname, $optionvalue) = each %qual_options) {
403 push @filtered_quals, $qual
404 if ( $optionname =~ /^ikano_Network_(\d+)_ProductGroup_(\d+)_Product_(\d+)_ProductCustomId$/
405 && $optionvalue eq $external_id );
413 my($self,$svc_dsl) = (shift,shift);
414 my $conf = new FS::Conf;
415 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
416 my @notes = $svc_dsl->notes;
417 my $html = '<TABLE border="1" cellspacing="2" cellpadding="2" id="dsl_notes">
418 <TR><TH>Date</TH><TH>By</TH><TH>Priority</TH><TH>Note</TH></TR>';
419 foreach my $note ( @notes ) {
421 <TD>".time2str("$date_format %H:%M",$note->date)."</TD>
422 <TD>".$note->by."</TD>
423 <TD>". ($note->priority eq 'N' ? 'Normal' : 'High') ."</TD>
424 <TD>".$note->note."</TD></TR>";
430 sub loop_type_long { # sub, not a method
431 my($svc_dsl) = (shift);
432 return $loopType{$svc_dsl->loop_type};
436 my( $self, $command, $args ) = @_;
440 my $ikano = Net::Ikano->new(
441 'keyid' => $self->option('keyid'),
442 'username' => $self->option('username'),
443 'password' => $self->option('password'),
444 'debug' => $self->option('debug'),
447 $ikano->$command($args);
451 eval "use Net::Ikano;";
456 my( $self, $svc_dsl, $action ) = (shift, shift, shift);
460 warn "$me valid_order action=$action svc_dsl:\n". Dumper($svc_dsl)
461 if $self->option('debug');
463 # common to all order types/status/loop_type
464 my $error = !($svc_dsl->desired_due_date
465 && grep($_ eq $svc_dsl->vendor_order_type, Net::Ikano->orderTypes)
468 && defined $svc_dsl->loop_type
469 && $svc_dsl->vendor_qual_id
471 return 'Missing or invalid order data' if $error;
473 my %vendor_pkg_ids = $svc_dsl->cust_svc->cust_pkg->part_pkg->vendor_pkg_ids;
474 return 'Package does not have an external id configured'
475 unless defined $vendor_pkg_ids{$self->exportnum};
477 return 'No valid qualification for this order'
478 unless qsearch( 'qual', { 'vendor_qual_id' => $svc_dsl->vendor_qual_id });
480 # now go by order type
481 # weird ifs & long lines for readability and ease of understanding - don't change
482 if($svc_dsl->vendor_order_type eq 'NEW') {
483 if($svc_dsl->pushed) {
484 $error = !( ($action eq 'pull' || $action eq 'statuschg'
485 || $action eq 'delete' || $action eq 'expire')
486 && length($svc_dsl->vendor_order_id) > 0
487 && length($svc_dsl->vendor_order_status) > 0
489 return 'Invalid order data' if $error;
491 return 'Phone number required for status change'
492 if ($action eq 'statuschg' && length($svc_dsl->phonenum) < 1);
494 else { # unpushed New order - cannot do anything other than push it
495 $error = !($action eq 'insert'
496 && length($svc_dsl->vendor_order_id) < 1
497 && length($svc_dsl->vendor_order_status) < 1
498 && ( ($svc_dsl->phonenum eq '' && $svc_dsl->loop_type eq '0') # dry
499 || ($svc_dsl->phonenum ne '' && $svc_dsl->loop_type eq '') # line-share
502 return 'Invalid order data' if $error;
505 elsif($svc_dsl->vendor_order_type eq 'CANCEL') {
507 elsif($svc_dsl->vendor_order_type eq 'CHANGE') {
514 my ($self,$vendor_qual_id,$ProductCustomId) = (shift,shift,shift);
515 my $qual = qsearchs( 'qual', { 'vendor_qual_id' => $vendor_qual_id });
516 return '' unless $qual;
517 my %qual_options = $qual->options;
518 my( $optionname, $optionvalue );
519 while (($optionname, $optionvalue) = each %qual_options) {
520 if ( $optionname =~ /^ikano_Network_(\d+)_ProductGroup_(\d+)_Product_(\d+)_ProductCustomId$/
521 && $optionvalue eq $ProductCustomId ) {
523 my $productgroup = $2;
524 return $qual->option("ikano_Network_".$network."_ProductGroup_".$productgroup."_TermsId");
531 my( $self, $svc_dsl ) = (shift, shift);
533 my $result = $self->valid_order($svc_dsl,'insert');
534 return $result unless $result eq '';
536 my $isp_chg = $svc_dsl->isp_chg eq 'Y' ? 'YES' : 'NO';
537 my $contactTN = $svc_dsl->cust_svc->cust_pkg->cust_main->daytime;
538 $contactTN =~ s/[^0-9]//g;
540 my %vendor_pkg_ids = $svc_dsl->cust_svc->cust_pkg->part_pkg->vendor_pkg_ids;
541 my $ProductCustomId = $vendor_pkg_ids{$self->exportnum};
545 ProductCustomId => $ProductCustomId,
546 TermsId => $self->qual2termsid($svc_dsl->vendor_qual_id,$ProductCustomId),
547 DSLPhoneNumber => $svc_dsl->loop_type eq '0' ? 'STANDALONE'
548 : $svc_dsl->phonenum,
549 Password => $svc_dsl->password,
550 PrequalId => $svc_dsl->vendor_qual_id,
551 CompanyName => $svc_dsl->company,
552 FirstName => $svc_dsl->first,
553 LastName => $svc_dsl->last,
555 ContactMethod => 'PHONE',
556 ContactPhoneNumber => $contactTN,
557 ContactEmail => 'x@x.xx',
559 DateToOrder => time2str("%Y-%m-%d",$svc_dsl->desired_due_date),
560 RequestClientIP => '127.0.0.1',
561 IspChange => $isp_chg,
562 IspPrevious => $isp_chg eq 'YES' ? $svc_dsl->isp_prev : '',
563 CurrentProvider => $isp_chg eq 'NO' ? $svc_dsl->isp_prev : '',
566 $result = $self->ikano_command('ORDER',$args);
567 return $result unless ref($result); # scalar (string) is an error
569 # now we're getting an OrderResponse which should have one Order in it
570 warn "$me _export_insert OrderResponse hash:\n".Dumper($result)
571 if $self->option('debug');
573 return 'Invalid order response' unless defined $result->{'Order'};
574 $result = $result->{'Order'};
576 return 'No/invalid order id or status returned'
577 unless defined $result->{'Status'} && defined $result->{'OrderId'}
578 && grep($_ eq $result->{'Status'}, @Net::Ikano::orderStatus);
580 $svc_dsl->pushed(time);
581 $svc_dsl->last_pull((time)+1);
582 $svc_dsl->vendor_order_id($result->{'OrderId'});
583 $svc_dsl->vendor_order_status($result->{'Status'});
584 $svc_dsl->username($result->{'Username'});
585 local $FS::svc_Common::noexport_hack = 1;
586 $result = $svc_dsl->replace;
587 return "Error setting DSL fields: $result" if $result;
591 sub _export_replace {
592 my( $self, $new, $old ) = (shift, shift, shift);
593 # XXX only supports password changes now, but should return error if
594 # another change is attempted?
596 if($new->password ne $old->password) {
597 my $result = $self->valid_order($new,'statuschg');
598 return $result unless $result eq '';
600 $result = $self->ikano_command('PASSWORDCHANGE',
601 { DSLPhoneNumber => $new->phonenum,
602 NewPassword => $new->password,
604 return $result unless ref($result); # scalar (string) is an error
606 return 'Error changing password' unless defined $result->{'Password'}
607 && $result->{'Password'} eq $new->password;
614 my( $self, $svc_dsl ) = (shift, shift);
616 my $result = $self->valid_order($svc_dsl,'delete');
617 return $result unless $result eq '';
619 # for now allow an immediate cancel only on New orders in New/Pending status
620 #XXX: add support for Change and Cancel orders in New/Pending status later
622 if($svc_dsl->vendor_order_type eq 'NEW') {
623 if($svc_dsl->vendor_order_status eq 'NEW'
624 || $svc_dsl->vendor_order_status eq 'PENDING') {
625 my $result = $self->ikano_command('CANCEL',
626 { OrderId => $svc_dsl->vendor_order_id, } );
627 return $result unless ref($result); # scalar (string) is an error
628 return 'Unable to cancel order' unless $result->{'Order'};
629 $result = $result->{'Order'};
630 return 'Invalid cancellation response'
631 unless $result->{'Status'} eq 'CANCELLED'
632 && $result->{'OrderId'} eq $svc_dsl->vendor_order_id;
634 # we're supposed to do a pull, but it will break everything, so don't
635 # this is very wrong...
638 return "Cannot cancel a NEW order unless it's in NEW or PENDING status";
641 elsif($svc_dsl->vendor_order_type eq 'CANCEL') {
642 return 'Cannot cancel a CANCEL order unless expire was set'
643 unless $svc_dsl->cust_svc->cust_pkg->expire > 0;
646 return 'Canceling orders other than NEW orders is not currently implemented';
653 my($self, $svc_dsl, $date) = (shift, shift, shift);
655 my $result = $self->valid_order($svc_dsl,'expire');
656 return $result unless $result eq '';
658 # for now allow a proper cancel only on New orders in Completed status
659 #XXX: add support for some other cases in future
661 if($svc_dsl->vendor_order_type eq 'NEW'
662 && $svc_dsl->vendor_order_status eq 'COMPLETED') {
664 my $contactTN = $svc_dsl->cust_svc->cust_pkg->cust_main->daytime;
665 $contactTN =~ s/[^0-9]//g;
667 my %vendor_pkg_ids = $svc_dsl->cust_svc->cust_pkg->part_pkg->vendor_pkg_ids;
668 my $ProductCustomId = $vendor_pkg_ids{$self->exportnum};
670 # we are now a cancel order
671 $svc_dsl->desired_due_date($date);
672 $svc_dsl->vendor_order_type('CANCEL');
675 orderType => 'CANCEL',
676 ProductCustomId => $ProductCustomId,
677 TermsId => $self->qual2termsid($svc_dsl->vendor_qual_id,$ProductCustomId),
678 DSLPhoneNumber => $svc_dsl->loop_type eq '0' ? 'STANDALONE'
679 : $svc_dsl->phonenum,
680 Password => $svc_dsl->password,
681 PrequalId => $svc_dsl->vendor_qual_id,
682 CompanyName => $svc_dsl->company,
683 FirstName => $svc_dsl->first,
684 LastName => $svc_dsl->last,
686 ContactMethod => 'PHONE',
687 ContactPhoneNumber => $contactTN,
688 ContactEmail => 'x@x.xx',
690 DateToOrder => time2str("%Y-%m-%d",$date),
691 RequestClientIP => '127.0.0.1',
694 CurrentProvider => '',
697 $args->{'VirtualPhoneNumber'} = $svc_dsl->phonenum
698 if $svc_dsl->loop_type eq '0';
700 $result = $self->ikano_command('ORDER',$args);
701 return $result unless ref($result); # scalar (string) is an error
703 # now we're getting an OrderResponse which should have one Order in it
704 warn "$me _export_insert OrderResponse hash:\n".Dumper($result)
705 if $self->option('debug');
707 return 'Invalid order response' unless defined $result->{'Order'};
708 $result = $result->{'Order'};
710 return 'No/invalid order id or status returned'
711 unless defined $result->{'Status'} && defined $result->{'OrderId'}
712 && grep($_ eq $result->{'Status'}, @Net::Ikano::orderStatus);
714 $svc_dsl->pushed(time);
715 $svc_dsl->last_pull((time)+1);
716 $svc_dsl->vendor_order_id($result->{'OrderId'});
717 $svc_dsl->vendor_order_status($result->{'Status'});
718 $svc_dsl->monitored('Y');
719 local $FS::svc_Common::noexport_hack = 1;
720 $result = $svc_dsl->replace;
721 return "Error setting DSL fields: $result" if $result;
724 return "Cancelling anything other than NEW orders in COMPLETED status is "
725 . "not currently implemented";
731 my( $self, $svc_dsl, $type ) = (shift, shift, shift);
733 my $result = $self->valid_order($svc_dsl,'statuschg');
734 return $result unless $result eq '';
736 # get the DSLServiceId
737 $result = $self->ikano_command('CUSTOMERLOOKUP',
738 { PhoneNumber => $svc_dsl->phonenum } );
739 return $result unless ref($result); # scalar (string) is an error
740 return 'No DSLServiceId found' unless defined $result->{'DSLServiceId'};
741 my $DSLServiceId = $result->{'DSLServiceId'};
743 $result = $self->ikano_command('ACCOUNTSTATUSCHANGE',
744 { DSLPhoneNumber => $svc_dsl->phonenum,
745 DSLServiceId => $DSLServiceId,
748 return $result unless ref($result); # scalar (string) is an error
752 sub _export_suspend {
753 my( $self, $svc_dsl ) = (shift, shift);
754 $self->statuschg($svc_dsl,"SUSPEND");
757 sub _export_unsuspend {
758 my( $self, $svc_dsl ) = (shift, shift);
759 $self->statuschg($svc_dsl,"UNSUSPEND");