X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fartera_turbo.pm;h=e22bbf2af2b7ab134d590290119d96169ab8b940;hb=9aee669886202be7035e6c6049fc71bc99dd3013;hp=af4c79052ecf50b055814c513f560d4dff6e4c3b;hpb=f7fd2a3e34da751cbc02bbf215e99c6dc89adc15;p=freeside.git
diff --git a/FS/FS/part_export/artera_turbo.pm b/FS/FS/part_export/artera_turbo.pm
index af4c79052..e22bbf2af 100644
--- a/FS/FS/part_export/artera_turbo.pm
+++ b/FS/FS/part_export/artera_turbo.pm
@@ -25,6 +25,9 @@ tie my %options, 'Tie::IxHash',
'debug' => { 'label' => 'Enable debug logging',
'type' => 'checkbox',
},
+ 'enable_edit' => { 'label' => 'Enable local editing of Artera serial numbers and key codes (note that the changes will NOT be exported to Artera)',
+ 'type' => 'checkbox',
+ },
;
%info = (
@@ -34,13 +37,14 @@ tie my %options, 'Tie::IxHash',
'Real-time export to Artera Turbo Reseller API',
'options' => \%options,
#'nodomain' => 'Y',
+ 'no_machine' => 1,
'notes' => <<'END'
Real-time export to Artera Turbo
Reseller API. Requires installation of
Net::Artera
from CPAN. You probably also want to:
- - In the configuraiton UI section: set the svc_external-skip_manual and svc_external-display_type configuration values.
+
- In the configuration UI section: set the svc_external-skip_manual and svc_external-display_type configuration values.
- In the message catalog: set svc_external-id to Artera Serial Number and set svc_external-title to Artera Key Code.
END
@@ -100,8 +104,8 @@ sub _export_insert {
if ( $result->{'id'} == 1 ) {
my $new = new FS::svc_external { $svc_external->hash };
- $new->id($result->{'ASN'});
- $new->title($result->{'AKC'});
+ $new->id(sprintf('%010d', $result->{'ASN'}));
+ $new->title( substr('0000000000'.uc($result->{'AKC'}), -10) );
$new->replace($svc_external);
} else {
$result->{'message'} || 'No response from Artera';
@@ -110,6 +114,7 @@ sub _export_insert {
sub _export_replace {
my( $self, $new, $old ) = (shift, shift, shift);
+ return '' if $self->option('enable_edit');
return "can't change serial number with Artera"
if $old->id != $new->id && $old->id;
return "can't change key code with Artera"
@@ -119,36 +124,58 @@ sub _export_replace {
sub _export_delete {
my( $self, $svc_external ) = (shift, shift);
- $self->statusChange(17, $svc_external);
+ $self->queue_statusChange(17, $svc_external);
}
sub _export_suspend {
my( $self, $svc_external ) = (shift, shift);
- $self->statusChange(16, $svc_external);
+ $self->queue_statusChange(16, $svc_external);
}
sub _export_unsuspend {
my( $self, $svc_external ) = (shift, shift);
- $self->statusChange(15, $svc_external);
+ $self->queue_statusChange(15, $svc_external);
}
-sub statusChange {
+sub queue_statusChange {
my( $self, $status, $svc_external ) = @_;
+ my $queue = new FS::queue {
+ 'svcnum' => $svc_external->svcnum,
+ 'job' => 'FS::part_export::artera_turbo::statusChange',
+ };
+ $queue->insert(
+ ( map { $self->option($_) }
+ qw( rid username password production ) ),
+ $status,
+ $svc_external->id,
+ $svc_external->title,
+ $self->option('debug'),
+ );
+}
+
+sub statusChange {
+ my( $rid, $username, $password, $prod, $status, $id, $title, $debug ) = @_;
+
eval "use Net::Artera;";
return $@ if $@;
- $Net::Artera::DEBUG = 1 if $self->option('debug');
- my $artera = $self->_new_Artera;
+ $Net::Artera::DEBUG = 1 if $debug;
+
+ my $artera = new Net::Artera (
+ 'rid' => $rid,
+ 'username' => $username,
+ 'password' => $password,
+ 'production' => $prod,
+ );
my $result = $artera->statusChange(
- 'asn' => sprintf('%010d', $svc_external->id),
- 'akc' => $svc_external->title,
+ 'asn' => sprintf('%010d', $id),
+ 'akc' => substr("0000000000$title", -10),
'statusid' => $status,
);
- $result->{'id'} == 1
- ? ''
- : $result->{'message'};
+ die $result->{'message'} unless $result->{'id'} == 1;
+
}
1;