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
237 foreach my $inote ( @inotes ) {
239 foreach my $onote ( @onotes ) {
240 if($onote->date == $inote->date && $onote->note eq $inote->note) {
245 my $error = $inote->insert unless ( $found );
247 $dbh->rollback if $oldAutoCommit;
248 return "Cannot add note: $error";
252 $svc_dsl->last_pull((time));
253 local $FS::svc_Common::noexport_hack = 1;
254 my $error = $svc_dsl->replace;
256 $dbh->rollback if $oldAutoCommit;
257 return "Cannot update DSL data: $error";
260 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
266 my($self,$n,$svcnum) = (shift,shift,shift);
267 my @ikanoRequired = qw( HighPriority StaffId Date Text CompanyStaffId );
268 return '' unless defined $n->{'HighPriority'}
269 && defined $n->{'StaffId'}
270 && defined $n->{'CompanyStaffId'}
271 && defined $n->{'Date'}
272 && defined $n->{'Text'}
275 $by = "Ikano" if $n->{'CompanyStaffId'} == -1 && $n->{'StaffId'} != -1;
276 $by = "Us" if $n->{'StaffId'} == -1 && $n->{'CompanyStaffId'} != -1;
281 'priority' => $n->{'HighPriority'} eq 'false' ? 'N' : 'H',
282 '_date' => int(str2time($n->{'Date'})),
283 'note' => $n->{'Text'},
287 # address always required for Ikano qual, TN optional (assume dry if not given)
289 my($self,$qual) = (shift,shift);
291 my %location_hash = $qual->location_hash;
292 return 'No address provided' unless keys %location_hash;
294 return 'Location kind is required' unless $location_hash{location_kind};
296 my $svctn = $qual->phonenum;
298 my $result = $self->ikano_command('PREQUAL',
299 { AddressLine1 => $location_hash{address1},
300 AddressUnitType => $location_hash{location_type},
301 AddressUnitValue => $location_hash{location_number},
302 AddressCity => $location_hash{city},
303 AddressState => $location_hash{state},
304 ZipCode => $location_hash{zip},
305 Country => $location_hash{country},
306 LocationType => $location_hash{location_kind},
307 PhoneNumber => length($svctn) > 1 ? $svctn : "STANDALONE",
308 RequestClientIP => '127.0.0.1',
309 CheckNetworks => $self->option('check_networks'),
311 return $result unless ref($result); # error case
312 return 'Invalid prequal response' unless defined $result->{'PrequalId'};
315 # lame data structure traversal...
316 # don't spend much time here, just get TermsId and ProductCustomId
317 my $networks = $result->{'Network'};
318 my @networks = defined $networks ? @$networks : ();
320 foreach my $network ( @networks ) {
321 my $productgroups = $network->{'ProductGroup'};
322 my @productgroups = defined $productgroups ? @$productgroups : ();
324 foreach my $productgroup ( @productgroups ) {
325 my $prefix = "ikano_Network_$netcount"."_ProductGroup_$pgcount"."_";
326 $qoptions->{$prefix."TermsId"} = $productgroup->{'TermsId'};
327 my $products = $productgroup->{'Product'};
328 my @products = defined $products ? @$products : ();
330 foreach my $product ( @products ) {
331 $qoptions->{$prefix."Product_$prodcount"."_ProductCustomId"} = $product->{'ProductCustomId'};
339 { 'vendor_qual_id' => $result->{'PrequalId'},
340 'status' => scalar(@networks) ? 'Q' : 'D',
341 'options' => $qoptions,
346 my($self,$qual) = (shift,shift);
348 my %qual_options = $qual->options;
349 my @externalids = ();
350 my( $optionname, $optionvalue );
351 while (($optionname, $optionvalue) = each %qual_options) {
352 push @externalids, $optionvalue
353 if ( $optionname =~ /^ikano_Network_(\d+)_ProductGroup_(\d+)_Product_(\d+)_ProductCustomId$/
354 && $optionvalue ne '' );
359 my @part_pkgs = qsearch( 'part_pkg', { 'disabled' => '' } );
360 foreach my $part_pkg ( @part_pkgs ) {
361 my %vendor_pkg_ids = $part_pkg->vendor_pkg_ids;
362 my $externalid = $vendor_pkg_ids{$self->exportnum}
363 if defined $vendor_pkg_ids{$self->exportnum};
364 if ( $externalid && grep { $_ eq $externalid } @externalids ) {
365 $pkglist{$part_pkg->pkgpart} = $part_pkg->pkg_comment;
366 $found{$externalid}++;
371 foreach my $externalid ( grep !$found{$_}, @externalids ) {
372 $not_avail{$externalid} = $externalid; #a better label?
376 'pkglist' => \%pkglist,
377 'not_avail' => \%not_avail,
381 sub quals_by_cust_and_pkg {
382 my($self, $custnum, $pkgpart) = (shift,shift,shift);
384 die "invalid custnum or pkgpart"
385 unless ($custnum =~ /^\d+$/ && $pkgpart =~ /^\d+$/);
387 my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } );
388 die "no part_pkg found" unless $part_pkg;
389 my %vendor_pkg_ids = $part_pkg->vendor_pkg_ids;
390 my $external_id = $vendor_pkg_ids{$self->exportnum};
391 die "no vendor package id defined on this package" unless $external_id;
393 my $extra_sql = "where custnum = $custnum or locationnum in (select "
394 . "locationnum from cust_location where custnum = $custnum)";
395 my @quals = qsearch( { 'table' => 'qual', 'extra_sql' => $extra_sql, } );
398 foreach my $qual ( @quals ) {
399 my %qual_options = $qual->options;
400 my( $optionname, $optionvalue );
401 while (($optionname, $optionvalue) = each %qual_options) {
402 push @filtered_quals, $qual
403 if ( $optionname =~ /^ikano_Network_(\d+)_ProductGroup_(\d+)_Product_(\d+)_ProductCustomId$/
404 && $optionvalue eq $external_id );
412 my($self,$svc_dsl) = (shift,shift);
413 my $conf = new FS::Conf;
414 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
415 my @notes = $svc_dsl->notes;
416 my $html = '<TABLE border="1" cellspacing="2" cellpadding="2" id="dsl_notes">
417 <TR><TH>Date</TH><TH>By</TH><TH>Priority</TH><TH>Note</TH></TR>';
418 foreach my $note ( @notes ) {
420 <TD>".time2str("$date_format %H:%M",$note->date)."</TD>
421 <TD>".$note->by."</TD>
422 <TD>". ($note->priority eq 'N' ? 'Normal' : 'High') ."</TD>
423 <TD>".$note->note."</TD></TR>";
429 sub loop_type_long { # sub, not a method
430 my($svc_dsl) = (shift);
431 return $loopType{$svc_dsl->loop_type};
435 my( $self, $command, $args ) = @_;
439 my $ikano = Net::Ikano->new(
440 'keyid' => $self->option('keyid'),
441 'username' => $self->option('username'),
442 'password' => $self->option('password'),
443 'debug' => $self->option('debug'),
446 $ikano->$command($args);
450 eval "use Net::Ikano;";
455 my( $self, $svc_dsl, $action ) = (shift, shift, shift);
459 warn "$me valid_order action=$action svc_dsl:\n". Dumper($svc_dsl)
460 if $self->option('debug');
462 # common to all order types/status/loop_type
463 return 'No desired_due_date' unless $svc_dsl->desired_due_date;
464 return 'Unknown vendor_order_type'
465 unless grep $_ eq $svc_dsl->vendor_order_type, Net::Ikano->orderTypes;
466 return 'No first name' unless $svc_dsl->first;
467 return 'No last name' unless $svc_dsl->get('last');
468 return 'No loop type' unless defined $svc_dsl->loop_type;
469 return 'No vendor_qual_id' unless $svc_dsl->vendor_qual_id;
471 my %vendor_pkg_ids = $svc_dsl->cust_svc->cust_pkg->part_pkg->vendor_pkg_ids;
472 return 'Package does not have an external id configured'
473 unless defined $vendor_pkg_ids{$self->exportnum};
475 return 'No valid qualification for this order'
476 unless qsearch( 'qual', { 'vendor_qual_id' => $svc_dsl->vendor_qual_id });
478 # now go by order type
479 # weird ifs & long lines for readability and ease of understanding - don't change
480 if($svc_dsl->vendor_order_type eq 'NEW') {
481 if($svc_dsl->pushed) {
482 my $error = !( ($action eq 'pull' || $action eq 'statuschg'
483 || $action eq 'delete' || $action eq 'expire')
484 && length($svc_dsl->vendor_order_id) > 0
485 && length($svc_dsl->vendor_order_status) > 0
487 return 'Invalid order data' if $error;
489 return 'Phone number required for status change'
490 if ($action eq 'statuschg' && length($svc_dsl->phonenum) < 1);
492 else { # unpushed New order - cannot do anything other than push it
493 my $error = !($action eq 'insert'
494 && length($svc_dsl->vendor_order_id) < 1
495 && length($svc_dsl->vendor_order_status) < 1
496 && ( ($svc_dsl->phonenum eq '' && $svc_dsl->loop_type eq '0') # dry
497 || ($svc_dsl->phonenum ne '' && $svc_dsl->loop_type eq '') # line-share
500 return 'Invalid order data' if $error;
503 elsif($svc_dsl->vendor_order_type eq 'CANCEL') {
505 elsif($svc_dsl->vendor_order_type eq 'CHANGE') {
512 my ($self,$vendor_qual_id,$ProductCustomId) = (shift,shift,shift);
513 my $qual = qsearchs( 'qual', { 'vendor_qual_id' => $vendor_qual_id });
514 return '' unless $qual;
515 my %qual_options = $qual->options;
516 my( $optionname, $optionvalue );
517 while (($optionname, $optionvalue) = each %qual_options) {
518 if ( $optionname =~ /^ikano_Network_(\d+)_ProductGroup_(\d+)_Product_(\d+)_ProductCustomId$/
519 && $optionvalue eq $ProductCustomId ) {
521 my $productgroup = $2;
522 return $qual->option("ikano_Network_".$network."_ProductGroup_".$productgroup."_TermsId");
529 my( $self, $svc_dsl ) = (shift, shift);
531 my $result = $self->valid_order($svc_dsl,'insert');
532 return $result unless $result eq '';
534 my $isp_chg = $svc_dsl->isp_chg eq 'Y' ? 'YES' : 'NO';
535 my $cust_main = $svc_dsl->cust_svc->cust_pkg->cust_main;
536 my $contactTN = $cust_main->daytime || $cust_main->night || '5555555555';
537 $contactTN =~ s/[^0-9]//g;
539 my %vendor_pkg_ids = $svc_dsl->cust_svc->cust_pkg->part_pkg->vendor_pkg_ids;
540 my $ProductCustomId = $vendor_pkg_ids{$self->exportnum};
544 ProductCustomId => $ProductCustomId,
545 TermsId => $self->qual2termsid($svc_dsl->vendor_qual_id,$ProductCustomId),
546 DSLPhoneNumber => $svc_dsl->loop_type eq '0' ? 'STANDALONE'
547 : $svc_dsl->phonenum,
548 Password => $svc_dsl->password,
549 PrequalId => $svc_dsl->vendor_qual_id,
550 CompanyName => $svc_dsl->company,
551 FirstName => $svc_dsl->first,
552 LastName => $svc_dsl->last,
554 ContactMethod => 'PHONE',
555 ContactPhoneNumber => $contactTN,
556 ContactEmail => 'x@x.xx',
558 DateToOrder => time2str("%Y-%m-%d",$svc_dsl->desired_due_date),
559 RequestClientIP => '127.0.0.1',
560 IspChange => $isp_chg,
561 IspPrevious => $isp_chg eq 'YES' ? $svc_dsl->isp_prev : '',
562 CurrentProvider => $isp_chg eq 'NO' ? $svc_dsl->isp_prev : '',
565 $result = $self->ikano_command('ORDER',$args);
566 return $result unless ref($result); # scalar (string) is an error
568 # now we're getting an OrderResponse which should have one Order in it
569 warn "$me _export_insert OrderResponse hash:\n".Dumper($result)
570 if $self->option('debug');
572 return 'Invalid order response' unless defined $result->{'Order'};
573 $result = $result->{'Order'};
575 return 'No/invalid order id or status returned'
576 unless defined $result->{'Status'} && defined $result->{'OrderId'}
577 && grep($_ eq $result->{'Status'}, @Net::Ikano::orderStatus);
579 $svc_dsl->pushed(time);
580 $svc_dsl->last_pull((time)+1);
581 $svc_dsl->vendor_order_id($result->{'OrderId'});
582 $svc_dsl->vendor_order_status($result->{'Status'});
583 $svc_dsl->username($result->{'Username'});
584 local $FS::svc_Common::noexport_hack = 1;
585 $result = $svc_dsl->replace;
586 return "Error setting DSL fields: $result" if $result;
590 sub _export_replace {
591 my( $self, $new, $old ) = (shift, shift, shift);
592 # XXX only supports password changes now, but should return error if
593 # another change is attempted?
595 if($new->password ne $old->password) {
596 my $result = $self->valid_order($new,'statuschg');
597 return $result unless $result eq '';
599 $result = $self->ikano_command('PASSWORDCHANGE',
600 { DSLPhoneNumber => $new->phonenum,
601 NewPassword => $new->password,
603 return $result unless ref($result); # scalar (string) is an error
605 return 'Error changing password' unless defined $result->{'Password'}
606 && $result->{'Password'} eq $new->password;
613 my( $self, $svc_dsl ) = (shift, shift);
615 my $result = $self->valid_order($svc_dsl,'delete');
616 return $result unless $result eq '';
618 # for now allow an immediate cancel only on New orders in New/Pending status
619 #XXX: add support for Change and Cancel orders in New/Pending status later
621 if($svc_dsl->vendor_order_type eq 'NEW') {
622 if($svc_dsl->vendor_order_status eq 'NEW'
623 || $svc_dsl->vendor_order_status eq 'PENDING') {
624 my $result = $self->ikano_command('CANCEL',
625 { OrderId => $svc_dsl->vendor_order_id, } );
626 return $result unless ref($result); # scalar (string) is an error
627 return 'Unable to cancel order' unless $result->{'Order'};
628 $result = $result->{'Order'};
629 return 'Invalid cancellation response'
630 unless $result->{'Status'} eq 'CANCELLED'
631 && $result->{'OrderId'} eq $svc_dsl->vendor_order_id;
633 # we're supposed to do a pull, but it will break everything, so don't
634 # this is very wrong...
637 return "Cannot cancel a NEW order unless it's in NEW or PENDING status";
640 elsif($svc_dsl->vendor_order_type eq 'CANCEL') {
641 return 'Cannot cancel a CANCEL order unless expire was set'
642 unless $svc_dsl->cust_svc->cust_pkg->expire > 0;
645 return 'Canceling orders other than NEW orders is not currently implemented';
652 my($self, $svc_dsl, $date) = (shift, shift, shift);
654 my $result = $self->valid_order($svc_dsl,'expire');
655 return $result unless $result eq '';
657 # for now allow a proper cancel only on New orders in Completed status
658 #XXX: add support for some other cases in future
660 if($svc_dsl->vendor_order_type eq 'NEW'
661 && $svc_dsl->vendor_order_status eq 'COMPLETED') {
663 my $contactTN = $svc_dsl->cust_svc->cust_pkg->cust_main->daytime;
664 $contactTN =~ s/[^0-9]//g;
666 my %vendor_pkg_ids = $svc_dsl->cust_svc->cust_pkg->part_pkg->vendor_pkg_ids;
667 my $ProductCustomId = $vendor_pkg_ids{$self->exportnum};
669 # we are now a cancel order
670 $svc_dsl->desired_due_date($date);
671 $svc_dsl->vendor_order_type('CANCEL');
674 orderType => 'CANCEL',
675 ProductCustomId => $ProductCustomId,
676 TermsId => $self->qual2termsid($svc_dsl->vendor_qual_id,$ProductCustomId),
677 DSLPhoneNumber => $svc_dsl->loop_type eq '0' ? 'STANDALONE'
678 : $svc_dsl->phonenum,
679 Password => $svc_dsl->password,
680 PrequalId => $svc_dsl->vendor_qual_id,
681 CompanyName => $svc_dsl->company,
682 FirstName => $svc_dsl->first,
683 LastName => $svc_dsl->last,
685 ContactMethod => 'PHONE',
686 ContactPhoneNumber => $contactTN,
687 ContactEmail => 'x@x.xx',
689 DateToOrder => time2str("%Y-%m-%d",$date),
690 RequestClientIP => '127.0.0.1',
693 CurrentProvider => '',
696 $args->{'VirtualPhoneNumber'} = $svc_dsl->phonenum
697 if $svc_dsl->loop_type eq '0';
699 $result = $self->ikano_command('ORDER',$args);
700 return $result unless ref($result); # scalar (string) is an error
702 # now we're getting an OrderResponse which should have one Order in it
703 warn "$me _export_insert OrderResponse hash:\n".Dumper($result)
704 if $self->option('debug');
706 return 'Invalid order response' unless defined $result->{'Order'};
707 $result = $result->{'Order'};
709 return 'No/invalid order id or status returned'
710 unless defined $result->{'Status'} && defined $result->{'OrderId'}
711 && grep($_ eq $result->{'Status'}, @Net::Ikano::orderStatus);
713 $svc_dsl->pushed(time);
714 $svc_dsl->last_pull((time)+1);
715 $svc_dsl->vendor_order_id($result->{'OrderId'});
716 $svc_dsl->vendor_order_status($result->{'Status'});
717 $svc_dsl->monitored('Y');
718 local $FS::svc_Common::noexport_hack = 1;
719 $result = $svc_dsl->replace;
720 return "Error setting DSL fields: $result" if $result;
723 return "Cancelling anything other than NEW orders in COMPLETED status is "
724 . "not currently implemented";
730 my( $self, $svc_dsl, $type ) = (shift, shift, shift);
732 my $result = $self->valid_order($svc_dsl,'statuschg');
733 return $result unless $result eq '';
735 # get the DSLServiceId
736 $result = $self->ikano_command('CUSTOMERLOOKUP',
737 { PhoneNumber => $svc_dsl->phonenum } );
738 return $result unless ref($result); # scalar (string) is an error
739 return 'No DSLServiceId found' unless defined $result->{'DSLServiceId'};
740 my $DSLServiceId = $result->{'DSLServiceId'};
742 $result = $self->ikano_command('ACCOUNTSTATUSCHANGE',
743 { DSLPhoneNumber => $svc_dsl->phonenum,
744 DSLServiceId => $DSLServiceId,
747 return $result unless ref($result); # scalar (string) is an error
751 sub _export_suspend {
752 my( $self, $svc_dsl ) = (shift, shift);
753 $self->statuschg($svc_dsl,"SUSPEND");
756 sub _export_unsuspend {
757 my( $self, $svc_dsl ) = (shift, shift);
758 $self->statuschg($svc_dsl,"UNSUSPEND");