5 use vars qw( @payby $cgi $init_data
6 $self_url $error $agentnum
8 $ieak_file $ieak_template
9 $signup_html $signup_template
10 $success_html $success_template
11 $decline_html $decline_template
14 use subs qw( print_form print_okay print_decline
15 success_default decline_default
18 #use CGI::Carp qw(fatalsToBrowser);
20 use Business::CreditCard;
21 use HTTP::BrowserDetect;
22 use FS::SelfService qw( signup_info new_customer );
24 #acceptable payment methods
26 #@payby = qw( CARD BILL COMP );
27 #@payby = qw( CARD BILL );
29 @payby = qw( CARD PREPAY );
31 $ieak_file = '/usr/local/freeside/ieak.template';
32 $signup_html = -e 'signup.html'
34 : '/usr/local/freeside/signup.html';
35 $success_html = -e 'success.html'
37 : '/usr/local/freeside/success.html';
38 $decline_html = -e 'decline.html'
40 : '/usr/local/freeside/decline.html';
43 if ( -e $ieak_file ) {
44 my $ieak_txt = Text::Template::_load_text($ieak_file)
45 or die $Text::Template::ERROR;
46 $ieak_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
48 $ieak_txt =~ s/\r//g; # don't double \r on old templates
49 $ieak_txt =~ s/\n/\r\n/g;
50 $ieak_template = new Text::Template ( TYPE => 'STRING', SOURCE => $ieak_txt )
51 or die $Text::Template::ERROR;
57 if ( -e $signup_html ) {
58 my $signup_txt = Text::Template::_load_text($signup_html)
59 or die $Text::Template::ERROR;
60 $signup_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
62 $signup_template = new Text::Template ( TYPE => 'STRING',
63 SOURCE => $signup_txt,
64 DELIMITERS => [ '<%=', '%>' ]
66 or die $Text::Template::ERROR;
68 /<\s*INPUT TYPE="?hidden"?\s+NAME="?agentnum"?\s+VALUE="?(\d+)"?\s*\/?\s*>/si
73 #too much maintenance hassle to keep in this file
74 die "can't find ./signup.html or /usr/local/freeside/signup.html";
75 #$signup_template = new Text::Template ( TYPE => 'STRING',
76 # SOURCE => &signup_default,
77 # DELIMITERS => [ '<%=', '%>' ]
79 # or die $Text::Template::ERROR;
82 if ( -e $success_html ) {
83 my $success_txt = Text::Template::_load_text($success_html)
84 or die $Text::Template::ERROR;
85 $success_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
87 $success_template = new Text::Template ( TYPE => 'STRING',
88 SOURCE => $success_txt,
89 DELIMITERS => [ '<%=', '%>' ],
91 or die $Text::Template::ERROR;
93 $success_template = new Text::Template ( TYPE => 'STRING',
94 SOURCE => &success_default,
95 DELIMITERS => [ '<%=', '%>' ],
97 or die $Text::Template::ERROR;
100 if ( -e $decline_html ) {
101 my $decline_txt = Text::Template::_load_text($decline_html)
102 or die $Text::Template::ERROR;
103 $decline_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
105 $decline_template = new Text::Template ( TYPE => 'STRING',
106 SOURCE => $decline_txt,
107 DELIMITERS => [ '<%=', '%>' ],
109 or die $Text::Template::ERROR;
111 $decline_template = new Text::Template ( TYPE => 'STRING',
112 SOURCE => &decline_default,
113 DELIMITERS => [ '<%=', '%>' ],
115 or die $Text::Template::ERROR;
120 $init_data = signup_info( 'agentnum' => $agentnum,
121 'promo_code' => scalar($cgi->param('promo_code')),
122 'reg_code' => uc(scalar($cgi->param('reg_code'))),
125 if ( ( defined($cgi->param('magic')) && $cgi->param('magic') eq 'process' )
126 || ( defined($cgi->param('action')) && $cgi->param('action') eq 'process_signup' )
131 $cgi->param('agentnum', $agentnum) if $agentnum;
132 $cgi->param('reg_code', uc(scalar($cgi->param('reg_code'))) );
134 #false laziness w/agent.cgi, identical except for agentnum
135 my $payby = $cgi->param('payby');
136 if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) {
137 #$payinfo = join('@', map { $cgi->param( $payby. "_payinfo$_" ) } (1,2) );
138 $cgi->param('payinfo' => $cgi->param($payby. '_payinfo1'). '@'.
139 $cgi->param($payby. '_payinfo2')
142 $cgi->param('payinfo' => $cgi->param( $payby. '_payinfo' ) );
144 $cgi->param('paydate' => $cgi->param( $payby. '_month' ). '-'.
145 $cgi->param( $payby. '_year' )
147 $cgi->param('payname' => $cgi->param( $payby. '_payname' ) );
148 $cgi->param('paycvv' => defined $cgi->param( $payby. '_paycvv' )
149 ? $cgi->param( $payby. '_paycvv' )
152 $cgi->param('paytype' => defined $cgi->param( $payby. '_paytype' )
153 ? $cgi->param( $payby. '_paytype' )
156 $cgi->param('paystate' => defined $cgi->param( $payby. '_paystate' )
157 ? $cgi->param( $payby. '_paystate' )
161 if ( $cgi->param('invoicing_list') ) {
162 $cgi->param('invoicing_list' => $cgi->param('invoicing_list'). ', POST')
163 if $cgi->param('invoicing_list_POST');
165 $cgi->param('invoicing_list' => 'POST' );
168 if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
169 $error = $init_data->{msgcat}{passwords_dont_match}; #msgcat
170 $cgi->param('_password', '');
171 $cgi->param('_password2', '');
174 if ( $payby =~ /^(CARD|DCRD)$/ && $cgi->param('CARD_type') ) {
175 my $payinfo = $cgi->param('payinfo');
178 $payinfo =~ /^(\d{13,16})$/
179 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
182 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
183 cardtype($payinfo) eq $cgi->param('CARD_type')
184 or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
187 if ($init_data->{emailinvoiceonly} && (length $cgi->param('invoicing_list') < 1)) {
188 $error ||= $init_data->{msgcat}{illegal_or_empty_text};
192 my $rv = new_customer( {
193 ( map { $_ => scalar($cgi->param($_)) }
194 qw( last first ss company
195 address1 address2 city county state zip country
196 daytime night fax stateid stateid_state
198 ship_last ship_first ship_company
199 ship_address1 ship_address2 ship_city ship_county ship_state
200 ship_zip ship_country
201 ship_daytime ship_night ship_fax
203 payby payinfo paycvv paydate payname paystate paytype
204 invoicing_list referral_custnum promo_code reg_code
205 pkgpart username sec_phrase _password popnum refnum
208 grep { /^snarf_/ } $cgi->param
210 'payip' => $cgi->remote_host(),
212 $error = $rv->{'error'};
216 if ( $error eq '_decline' ) {
219 #fudge the snarf info
221 ${$_} = $cgi->param($_) foreach grep { /^snarf_/ } $cgi->param;
225 'pkgpart' => scalar($cgi->param('pkgpart')),
236 $error = "Error: $error" if $error;
244 $r->{pkgpart} ||= $r->{default_pkgpart};
246 $r->{referral_custnum} = $r->{'ref'};
247 #$cgi->delete('ref');
248 #$cgi->delete('init_popstate');
249 $r->{self_url} = $cgi->self_url;
251 print $cgi->header( '-expires' => 'now' ),
252 $signup_template->fill_in( PACKAGE => 'FS::SelfService::_signupcgi',
258 print $cgi->header( '-expires' => 'now' ),
259 $decline_template->fill_in();
264 my $user_agent = new HTTP::BrowserDetect $ENV{HTTP_USER_AGENT};
266 $cgi->param('username') =~ /^(.+)$/
267 or die "fatal: invalid username got past FS::SelfService::new_customer";
269 $cgi->param('_password') =~ /^(.+)$/
270 or die "fatal: invalid password got past FS::SelfService::new_customer";
272 ( $cgi->param('first'). ' '. $cgi->param('last') ) =~ /^(.*)$/
273 or die "fatal: invalid email_name got past FS::SelfService::new_customer";
274 my $email_name = $1; #global for template
278 foreach ( @{ $init_data->{'svc_acct_pop'} } ) {
279 #push @{ $pop{ $_->{state} }->{ $_->{ac} } }, $_;
280 $popnum2pop{$_->{popnum}} = $_;
283 my( $ac, $exch, $loc);
284 my $pop = $popnum2pop{$cgi->param('popnum')};
285 #or die "fatal: invalid popnum got past FS::SelfService::new_customer";
287 ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
289 ( $ac, $exch, $loc ) = ( '', '', ''); #presumably you're not using them.
293 my $part_pkg = ( grep { $_->{'pkgpart'} eq $param{'pkgpart'} }
294 @{ $init_data->{'part_pkg'} }
296 my $pkg = $part_pkg->{'pkg'};
298 if ( $ieak_template && $user_agent->windows && $user_agent->ie ) {
300 print $cgi->header('application/x-Internet-signup'),
301 $ieak_template->fill_in();
302 } else { #send a simple confirmation
303 print $cgi->header( '-expires' => 'now' ),
304 $success_template->fill_in( HASH => {
305 username => $username,
306 password => $password,
307 _password => $password,
308 email_name => $email_name,
313 part_pkg => \$part_pkg,
318 sub success_default { #html to use if you don't specify a success file
320 <HTML><HEAD><TITLE>Signup successful</TITLE></HEAD>
321 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Signup successful</FONT><BR><BR>
322 Thanks for signing up!
324 Signup information for <%= $email_name %>:
326 Username: <%= $username %><BR>
327 Password: <%= $password %><BR>
328 Access number: (<%= $ac %>) / <%= $exch %> - <%= $local %><BR>
329 Package: <%= $pkg %><BR>
334 sub decline_default { #html to use if there is a decline
336 <HTML><HEAD><TITLE>Processing error</TITLE></HEAD>
337 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Processing error</FONT><BR><BR>
338 There has been an error processing your account. Please contact customer
344 # subs for the templates...
346 package FS::SelfService::_signupcgi;
348 use FS::SelfService qw(regionselector expselect popselector didselector);