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