1 package FS::part_export::artera_turbo;
3 use vars qw(@ISA %info);
5 use FS::Record qw(qsearch);
10 @ISA = qw(FS::part_export);
12 tie my %options, 'Tie::IxHash',
13 'rid' => { 'label' => 'Reseller ID (RID)' },
14 'username' => { 'label' => 'Reseller username', },
15 'password' => { 'label' => 'Reseller password', },
16 'pid' => { 'label' => 'Artera Product ID', },
17 'priceid' => { 'label' => 'Artera Price ID', },
18 'agent_aid' => { 'label' => 'Export agentnum values to Artera AID',
21 'production' => { 'label' => 'Production mode (leave unchecked for staging)',
27 'svc' => 'svc_external',
28 #'svc' => [qw( svc_acct svc_forward )],
30 'Real-time export to Artera Turbo Reseller API',
31 'options' => \%options,
34 Real-time export to <a href="http://www.arteraturbo.com/">Artera Turbo</a>
35 Reseller API. Requires installation of
36 <a href="http://search.cpan.org/dist/Net-Artera">Net::Artera</a>
37 from CPAN. You probably also want to:
39 <LI>In the configuraiton UI section: set the <B>svc_external-skip_manual</B> and <B>svc_external-display_type</B> configuration values.
40 <LI>In the message catalog: set <B>svc_external-id</B> to <I>Artera Serial Number</I> and set <B>svc_external-title</B> to <I>Artera Key Code</I>.
45 sub rebless { shift; }
50 my $artera = new Net::Artera (
51 map { $_ => $self->option($_) }
52 qw( rid username password production )
58 my($self, $svc_external) = (shift, shift);
60 # want the ASN (serial) and AKC (key code) right away
62 eval "use Net::Artera;";
65 my $artera = $self->_new_Artera;
67 my $cust_pkg = $svc_external->cust_svc->cust_pkg;
68 my $part_pkg = $cust_pkg->part_pkg;
69 my @svc_acct = grep { $_->table eq 'svc_acct' }
71 sort { my $svcpart = $part_pkg->svcpart('svc_acct');
72 ($b->svcpart==$svcpart) cmp ($a->svcpart==$svcpart); }
73 qsearch('cust_svc', { 'pkgnum' => $cust_pkg->pkgnum } );
74 my $email = scalar(@svc_acct) ? $svc_acct[0]->email : '';
76 my $cust_main = $cust_pkg->cust_main;
78 my $result = $artera->newOrder(
79 'pid' => $self->option('pid'),
80 'priceid' => $self->option('priceid'),
82 'cname' => $cust_main->name,
83 'ref' => $svc_external->svcnum,
84 'aid' => ( $self->option('agent_aid') ? $cust_main->agentnum : '' ),
85 'add1' => $cust_main->address1,
86 'add2' => $cust_main->address2,
87 'add3' => $cust_main->city,
88 'add4' => $cust_main->state,
89 'zip' => $cust_main->zip,
90 'cid' => $cust_main->country,
91 'phone' => $cust_main->daytime || $cust_main->night,
92 'fax' => $cust_main->fax,
95 if ( $result->{'id'} == 1 ) {
96 my $new = new FS::svc_external { $svc_external->hash };
97 $new->id($result->{'ASN'});
98 $new->title($result->{'AKC'});
99 $new->replace($svc_external);
101 $result->{'message'} || 'No response from Artera';
105 sub _export_replace {
106 my( $self, $new, $old ) = (shift, shift, shift);
107 return "can't change serial number with Artera"
108 if $old->id != $new->id && $old->id;
109 return "can't change key code with Artera"
110 if $old->title ne $new->title && $old->title;
115 my( $self, $svc_external ) = (shift, shift);
116 $self->StatusChange(17, $svc_external);
119 sub _export_suspend {
120 my( $self, $svc_external ) = (shift, shift);
121 $self->StatusChange(16, $svc_external);
124 sub _export_unsuspend {
125 my( $self, $svc_external ) = (shift, shift);
126 $self->StatusChange(15, $svc_external);
130 my( $self, $status, $svc_external ) = @_;
132 my $artera = $self->_new_Artera;
134 my $result = $artera->StatusChange(
135 'asn' => sprintf('%010d', $svc_external->id),
136 'akc' => $svc_external->title,
137 'statusid' => $status,
142 : $result->{'message'};