+sub export_expire {
+ my($self, $svc_dsl, $date) = (shift, shift, shift);
+
+ return 'Invalid operation - Import Mode is enabled' if $self->import_mode;
+
+ my $result = $self->valid_order($svc_dsl,'expire');
+ return $result unless $result eq '';
+
+ # for now allow a proper cancel only on New orders in Completed status
+ #XXX: add support for some other cases in future
+
+ if($svc_dsl->vendor_order_type eq 'NEW'
+ && $svc_dsl->vendor_order_status eq 'COMPLETED') {
+
+ my $contactTN = $svc_dsl->cust_svc->cust_pkg->cust_main->daytime;
+ $contactTN =~ s/[^0-9]//g;
+
+ my %vendor_pkg_ids = $svc_dsl->cust_svc->cust_pkg->part_pkg->vendor_pkg_ids;
+ my $ProductCustomId = $vendor_pkg_ids{$self->exportnum};
+
+ # we are now a cancel order
+ $svc_dsl->desired_due_date($date);
+ $svc_dsl->vendor_order_type('CANCEL');
+
+ my $args = {
+ orderType => 'CANCEL',
+ ProductCustomId => $ProductCustomId,
+ TermsId => $self->qual2termsid($svc_dsl->vendor_qual_id,$ProductCustomId),
+ DSLPhoneNumber => $svc_dsl->loop_type eq '0' ? 'STANDALONE'
+ : $svc_dsl->phonenum,
+ Password => $svc_dsl->password,
+ PrequalId => $svc_dsl->vendor_qual_id,
+ CompanyName => $svc_dsl->company,
+ FirstName => $svc_dsl->first,
+ LastName => $svc_dsl->last,
+ MiddleName => '',
+ ContactMethod => 'PHONE',
+ ContactPhoneNumber => $contactTN,
+ ContactEmail => 'x@x.xx',
+ ContactFax => '',
+ DateToOrder => time2str("%Y-%m-%d",$date),
+ RequestClientIP => '127.0.0.1',
+ IspChange => 'NO',
+ IspPrevious => '',
+ CurrentProvider => '',
+ };
+
+ $args->{'VirtualPhoneNumber'} = $svc_dsl->phonenum
+ if $svc_dsl->loop_type eq '0';
+
+ $result = $self->ikano_command('ORDER',$args);
+ return $result unless ref($result); # scalar (string) is an error
+
+ # now we're getting an OrderResponse which should have one Order in it
+ warn "$me _export_insert OrderResponse hash:\n".Dumper($result)
+ if $self->option('debug');
+
+ return 'Invalid order response' unless defined $result->{'Order'};
+ $result = $result->{'Order'};
+
+ return 'No/invalid order id or status returned'
+ unless defined $result->{'Status'} && defined $result->{'OrderId'}
+ && grep($_ eq $result->{'Status'}, @Net::Ikano::orderStatus);
+
+ $svc_dsl->pushed(time);
+ $svc_dsl->last_pull((time)+1);
+ $svc_dsl->vendor_order_id($result->{'OrderId'});
+ $svc_dsl->vendor_order_status($result->{'Status'});
+ $svc_dsl->monitored('Y');
+ local $FS::svc_Common::noexport_hack = 1;
+ $result = $svc_dsl->replace;
+ return "Error setting DSL fields: $result" if $result;
+ }
+ else {
+ return "Cancelling anything other than NEW orders in COMPLETED status is "
+ . "not currently implemented";
+ }
+ '';
+}
+