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>
41 sub rebless { shift; }
46 my $artera = new Net::Artera (
47 map { $_ => $self->option($_) }
48 qw( rid username password production )
54 my($self, $svc_external) = (shift, shift);
56 # want the ASN (serial) and AKC (key code) right away
58 eval "use Net::Artera;";
61 my $artera = $self->_new_Artera;
63 my $cust_pkg = $svc_external->cust_svc->cust_pkg;
64 my $part_pkg = $cust_pkg->part_pkg;
65 my @svc_acct = grep { $_->table eq 'svc_acct' }
67 sort { my $svcpart = $part_pkg->svcpart('svc_acct');
68 ($b->svcpart==$svcpart) cmp ($a->svcpart==$svcpart); }
69 qsearch('cust_svc', { 'pkgnum' => $cust_pkg->pkgnum } );
70 my $email = scalar(@svc_acct) ? $svc_acct[0]->email : '';
72 my $cust_main = $cust_pkg->cust_main;
74 my $result = $artera->newOrder(
75 'pid' => $self->option('pid'),
76 'priceid' => $self->option('priceid'),
78 'cname' => $cust_main->name,
79 'ref' => $svc_external->svcnum,
80 'aid' => ( $self->option('agent_aid') ? $cust_main->agentnum : '' ),
81 'add1' => $cust_main->address1,
82 'add2' => $cust_main->address2,
83 'add3' => $cust_main->city,
84 'add4' => $cust_main->state,
85 'zip' => $cust_main->zip,
86 'cid' => $cust_main->country,
87 'phone' => $cust_main->daytime || $cust_main->night,
88 'fax' => $cust_main->fax,
91 if ( $result->{'id'} == 1 ) {
92 my $new = new FS::svc_external { $svc_external->hash };
93 $new->id($result->{'ASN'});
94 $new->title($result->{'AKC'});
95 $new->replace($svc_external);
97 $result->{'message'} || 'No response from Artera';
101 sub _export_replace {
102 my( $self, $new, $old ) = (shift, shift, shift);
103 #except the first time, hehe..
104 #return "can't change serial number with Artera"
105 # if $old->id != $new->id;
106 #return "can't change key code with Artera"
107 # if $old->title ne $new->title;
112 my( $self, $svc_external ) = (shift, shift);
113 $self->StatusChange(17, $svc_external);
116 sub _export_suspend {
117 my( $self, $svc_external ) = (shift, shift);
118 $self->StatusChange(16, $svc_external);
121 sub _export_unsuspend {
122 my( $self, $svc_external ) = (shift, shift);
123 $self->StatusChange(15, $svc_external);
127 my( $self, $status, $svc_external ) = @_;
129 my $artera = $self->_new_Artera;
131 my $result = $artera->StatusChange(
132 'asn' => sprintf('%010d', $svc_external->id),
133 'akc' => $svc_external->title,
134 'statusid' => $status,
139 : $result->{'message'};