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