1 package FS::part_export::infostreet;
3 use vars qw(@ISA %infostreet2cust_main);
7 @ISA = qw(FS::part_export);
9 %infostreet2cust_main = (
10 'firstName' => 'first',
12 'address1' => 'address1',
13 'address2' => 'address2',
17 'country' => 'country',
18 'phoneNumber' => 'daytime',
19 'faxNumber' => 'night', #noment-request...
22 sub rebless { shift; }
25 my( $self, $svc_acct ) = (shift, shift);
26 my $cust_main = $svc_acct->cust_svc->cust_pkg->cust_main;
28 local $SIG{HUP} = 'IGNORE';
29 local $SIG{INT} = 'IGNORE';
30 local $SIG{QUIT} = 'IGNORE';
31 local $SIG{TERM} = 'IGNORE';
32 local $SIG{TSTP} = 'IGNORE';
33 local $SIG{PIPE} = 'IGNORE';
34 my $oldAutoCommit = $FS::UID::AutoCommit;
35 local $FS::UID::AutoCommit = 0;
38 my $err_or_queue = $self->infostreet_err_or_queue( $svc_acct->svcnum,
39 'createUser', $svc_acct->username, $svc_acct->_password );
40 return $err_or_queue unless ref($err_or_queue);
41 my $jobnum = $err_or_queue->jobnum;
43 my %contact_info = ( map {
44 $_ => $cust_main->getfield( $infostreet2cust_main{$_} );
45 } keys %infostreet2cust_main );
47 my @emails = grep { $_ ne 'POST' } $cust_main->invoicing_list;
48 $contact_info{'email'} = $emails[0] if @emails;
50 #this one is kinda noment-specific
51 $contact_info{'title'} = $cust_main->agent->agent;
53 $err_or_queue = $self->infostreet_queueContact( $svc_acct->svcnum,
54 $svc_acct->username, %contact_info );
55 return $err_or_queue unless ref($err_or_queue);
56 my $error = $err_or_queue->depend_insert( $jobnum );
57 return $error if $error;
59 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
66 my( $self, $new, $old ) = (shift, shift, shift);
67 return "can't change username with InfoStreet"
68 if $old->username ne $new->username;
69 return '' unless $old->_password ne $new->_password;
70 $self->infostreet_queue( $new->svcnum,
71 'passwd', $new->username, $new->_password );
75 my( $self, $svc_acct ) = (shift, shift);
76 $self->infostreet_queue( $svc_acct->svcnum,
77 'purgeAccount,releaseUsername', $svc_acct->username );
81 my( $self, $svc_acct ) = (shift, shift);
82 $self->infostreet_queue( $svc_acct->svcnum,
83 'setStatus', $svc_acct->username, 'DISABLED' );
86 sub _export_unsuspend {
87 my( $self, $svc_acct ) = (shift, shift);
88 $self->infostreet_queue( $svc_acct->svcnum,
89 'setStatus', $svc_acct->username, 'ACTIVE' );
92 sub infostreet_queue {
93 my( $self, $svcnum, $method ) = (shift, shift, shift);
94 my $queue = new FS::queue {
96 'job' => 'FS::part_export::infostreet::infostreet_command',
100 $self->option('login'),
101 $self->option('password'),
102 $self->option('groupID'),
109 sub infostreet_err_or_queue {
110 my( $self, $svcnum, $method ) = (shift, shift, shift);
111 my $queue = new FS::queue {
113 'job' => 'FS::part_export::infostreet::infostreet_command',
116 $self->option('url'),
117 $self->option('login'),
118 $self->option('password'),
119 $self->option('groupID'),
125 sub infostreet_queueContact {
126 my( $self, $svcnum ) = (shift, shift);
127 my $queue = new FS::queue {
129 'job' => 'FS::part_export::infostreet::infostreet_setContact',
132 $self->option('url'),
133 $self->option('login'),
134 $self->option('password'),
135 $self->option('groupID'),
140 sub infostreet_setContact {
141 my($url, $is_username, $is_password, $groupID, $username, %contact_info) = @_;
142 my $accountID = infostreet_command($url, $is_username, $is_password, $groupID,
143 'getAccountID', $username);
144 foreach my $field ( %contact_info ) {
145 infostreet_command($url, $is_username, $is_password, $groupID,
146 'setContactField', $field, $contact_info{$field} );
151 sub infostreet_command { #subroutine, not method
152 my($url, $username, $password, $groupID, $method, @args) = @_;
155 if ( $method =~ /,/ ) {
156 foreach my $part ( split(/,\s*/, $method) ) {
157 infostreet_command($url, $username, $password, $groupID, $part, @args);
162 eval "use Frontier::Client;";
164 my $conn = Frontier::Client->new( url => $url );
165 my $key_result = $conn->call( 'authenticate', $username, $password, $groupID);
166 my %key_result = _infostreet_parse($key_result);
167 die $key_result{error} unless $key_result{success};
168 my $key = $key_result{data};
170 #my $result = $conn->call($method, $key, @args);
171 my $result = $conn->call($method, $key, map { $conn->string($_) } @args);
172 my %result = _infostreet_parse($result);
173 die $result{error} unless $result{success};
179 #sub infostreet_command_byid { #subroutine, not method;
180 # my($url, $username, $password, $groupID, $method, @args ) = @_;
186 sub _infostreet_parse { #subroutine, not method
189 my $value = $arg->{$_};
191 $value = $value->value()
192 if ref($value) && $value->isa('Frontier::RPC2::DataType');