remove bad doc link
[freeside.git] / fs_signup / FS-SignupClient / SignupClient.pm
1 package FS::SignupClient;
2
3 use strict;
4 use vars qw($VERSION @ISA @EXPORT_OK $fs_signupd_socket);
5 use Exporter;
6 use Socket;
7 use FileHandle;
8 use IO::Handle;
9
10 $VERSION = '0.02';
11
12 @ISA = qw( Exporter );
13 @EXPORT_OK = qw( signup_info new_customer );
14
15 $fs_signupd_socket = "/usr/local/freeside/fs_signupd_socket";
16
17 $ENV{'PATH'} ='/usr/bin:/usr/ucb:/bin';
18 $ENV{'SHELL'} = '/bin/sh';
19 $ENV{'IFS'} = " \t\n";
20 $ENV{'CDPATH'} = '';
21 $ENV{'ENV'} = '';
22 $ENV{'BASH_ENV'} = '';
23
24 my $freeside_uid = scalar(getpwnam('freeside'));
25 die "not running as the freeside user\n" if $> != $freeside_uid;
26
27 =head1 NAME
28
29 FS::SignupClient - Freeside signup client API
30
31 =head1 SYNOPSIS
32
33   use FS::SignupClient qw( signup_info new_customer );
34
35   ( $locales, $packages, $pops ) = signup_info;
36
37   $error = new_customer ( {
38     'first'            => $first,
39     'last'             => $last,
40     'ss'               => $ss,
41     'comapny'          => $company,
42     'address1'         => $address1,
43     'address2'         => $address2,
44     'city'             => $city,
45     'county'           => $county,
46     'state'            => $state,
47     'zip'              => $zip,
48     'country'          => $country,
49     'daytime'          => $daytime,
50     'night'            => $night,
51     'fax'              => $fax,
52     'payby'            => $payby,
53     'payinfo'          => $payinfo,
54     'paydate'          => $paydate,
55     'payname'          => $payname,
56     'invoicing_list'   => $invoicing_list,
57     'referral_custnum' => $referral_custnum,
58     'pkgpart'          => $pkgpart,
59     'username'         => $username,
60     '_password'        => $password,
61     'popnum'           => $popnum,
62   } );
63
64 =head1 DESCRIPTION
65
66 This module provides an API for a remote signup server.
67
68 It needs to be run as the freeside user.  Because of this, the program which
69 calls these subroutines should be written very carefully.
70
71 =head1 SUBROUTINES
72
73 =over 4
74
75 =item signup_info
76
77 Returns three array references of hash references.
78
79 The first set of hash references is of allowable locales.  Each hash reference
80 has the following keys:
81   taxnum
82   state
83   county
84   country
85
86 The second set of hash references is of allowable packages.  Each hash
87 reference has the following keys:
88   pkgpart
89   pkg
90
91 The third set of hash references is of allowable POPs (Points Of Presence).
92 Each hash reference has the following keys:
93   popnum
94   city
95   state
96   ac
97   exch
98
99 =cut
100
101 sub signup_info {
102   socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
103   connect(SOCK, sockaddr_un($fs_signupd_socket)) or die "connect: $!";
104   print SOCK "signup_info\n";
105   SOCK->flush;
106
107   chop ( my $n_cust_main_county = <SOCK> );
108   my @cust_main_county = map {
109     chop ( my $taxnum  = <SOCK> ); 
110     chop ( my $state   = <SOCK> ); 
111     chop ( my $county  = <SOCK> ); 
112     chop ( my $country = <SOCK> );
113     {
114       'taxnum'  => $taxnum,
115       'state'   => $state,
116       'county'  => $county,
117       'country' => $country,
118     };
119   } 1 .. $n_cust_main_county;
120
121   chop ( my $n_part_pkg = <SOCK> );
122   my @part_pkg = map {
123     chop ( my $pkgpart = <SOCK> ); 
124     chop ( my $pkg     = <SOCK> ); 
125     {
126       'pkgpart' => $pkgpart,
127       'pkg'     => $pkg,
128     };
129   } 1 .. $n_part_pkg;
130
131   chop ( my $n_svc_acct_pop = <SOCK> );
132   my @svc_acct_pop = map {
133     chop ( my $popnum = <SOCK> ); 
134     chop ( my $city   = <SOCK> ); 
135     chop ( my $state  = <SOCK> ); 
136     chop ( my $ac     = <SOCK> );
137     chop ( my $exch   = <SOCK> );
138     chop ( my $loc    = <SOCK> );
139     {
140       'popnum' => $popnum,
141       'city'   => $city,
142       'state'  => $state,
143       'ac'     => $ac,
144       'exch'   => $exch,
145       'loc'    => $loc,
146     };
147   } 1 .. $n_svc_acct_pop;
148
149   close SOCK;
150
151   \@cust_main_county, \@part_pkg, \@svc_acct_pop;
152 }
153
154 =item new_customer HASHREF
155
156 Adds a customer to the remote Freeside system.  Requires a hash reference as
157 a paramater with the following keys:
158   first
159   last
160   ss
161   comapny
162   address1
163   address2
164   city
165   county
166   state
167   zip
168   country
169   daytime
170   night
171   fax
172   payby
173   payinfo
174   paydate
175   payname
176   invoicing_list
177   referral_custnum
178   pkgpart
179   username
180   _password
181   popnum
182
183 Returns a scalar error message, or the empty string for success.
184
185 =cut
186
187 sub new_customer {
188   my $hashref = shift;
189
190   #things that aren't necessary in base class, but are for signup server
191   return "Empty password" unless $hashref->{'_password'};
192   return "No POP selected" unless $hashref->{'popnum'};
193
194   socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
195   connect(SOCK, sockaddr_un($fs_signupd_socket)) or die "connect: $!";
196   print SOCK "new_customer\n";
197
198   print SOCK join("\n", map { $hashref->{$_} } qw(
199     first last ss company address1 address2 city county state zip country
200     daytime night fax payby payinfo paydate payname invoicing_list
201     referral_custnum pkgpart username _password popnum
202   ) ), "\n";
203   SOCK->flush;
204
205   chop( my $error = <SOCK> );
206   $error;
207 }
208
209 =back
210
211 =head1 BUGS
212
213 =head1 SEE ALSO
214
215 L<fs_signupd>, L<FS::cust_main>
216
217 =cut
218
219 1;
220