d6730301ced83a1fd99cd9e90c118214b1bb8bff
[freeside.git] / fs_signup / FS-SignupClient / SignupClient.pm
1 package FS::SignupClient;
2
3 use strict;
4 use vars qw($VERSION @ISA @EXPORT_OK $init_data); # $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 use FS::SelfService; # qw( new_customer signup_info );
11
12 $VERSION = '0.04';
13
14 @ISA = qw( Exporter );
15 @EXPORT_OK = qw( signup_info new_customer regionselector expselect popselector);
16
17 =head1 NAME
18
19 FS::SignupClient - Freeside signup client API
20
21 =head1 SYNOPSIS
22
23   use FS::SignupClient qw( signup_info new_customer );
24
25   #this is the backwards-compatibility bit
26   ( $locales, $packages, $pops, $real_signup_info ) = signup_info;
27
28   #this is compatible with FS::SelfService::new_customer
29   $error = new_customer ( {
30     'first'            => $first,
31     'last'             => $last,
32     'ss'               => $ss,
33     'comapny'          => $company,
34     'address1'         => $address1,
35     'address2'         => $address2,
36     'city'             => $city,
37     'county'           => $county,
38     'state'            => $state,
39     'zip'              => $zip,
40     'country'          => $country,
41     'daytime'          => $daytime,
42     'night'            => $night,
43     'fax'              => $fax,
44     'payby'            => $payby,
45     'payinfo'          => $payinfo,
46     'paycvv'           => $paycvv,
47     'paydate'          => $paydate,
48     'payname'          => $payname,
49     'invoicing_list'   => $invoicing_list,
50     'referral_custnum' => $referral_custnum,
51     'comments'         => $comments,
52     'pkgpart'          => $pkgpart,
53     'username'         => $username,
54     '_password'        => $password,
55     'sec_phrase'       => $sec_phrase,
56     'popnum'           => $popnum,
57     'agentnum'         => $agentnum, #optional
58   } );
59
60 =head1 DESCRIPTION
61
62 This module provides an API for a remote signup server.
63
64 It needs to be run as the freeside user.  Because of this, the program which
65 calls these subroutines should be written very carefully.
66
67 =head1 SUBROUTINES
68
69 =over 4
70
71 =item signup_info
72
73 Returns three array references of hash references.
74
75 The first set of hash references is of allowable locales.  Each hash reference
76 has the following keys:
77   taxnum
78   state
79   county
80   country
81
82 The second set of hash references is of allowable packages.  Each hash
83 reference has the following keys:
84   pkgpart
85   pkg
86
87 The third set of hash references is of allowable POPs (Points Of Presence).
88 Each hash reference has the following keys:
89   popnum
90   city
91   state
92   ac
93   exch
94
95 (Future expansion: fourth argument is the $init_data hash reference)
96
97 =cut
98
99 #compatibility bit
100 sub signup_info {
101
102   $init_data = FS::SelfService::signup_info();
103
104   (map { $init_data->{$_} } qw( cust_main_county part_pkg svc_acct_pop ) ),
105   $init_data;
106
107 }
108
109 =item new_customer HASHREF
110
111 Adds a customer to the remote Freeside system.  Requires a hash reference as
112 a paramater with the following keys:
113   first
114   last
115   ss
116   comapny
117   address1
118   address2
119   city
120   county
121   state
122   zip
123   country
124   daytime
125   night
126   fax
127   payby
128   payinfo
129   paycvv
130   paydate
131   payname
132   invoicing_list
133   referral_custnum
134   comments
135   pkgpart
136   username
137   _password
138   sec_phrase
139   popnum
140
141 Returns a scalar error message, or the empty string for success.
142
143 =cut
144
145 #compatibility bit
146 sub new_customer { 
147   my $hash = FS::SelfService::new_customer(@_);
148   $hash->{'error'};
149 }
150
151 =item regionselector SELECTED_COUNTY, SELECTED_STATE, SELECTED_COUNTRY, PREFIX, ONCHANGE
152
153 =cut
154
155 sub regionselector {
156   my ( $selected_county, $selected_state, $selected_country,
157        $prefix, $onchange ) = @_;
158   signup_info() unless $init_data;
159   FS::SelfService::regionselector({
160     selected_county  => $selected_county,
161     selected_state   => $selected_state,
162     selected_country => $selected_country,
163     prefix           => $prefix,
164     onchange         => $onchange,
165     default_country  => $init_data->{countrydefault},
166     locales          => $init_data->{cust_main_county},
167   });
168     #default_state    => $init_data->{statedefault},
169 }
170
171 =item expselect PREFIX, DATE
172
173 =cut
174
175 sub expselect {
176   FS::SelfService::expselect(@_);
177 }
178
179 =item popselector 
180
181 =cut
182
183 sub popselector {
184   my( $popnum ) = @_;
185   signup_info() unless $init_data;
186   FS::SelfService::popselector({
187     popnum => $popnum,
188     pops   => $init_data->{svc_acct_pop},
189   });
190     #popac =>
191     #acstate =>
192 }
193
194 =back
195
196 =head1 BUGS
197
198 This is just a wrapper around FS::SelfService functions for backwards
199 compatibility.  It is only necessary if you're using a signup.cgi from before
200 1.5.0pre7.
201
202 =head1 SEE ALSO
203
204 L<fs_signupd>, L<FS::cust_main>
205
206 =cut
207
208 1;
209