11 use vars qw($VERSION @ISA $DEBUG @login_opt); #$WARN );
12 # @EXPORT @EXPORT_OK %EXPORT_TAGS);
15 # This allows declaration use Net-Artera ':all';
16 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
18 #%EXPORT_TAGS = ( 'all' => [ qw(
22 #@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
33 Net::Artera - Perl extension for Artera XML API.
39 my $connection = new Net::Artera (
40 'rid' => 'reseller_id',
41 'username' => 'reseller_username',
42 'password' => 'reseller_password',
46 my $result = $artera->newOrder(
50 'aid' => $affiliatenum,
61 if ( $result->{'id'} == 1 ) {
63 $serialnum = $result->{'ASN'};
64 $keycode = $result->{'AKC'};
67 die $result->{'message'};
74 This is a Perl module which speaks the Artera XML API.
75 See <http://www.arteraturbo.com>. Artera Resellers can use this module
76 to access some features of the API.
82 =item new [ OPTIONS_HASHREF | OPTION => VALUE ... ]
84 Constructor. Options can be passed as a hash reference or a list. Options are
87 Available options are:
91 =item username - Reseller username
93 =item password - Reseller password
95 =item rid - Reseller ID (RID)
97 =item pid - Product ID (PID).
99 =item production - if set true, uses the production server instead of the staging server.
105 @login_opt = qw( RID Username Password );
109 my $class = ref($proto) || $proto;
111 bless ($self, $class);
113 my $opt = $self->_lc_hash_or_hashref(@_);
114 $self->{$_} = $opt->{$_} for map lc($_), @login_opt;
116 if ( defined($opt->{'production'}) && $opt->{'production'} ) {
117 $self->{'url'} = 'https://secure.arteragroup.com/';
119 $self->{'url'} = 'http://staging.arteragroup.com/';
121 $self->{'url'} .= 'Wizards/wsapi/31/APIService.asmx';
123 $self->{'ua'} = LWP::UserAgent->new;
125 warn "\n$self created: ". Dumper($self) if $DEBUG;
130 sub _lc_hash_or_hashref {
132 my $opt = ref($_[0]) ? shift : {@_};
133 my $gratuitous = { map { lc($_) => $opt->{$_} } keys %$opt };
137 =item newTrial [ OPTIONS_HASHREF | OPTION => VALUE ... ]
139 Options can be passed as a hash reference or a list. Options are
142 Available options are:
146 =item email (required)
148 =item cname (required) - Customer's name
150 =item ref (required) - Reseller's own order reference
152 =item pid (required) - Artera Product ID
154 =item priceid (required) - Artera Price ID
156 =item aid - Affiliate ID number used when the Reseller wants to track some type of sales channel beneath them.
168 =item cid* - Country ID. Defaults to 2 (USA). Can be specified as a numeric CID or as an ISO 3166 two-letter country code or full name.
176 *These fields are optional, but must be supplied as a set.
178 Returns a hash reference with the following keys (these keys B<are>
183 =item id - This is the Result ID to indicate success or failure: 1 for success, anything else for failure
185 =item message - Some descriptive text regarding the success or failure
187 =item ASN - The Artera Serial Number
189 =item AKC - The Artera Key Code
191 =item TrialID - The Artera Trial Number
193 =item Ref - The Reseller Reference
195 =item CustomerID - Artera's CustomerID
197 =item TrialLength - Trial Length
203 my $opt = $self->_lc_hash_or_hashref(@_);
204 $self->_newX('Trial', $opt);
207 =item newOrder [ OPTIONS_HASHREF | OPTION => VALUE ... ]
209 Available options are the same as B<newTrial>. Additionally the I<asn> and
210 I<akc> fields may be specified to convert a trial to an order.
216 my $opt = $self->_lc_hash_or_hashref(@_);
217 push @{$opt->{'optional_params'}}, qw( ASN AKC );
218 $self->_newX('Order', $opt);
222 my( $self, $x, $opt ) = @_;
224 if ( defined($opt->{'cid'}) ) {
225 $opt->{'cid'} = $self->_country2cid($opt->{'cid'});
227 $opt->{'cid'} = 2 if grep defined($_), qw(Add1 Add3 Add4 Zip);
230 push @{$opt->{'required_params'}},
231 qw( Email CName Ref PID PriceID );
232 push @{$opt->{'optional_params'}},
233 qw( AID Add1 Add2 Add3 Add4 Zip CID Phone Fax );
235 $self->_submit( "new$x", $opt );
282 '' => 43, #HERZEGOVINA
286 '' => 47, #MONTENEGRO
299 my( $self, $country ) = @_;
300 if ( $country =~ /^\s*(\d+)\s*$/ ) {
302 } elsif ( $country =~ /^\s*(\w\w)\s*$/ ) {
304 } elsif ( $country !~ /^\s*$/ ) {
305 $country2cid{country2code($country)};
311 =item statusChange [ OPTIONS_HASHREF | OPTION => VALUE ... ]
313 Options can be passed as a hash reference or a list. Options are
316 Available options are:
320 =item ASN (required) - Artera Serial Number
322 =item AKC (required) - Artera Key Code
324 =item StatusID (required) - Possible StatusID values are as follows:
328 =item 15 - Normal Unrestricted: re-enable a disabled Serial Number (e.g. a payment dispute has been resolved so the Serial Number needs to be re-enabled).
330 =item 16 - Disable: temporarily prohibit an end-user's serial number from working (e.g. there is a payment dispute, so you want to turn off the Serial Number until the dispute is resolved).
332 =item 17 - Terminate: permanently prohibit an end-user's Serial Number from working (e.g. subscription cancellation)
336 =item Reason - Reason for terminating
340 Returns a hash reference with the following keys (these keys B<are>
345 =item id - This is the Result ID to indicate success or failure: 1 for success, anything else for failure
347 =item message - Some descriptive text regarding the success or failure
355 my $opt = $self->_lc_hash_or_hashref(@_);
357 push @{$opt->{'required_params'}},
358 qw( ASN AKC StatusID );
359 push @{$opt->{'optional_params'}}, 'Reason';
361 $self->_submit('statusChange', $opt );
364 =item getProductStatus [ OPTIONS_HASHREF | OPTION => VALUE ... ]
366 Options can be passed as a hash reference or a list. Options are
369 Available options are:
373 =item ASN (required) - Artera Serial Number
375 =item AKC (required) - Artera Key Code
379 Returns a hash reference with the following keys (these keys B<are>
384 =item id - This is the Result ID to indicate success or failure: 1 for success, anything else for failure
386 =item message - On failure, descriptive text regarding the failure
388 =item StatusID (required) - Possible StatusID values are as follows:
392 =item 15 - Normal Unrestricted: re-enable a disabled Serial Number (e.g. a payment dispute has been resolved so the Serial Number needs to be re-enabled).
394 =item 16 - Disable: temporarily prohibit an end-user's serial number from working (e.g. there is a payment dispute, so you want to turn off the Serial Number until the dispute is resolved).
396 =item 17 - Terminate: permanently prohibit an end-user's Serial Number from working (e.g. subscription cancellation)
400 =item Description - Status description
406 sub getProductStatus {
409 my $opt = $self->_lc_hash_or_hashref(@_);
411 push @{$opt->{'required_params'}}, qw( ASN AKC );
413 my $result = $self->_submit('getProductStatus', $opt );
415 # munch results, present as flat list
416 $result->{$_} = $result->{'Status'}->{$_} foreach (qw(StatusID Description));
417 delete $result->{'Status'};
423 =item updateContentControl [ OPTIONS_HASHREF | OPTION => VALUE ... ]
425 Options can be passed as a hash reference or a list. Options are
428 Available options are:
432 =item ASN (required) - Artera Serial Number
434 =item AKC (required) - Artera Key Code
436 =item UseContentControl (required) - 0 for off, 1 for on
440 Returns a hash reference with the following keys (these keys B<are>
445 =item id - This is the Result ID to indicate success or failure: 1 for success, anything else for failure
447 =item message - Some descriptive text regarding the success or failure
453 sub updateContentControl {
456 my $opt = $self->_lc_hash_or_hashref(@_);
458 push @{$opt->{'required_params'}}, qw( ASN AKC UseContentControl );
460 $self->_submit('updateContentControl', $opt );
463 =item orderListByDate [ OPTIONS_HASHREF | OPTION => VALUE ... ]
472 my( $self, $method, $opt ) = @_;
473 my $ua = $self->{'ua'};
476 ( map { $_ => $self->{lc($_)} }
479 ( map { $_ => $opt->{lc($_)} }
480 @{$opt->{'required_params'}}
482 ( map { $_ => ( exists $opt->{lc($_)} ? $opt->{lc($_)} : '' ) }
483 @{$opt->{'optional_params'}}
486 warn "$self url $self->{url}/$method\n" if $DEBUG;
487 warn "$self request parameters: ". Dumper($param). "\n" if $DEBUG;
490 my $response = $ua->post( "$self->{'url'}/$method", $param );
492 warn "$self raw response: ". $response->content. "\n" if $DEBUG;
494 #unless ( $response->is_success ) {
495 # die $response->content;
498 my $xml = XMLin( $response->content );
499 warn "$self parsed response: ". Dumper($xml) if $DEBUG;
501 #warn "\n".$xml->{'message'}."\n" unless $xml->{'id'} == 1 or not $WARN;
511 orderListByDate is unimplemented.
515 <http://www.arteraturbo.com>
519 Ivan Kohler, E<lt>ivan-net-artera@420.amE<gt>
521 Freeside, open-source billing for ISPs: <http://www.sisd.com/freeside>
523 Not affiliated with Artera Group, Inc.
525 =head1 COPYRIGHT AND LICENSE
527 Copyright (C) 2004 Ivan Kohler
529 This library is free software; you can redistribute it and/or modify
530 it under the same terms as Perl itself.