1 package FS::part_export::infostreet;
3 use vars qw(@ISA %infostreet2cust_main);
6 @ISA = qw(FS::part_export);
8 %infostreet2cust_main = (
9 'firstName' => 'first',
11 'address1' => 'address1',
12 'address2' => 'address2',
16 'country' => 'country',
17 'phoneNumber' => 'daytime',
18 'faxNumber' => 'night',
21 sub rebless { shift; }
24 my( $self, $svc_acct ) = (shift, shift);
25 my $cust_main = $svc_acct->cust_svc->cust_pkg->cust_main;
26 my $accountID = $self->infostreet_queue( $svc_acct->svcnum,
27 'createUser', $svc_acct->username, $svc_acct->_password );
28 foreach my $infostreet_field ( keys %infostreet2cust_main ) {
29 my $error = $self->infostreet_queue( $svc_acct->svcnum,
30 'setContactField', $accountID, $infostreet_field,
31 $cust_main->getfield( $infostreet2cust_main{$infostreet_field} ) );
32 return $error if $error;
35 my @emails = grep { $_ ne 'POST' } $cust_main->invoicing_list;
37 my $error = $self->infostreet_queue( $svc_acct->svcnum,
38 'setContactField', $accountID, 'email', $emails[0] );
39 return $error if $error;
42 #this one is kinda noment-specific
43 $self->infostreet_queue( $svc_acct->svcnum,
44 'setContactField', $accountID, 'title', $cust_main->agent->agent );
49 my( $self, $new, $old ) = (shift, shift, shift);
50 return "can't change username with InfoStreet"
51 if $old->username ne $new->username;
52 return '' unless $old->_password ne $new->_password;
53 $self->infostreet_queue( $new->svcnum,
54 'passwd', $new->username, $new->_password );
58 my( $self, $svc_acct ) = (shift, shift);
59 $self->infostreet_queue( $svc_acct->svcnum,
60 'purgeAccount,releaseUsername', $svc_acct->username );
64 my( $self, $svc_acct ) = (shift, shift);
65 $self->infostreet_queue( $svc_acct->svcnum,
66 'setStatus', $svc_acct->username, 'DISABLED' );
69 sub _export_unsuspend {
70 my( $self, $svc_acct ) = (shift, shift);
71 $self->infostreet_queue( $svc_acct->svcnum,
72 'setStatus', $svc_acct->username, 'ACTIVE' );
75 sub infostreet_queue {
76 my( $self, $svcnum, $method ) = (shift, shift, shift);
77 my $queue = new FS::queue {
79 'job' => 'FS::part_export::infostreet::infostreet_command',
83 $self->option('login'),
84 $self->option('password'),
85 $self->option('groupID'),
91 sub infostreet_command { #subroutine, not method
92 my($url, $username, $password, $groupID, $method, @args) = @_;
95 if ( $method =~ /,/ ) {
96 foreach my $part ( split(/,\s*/, $method) ) {
97 infostreet_command($url, $username, $password, $groupID, $part, @args);
102 eval "use Frontier::Client;";
104 my $conn = Frontier::Client->new( url => $url );
105 my $key_result = $conn->call( 'authenticate', $username, $password, $groupID);
106 my %key_result = _infostreet_parse($key_result);
107 die $key_result{error} unless $key_result{success};
108 my $key = $key_result{data};
110 #my $result = $conn->call($method, $key, @args);
111 my $result = $conn->call($method, $key, map { $conn->string($_) } @args);
112 my %result = _infostreet_parse($result);
113 die $result{error} unless $result{success};
119 #sub infostreet_command_byid { #subroutine, not method;
120 # my($url, $username, $password, $groupID, $method, @args ) = @_;
126 sub _infostreet_parse { #subroutine, not method
129 my $value = $arg->{$_};
131 $value = $value->value()
132 if ref($value) && $value->isa('Frontier::RPC2::DataType');