1 package FS::part_export::infostreet;
3 use vars qw(@ISA %infostreet2cust_main $DEBUG);
7 @ISA = qw(FS::part_export);
11 %infostreet2cust_main = (
12 'firstName' => 'first',
14 'address1' => 'address1',
15 'address2' => 'address2',
19 'country' => 'country',
20 'phoneNumber' => 'daytime',
21 'faxNumber' => 'night', #noment-request...
24 sub rebless { shift; }
27 my( $self, $svc_acct ) = (shift, shift);
28 my $cust_main = $svc_acct->cust_svc->cust_pkg->cust_main;
30 local $SIG{HUP} = 'IGNORE';
31 local $SIG{INT} = 'IGNORE';
32 local $SIG{QUIT} = 'IGNORE';
33 local $SIG{TERM} = 'IGNORE';
34 local $SIG{TSTP} = 'IGNORE';
35 local $SIG{PIPE} = 'IGNORE';
36 my $oldAutoCommit = $FS::UID::AutoCommit;
37 local $FS::UID::AutoCommit = 0;
40 my $err_or_queue = $self->infostreet_err_or_queue( $svc_acct->svcnum,
41 'createUser', $svc_acct->username, $svc_acct->_password );
42 return $err_or_queue unless ref($err_or_queue);
43 my $jobnum = $err_or_queue->jobnum;
45 my %contact_info = ( map {
46 $_ => $cust_main->getfield( $infostreet2cust_main{$_} );
47 } keys %infostreet2cust_main );
49 my @emails = grep { $_ ne 'POST' } $cust_main->invoicing_list;
50 $contact_info{'email'} = $emails[0] if @emails;
52 #this one is kinda noment-specific
53 $contact_info{'organization'} = $cust_main->agent->agent;
55 $err_or_queue = $self->infostreet_queueContact( $svc_acct->svcnum,
56 $svc_acct->username, %contact_info );
57 return $err_or_queue unless ref($err_or_queue);
58 my $error = $err_or_queue->depend_insert( $jobnum );
59 return $error if $error;
61 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
68 my( $self, $new, $old ) = (shift, shift, shift);
69 return "can't change username with InfoStreet"
70 if $old->username ne $new->username;
71 return '' unless $old->_password ne $new->_password;
72 $self->infostreet_queue( $new->svcnum,
73 'passwd', $new->username, $new->_password );
77 my( $self, $svc_acct ) = (shift, shift);
78 $self->infostreet_queue( $svc_acct->svcnum,
79 'purgeAccount,releaseUsername', $svc_acct->username );
83 my( $self, $svc_acct ) = (shift, shift);
84 $self->infostreet_queue( $svc_acct->svcnum,
85 'setStatus', $svc_acct->username, 'DISABLED' );
88 sub _export_unsuspend {
89 my( $self, $svc_acct ) = (shift, shift);
90 $self->infostreet_queue( $svc_acct->svcnum,
91 'setStatus', $svc_acct->username, 'ACTIVE' );
94 sub infostreet_queue {
95 my( $self, $svcnum, $method ) = (shift, shift, shift);
96 my $queue = new FS::queue {
98 'job' => 'FS::part_export::infostreet::infostreet_command',
101 $self->option('url'),
102 $self->option('login'),
103 $self->option('password'),
104 $self->option('groupID'),
111 sub infostreet_err_or_queue {
112 my( $self, $svcnum, $method ) = (shift, shift, shift);
113 my $queue = new FS::queue {
115 'job' => 'FS::part_export::infostreet::infostreet_command',
118 $self->option('url'),
119 $self->option('login'),
120 $self->option('password'),
121 $self->option('groupID'),
127 sub infostreet_queueContact {
128 my( $self, $svcnum ) = (shift, shift);
129 my $queue = new FS::queue {
131 'job' => 'FS::part_export::infostreet::infostreet_setContact',
134 $self->option('url'),
135 $self->option('login'),
136 $self->option('password'),
137 $self->option('groupID'),
142 sub infostreet_setContact {
143 my($url, $is_username, $is_password, $groupID, $username, %contact_info) = @_;
144 my $accountID = infostreet_command($url, $is_username, $is_password, $groupID,
145 'getAccountID', $username);
146 foreach my $field ( keys %contact_info ) {
147 infostreet_command($url, $is_username, $is_password, $groupID,
148 'setContactField', [ 'int'=>$accountID ], $field, $contact_info{$field} );
153 sub infostreet_command { #subroutine, not method
154 my($url, $username, $password, $groupID, $method, @args) = @_;
156 warn "[FS::part_export::infostreet] $method ".join(' ', @args)."\n" if $DEBUG;
159 if ( $method =~ /,/ ) {
160 foreach my $part ( split(/,\s*/, $method) ) {
161 infostreet_command($url, $username, $password, $groupID, $part, @args);
166 eval "use Frontier::Client;";
169 eval 'sub Frontier::RPC2::String::repr {
172 $value =~ s/([&<>\"])/$Frontier::RPC2::char_entities{$1}/ge;
177 my $conn = Frontier::Client->new( url => $url );
178 my $key_result = $conn->call( 'authenticate', $username, $password, $groupID);
179 my %key_result = _infostreet_parse($key_result);
180 die $key_result{error} unless $key_result{success};
181 my $key = $key_result{data};
183 #my $result = $conn->call($method, $key, @args);
184 my $result = $conn->call( $method, $key,
187 my( $type, $value) = @{$_};
188 $conn->$type($value);
193 my %result = _infostreet_parse($result);
194 die $result{error} unless $result{success};
200 #sub infostreet_command_byid { #subroutine, not method;
201 # my($url, $username, $password, $groupID, $method, @args ) = @_;
207 sub _infostreet_parse { #subroutine, not method
210 my $value = $arg->{$_};
212 $value = $value->value()
213 if ref($value) && $value->isa('Frontier::RPC2::DataType');