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