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);
59 # If a quota has been specified set the quota because it is not the default
60 $err_or_queue = $self->infostreet_queueSetQuota( $svc_acct->svcnum,
61 $svc_acct->username, $svc_acct->quota ) if $svc_acct->quota;
62 return $err_or_queue unless ref($err_or_queue);
64 my $error = $err_or_queue->depend_insert( $jobnum );
65 return $error if $error;
67 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
74 my( $self, $new, $old ) = (shift, shift, shift);
75 return "can't change username with InfoStreet"
76 if $old->username ne $new->username;
78 # If the quota has changed then do the export to setQuota
79 my $err_or_queue = $self->infostreet_queueSetQuota( $new->svcnum, $new->username, $new->quota )
80 if ( $old->quota != $new->quota );
81 return $err_or_queue unless ref($err_or_queue);
84 return '' unless $old->_password ne $new->_password;
85 $self->infostreet_queue( $new->svcnum,
86 'passwd', $new->username, $new->_password );
90 my( $self, $svc_acct ) = (shift, shift);
91 $self->infostreet_queue( $svc_acct->svcnum,
92 'purgeAccount,releaseUsername', $svc_acct->username );
96 my( $self, $svc_acct ) = (shift, shift);
97 $self->infostreet_queue( $svc_acct->svcnum,
98 'setStatus', $svc_acct->username, 'DISABLED' );
101 sub _export_unsuspend {
102 my( $self, $svc_acct ) = (shift, shift);
103 $self->infostreet_queue( $svc_acct->svcnum,
104 'setStatus', $svc_acct->username, 'ACTIVE' );
107 sub infostreet_queue {
108 my( $self, $svcnum, $method ) = (shift, shift, shift);
109 my $queue = new FS::queue {
111 'job' => 'FS::part_export::infostreet::infostreet_command',
114 $self->option('url'),
115 $self->option('login'),
116 $self->option('password'),
117 $self->option('groupID'),
124 sub infostreet_err_or_queue {
125 my( $self, $svcnum, $method ) = (shift, shift, shift);
126 my $queue = new FS::queue {
128 'job' => 'FS::part_export::infostreet::infostreet_command',
131 $self->option('url'),
132 $self->option('login'),
133 $self->option('password'),
134 $self->option('groupID'),
140 sub infostreet_queueContact {
141 my( $self, $svcnum ) = (shift, shift);
142 my $queue = new FS::queue {
144 'job' => 'FS::part_export::infostreet::infostreet_setContact',
147 $self->option('url'),
148 $self->option('login'),
149 $self->option('password'),
150 $self->option('groupID'),
155 sub infostreet_setContact {
156 my($url, $is_username, $is_password, $groupID, $username, %contact_info) = @_;
157 my $accountID = infostreet_command($url, $is_username, $is_password, $groupID,
158 'getAccountID', $username);
159 foreach my $field ( keys %contact_info ) {
160 infostreet_command($url, $is_username, $is_password, $groupID,
161 'setContactField', [ 'int'=>$accountID ], $field, $contact_info{$field} );
166 sub infostreet_queueSetQuota {
168 my( $self, $svcnum) = (shift, shift);
169 my $queue = new FS::queue {
171 'job' => 'FS::part_export::infostreet::infostreet_setQuota',
175 $self->option('url'),
176 $self->option('login'),
177 $self->option('password'),
178 $self->option('groupID'),
184 sub infostreet_setQuota {
185 my($url, $is_username, $is_password, $groupID, $username, $quota) = @_;
186 infostreet_command($url, $is_username, $is_password, $groupID, 'setQuota', $username, [ 'int'=> $quota ] );
190 sub infostreet_command { #subroutine, not method
191 my($url, $username, $password, $groupID, $method, @args) = @_;
193 warn "[FS::part_export::infostreet] $method ".join(' ', @args)."\n" if $DEBUG;
196 if ( $method =~ /,/ ) {
197 foreach my $part ( split(/,\s*/, $method) ) {
198 infostreet_command($url, $username, $password, $groupID, $part, @args);
203 eval "use Frontier::Client;";
206 eval 'sub Frontier::RPC2::String::repr {
209 $value =~ s/([&<>\"])/$Frontier::RPC2::char_entities{$1}/ge;
214 my $conn = Frontier::Client->new( url => $url );
215 my $key_result = $conn->call( 'authenticate', $username, $password, $groupID);
216 my %key_result = _infostreet_parse($key_result);
217 die $key_result{error} unless $key_result{success};
218 my $key = $key_result{data};
220 #my $result = $conn->call($method, $key, @args);
221 my $result = $conn->call( $method, $key,
224 my( $type, $value) = @{$_};
225 $conn->$type($value);
230 my %result = _infostreet_parse($result);
231 die $result{error} unless $result{success};
237 #sub infostreet_command_byid { #subroutine, not method;
238 # my($url, $username, $password, $groupID, $method, @args ) = @_;
244 sub _infostreet_parse { #subroutine, not method
247 my $value = $arg->{$_};
249 $value = $value->value()
250 if ref($value) && $value->isa('Frontier::RPC2::DataType');