X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fartera_turbo.pm;h=bbc6be945d1d6430a3fd9df19a43617477aeede7;hb=e96a3fd1c8ee8c711a7e119c0937da6866bbd4f0;hp=60cafc34fdbe951045fe3d23bfdc5eeb64a6320e;hpb=dbc6a01ed6a3b4373b01bf985ca735386dd047d4;p=freeside.git
diff --git a/FS/FS/part_export/artera_turbo.pm b/FS/FS/part_export/artera_turbo.pm
index 60cafc34f..bbc6be945 100644
--- a/FS/FS/part_export/artera_turbo.pm
+++ b/FS/FS/part_export/artera_turbo.pm
@@ -18,9 +18,16 @@ tie my %options, 'Tie::IxHash',
'agent_aid' => { 'label' => 'Export agentnum values to Artera AID',
'type' => 'checkbox',
},
+ 'aid' => { 'label' => 'Artera Agent ID to use if not using agentnum values', },
'production' => { 'label' => 'Production mode (leave unchecked for staging)',
'type' => 'checkbox',
},
+ '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,7 +41,11 @@ tie my %options, 'Tie::IxHash',
Real-time export to Artera Turbo
Reseller API. Requires installation of
Net::Artera
-from CPAN.
+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 message catalog: set svc_external-id to Artera Serial Number and set svc_external-title to Artera Key Code.
+
END
);
@@ -57,7 +68,7 @@ sub _export_insert {
eval "use Net::Artera;";
return $@ if $@;
-
+ $Net::Artera::DEBUG = 1 if $self->option('debug');
my $artera = $self->_new_Artera;
my $cust_pkg = $svc_external->cust_svc->cust_pkg;
@@ -77,7 +88,9 @@ sub _export_insert {
'email' => $email,
'cname' => $cust_main->name,
'ref' => $svc_external->svcnum,
- 'aid' => ( $self->option('agent_aid') ? $cust_main->agentnum : '' ),
+ 'aid' => ( $self->option('agent_aid')
+ ? $cust_main->agentnum
+ : $self->option('aid') ),
'add1' => $cust_main->address1,
'add2' => $cust_main->address2,
'add3' => $cust_main->city,
@@ -90,8 +103,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';
@@ -100,43 +113,68 @@ sub _export_insert {
sub _export_replace {
my( $self, $new, $old ) = (shift, shift, shift);
- #except the first time, hehe..
- #return "can't change serial number with Artera"
- # if $old->id != $new->id;
- #return "can't change key code with Artera"
- # if $old->title ne $new->title;
+ 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"
+ if $old->title ne $new->title && $old->title;
'';
}
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 $artera = $self->_new_Artera;
+ 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 ) = @_;
- my $result = $artera->StatusChange(
- 'asn' => sprintf('%010d', $svc_external->id),
- 'akc' => $svc_external->title,
+ eval "use Net::Artera;";
+ return $@ if $@;
+ $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', $id),
+ 'akc' => substr("0000000000$title", -10),
'statusid' => $status,
);
- $result->{'id'} == 1
- ? ''
- : $result->{'message'};
+ die $result->{'message'} unless $result->{'id'} == 1;
+
}
1;