4 # $Id: signup.cgi,v 1.1 2005-03-12 14:31:50 ivan Exp $
7 use vars qw( @payby $cgi $init_data
8 $self_url $error $agentnum
10 $ieak_file $ieak_template
11 $signup_html $signup_template
12 $success_html $success_template
13 $decline_html $decline_template
16 #$pops %pop %popnum2pop
18 #$last $first $ss $company $address1
19 #$address2 $city $state $county
20 #$country $zip $daytime $night $fax
22 #$ship_last $ship_first $ship_ss $ship_company $ship_address1
23 #$ship_address2 $ship_city $ship_state $ship_county
24 #$ship_country $ship_zip $ship_daytime $ship_night $ship_fax
26 #$invoicing_list $payby $payinfo
27 #$paycvv $paydate $payname $referral_custnum $init_popstate
28 #$pkgpart $username $_password $_password2 $sec_phrase $popnum
33 use subs qw( print_form print_okay print_decline
34 success_default decline_default
37 #use CGI::Carp qw(fatalsToBrowser);
39 use Business::CreditCard;
40 use HTTP::BrowserDetect;
41 use FS::SelfService qw( signup_info new_customer );
43 #acceptable payment methods
45 #@payby = qw( CARD BILL COMP );
46 #@payby = qw( CARD BILL );
48 @payby = qw( CARD PREPAY );
50 $ieak_file = '/usr/local/freeside/ieak.template';
51 $signup_html = -e 'signup.html'
53 : '/usr/local/freeside/signup.html';
54 $success_html = -e 'success.html'
56 : '/usr/local/freeside/success.html';
57 $decline_html = -e 'decline.html'
59 : '/usr/local/freeside/decline.html';
62 if ( -e $ieak_file ) {
63 my $ieak_txt = Text::Template::_load_text($ieak_file)
64 or die $Text::Template::ERROR;
65 $ieak_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
67 $ieak_txt =~ s/\r//g; # don't double \r on old templates
68 $ieak_txt =~ s/\n/\r\n/g;
69 $ieak_template = new Text::Template ( TYPE => 'STRING', SOURCE => $ieak_txt )
70 or die $Text::Template::ERROR;
76 if ( -e $signup_html ) {
77 my $signup_txt = Text::Template::_load_text($signup_html)
78 or die $Text::Template::ERROR;
79 $signup_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
81 $signup_template = new Text::Template ( TYPE => 'STRING',
82 SOURCE => $signup_txt,
83 DELIMITERS => [ '<%=', '%>' ]
85 or die $Text::Template::ERROR;
87 /<\s*INPUT TYPE="?hidden"?\s+NAME="?agentnum"?\s+VALUE="?(\d+)"?\s*>/si
92 #too much maintenance hassle to keep in this file
93 die "can't find ./signup.html or /usr/local/freeside/signup.html";
94 #$signup_template = new Text::Template ( TYPE => 'STRING',
95 # SOURCE => &signup_default,
96 # DELIMITERS => [ '<%=', '%>' ]
98 # or die $Text::Template::ERROR;
101 if ( -e $success_html ) {
102 my $success_txt = Text::Template::_load_text($success_html)
103 or die $Text::Template::ERROR;
104 $success_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
106 $success_template = new Text::Template ( TYPE => 'STRING',
107 SOURCE => $success_txt,
108 DELIMITERS => [ '<%=', '%>' ],
110 or die $Text::Template::ERROR;
112 $success_template = new Text::Template ( TYPE => 'STRING',
113 SOURCE => &success_default,
114 DELIMITERS => [ '<%=', '%>' ],
116 or die $Text::Template::ERROR;
119 if ( -e $decline_html ) {
120 my $decline_txt = Text::Template::_load_text($decline_html)
121 or die $Text::Template::ERROR;
122 $decline_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
124 $decline_template = new Text::Template ( TYPE => 'STRING',
125 SOURCE => $decline_txt,
126 DELIMITERS => [ '<%=', '%>' ],
128 or die $Text::Template::ERROR;
130 $decline_template = new Text::Template ( TYPE => 'STRING',
131 SOURCE => &decline_default,
132 DELIMITERS => [ '<%=', '%>' ],
134 or die $Text::Template::ERROR;
139 $init_data = signup_info( 'agentnum' => $agentnum,
140 'promo_code' => scalar($cgi->param('promo_code')),
141 'reg_code' => uc(scalar($cgi->param('reg_code'))),
143 #$error = $init_data->{'error'};
144 #$locales = $init_data->{'cust_main_county'};
145 #$packages = $init_data->{'part_pkg'};
146 #$pops = $init_data->{'svc_acct_pop'};
147 #@payby = @{$init_data->{'payby'}} if @{$init_data->{'payby'}};
148 #$packages = $init_data->{agentnum2part_pkg}{$agentnum} if $agentnum;
150 if ( ( defined($cgi->param('magic')) && $cgi->param('magic') eq 'process' )
151 || ( defined($cgi->param('action')) && $cgi->param('action') eq 'process_signup' )
154 # if ( $cgi->param('state') =~ /^(\w*)( \(([\w ]+)\))? ?\/ ?(\w+)$/ ) {
156 # $county = $3 || '';
158 # } elsif ( $cgi->param('state') =~ /^(\w*)$/ ) {
160 # $cgi->param('county') =~ /^([\w ]*)$/
161 # or die "illegal county: ". $cgi->param('county');
163 # $cgi->param('country') =~ /^(\w+)$/
164 # or die "illegal country: ". $cgi->param('country');
167 # die "illegal state: ". $cgi->param('state');
169 # if ( $cgi->param('ship_state') =~ /^(\w*)( \(([\w ]+)\))? ?\/ ?(\w+)$/ ) {
171 # $ship_county = $3 || '';
172 # $ship_country = $4;
173 # } elsif ( $cgi->param('ship_state') =~ /^(\w*)$/ ) {
175 # $cgi->param('ship_county') =~ /^([\w ]*)$/
176 # or die "illegal county: ". $cgi->param('ship_county');
178 # #$cgi->param('ship_country') =~ /^(\w+)$/
179 # $cgi->param('ship_country') =~ /^(\w*)$/
180 # or die "illegal ship_country: ". $cgi->param('ship_country');
181 # $ship_country = $1;
183 # # die "illegal ship_state: ". $cgi->param('ship_state');
188 $cgi->param('agentnum', $agentnum) if $agentnum;
189 $cgi->param('reg_code', uc(scalar($cgi->param('reg_code'))) );
191 #false laziness w/agent.cgi, identical except for agentnum
192 my $payby = $cgi->param('payby');
193 if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) {
194 #$payinfo = join('@', map { $cgi->param( $payby. "_payinfo$_" ) } (1,2) );
195 $cgi->param('payinfo' => $cgi->param($payby. '_payinfo1'). '@'.
196 $cgi->param($payby. '_payinfo2')
199 $cgi->param('payinfo' => $cgi->param( $payby. '_payinfo' ) );
201 $cgi->param('paydate' => $cgi->param( $payby. '_month' ). '-'.
202 $cgi->param( $payby. '_year' )
204 $cgi->param('payname' => $cgi->param( $payby. '_payname' ) );
205 $cgi->param('paycvv' => defined $cgi->param( $payby. '_paycvv' )
206 ? $cgi->param( $payby. '_paycvv' )
210 if ( $cgi->param('invoicing_list') ) {
211 $cgi->param('invoicing_list' => $cgi->param('invoicing_list'). ', POST')
212 if $cgi->param('invoicing_list_POST');
214 $cgi->param('invoicing_list' => 'POST' );
217 if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
218 $error = $init_data->{msgcat}{passwords_dont_match}; #msgcat
219 $cgi->param('_password', '');
220 $cgi->param('_password2', '');
223 if ( $payby =~ /^(CARD|DCRD)$/ && $cgi->param('CARD_type') ) {
224 my $payinfo = $cgi->param('payinfo');
227 $payinfo =~ /^(\d{13,16})$/
228 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
231 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
232 cardtype($payinfo) eq $cgi->param('CARD_type')
233 or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
237 my $rv = new_customer( {
238 map { $_ => scalar($cgi->param($_)) }
239 qw( last first ss company
240 address1 address2 city county state zip country
243 ship_last ship_first ship_company
244 ship_address1 ship_address2 ship_city ship_county ship_state
245 ship_zip ship_country
246 ship_daytime ship_night ship_fax
248 payby payinfo paycvv paydate payname invoicing_list
249 referral_custnum promo_code reg_code
250 pkgpart username sec_phrase _password popnum refnum
253 grep { /^snarf_/ } $cgi->param
255 $error = $rv->{'error'};
259 if ( $error eq '_decline' ) {
262 #fudge the snarf info
264 ${$_} = $cgi->param($_) foreach grep { /^snarf_/ } $cgi->param;
268 'pkgpart' => scalar($cgi->param('pkgpart')),
281 # $state = $init_data->{statedefault};
283 # $country = $init_data->{countrydefault};
290 # $ship_company = '';
291 # $ship_address1 = '';
292 # $ship_address2 = '';
294 # $ship_state = $init_data->{statedefault};
296 # $ship_country = $init_data->{countrydefault};
298 # $ship_daytime = '';
301 # $invoicing_list = '';
312 # $referral_custnum = $cgi->param('ref') || '';
313 # $init_popstate = $cgi->param('init_popstate') || '';
314 # $refnum = $init_data->{'refnum'};
320 $error = "Error: $error" if $error;
328 $r->{referral_custnum} = $r->{'ref'};
329 #$cgi->delete('ref');
330 #$cgi->delete('init_popstate');
331 $r->{self_url} = $cgi->self_url;
333 print $cgi->header( '-expires' => 'now' ),
334 $signup_template->fill_in( PACKAGE => 'FS::SelfService::_signupcgi',
340 print $cgi->header( '-expires' => 'now' ),
341 $decline_template->fill_in();
346 my $user_agent = new HTTP::BrowserDetect $ENV{HTTP_USER_AGENT};
348 $cgi->param('username') =~ /^(.+)$/
349 or die "fatal: invalid username got past FS::SelfService::new_customer";
351 $cgi->param('_password') =~ /^(.+)$/
352 or die "fatal: invalid password got past FS::SelfService::new_customer";
354 ( $cgi->param('first'). ' '. $cgi->param('last') ) =~ /^(.*)$/
355 or die "fatal: invalid email_name got past FS::SelfService::new_customer";
356 my $email_name = $1; #global for template
360 foreach ( @{ $init_data->{'svc_acct_pop'} } ) {
361 #push @{ $pop{ $_->{state} }->{ $_->{ac} } }, $_;
362 $popnum2pop{$_->{popnum}} = $_;
365 my( $ac, $exch, $loc);
366 my $pop = $popnum2pop{$cgi->param('popnum')};
367 #or die "fatal: invalid popnum got past FS::SelfService::new_customer";
369 ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
371 ( $ac, $exch, $loc ) = ( '', '', ''); #presumably you're not using them.
375 my $pkg = ( grep { $_->{'pkgpart'} eq $param{'pkgpart'} }
376 @{ $init_data->{'part_pkg'} }
379 if ( $ieak_template && $user_agent->windows && $user_agent->ie ) {
381 print $cgi->header('application/x-Internet-signup'),
382 $ieak_template->fill_in();
383 } else { #send a simple confirmation
384 print $cgi->header( '-expires' => 'now' ),
385 $success_template->fill_in( HASH => {
386 username => $username,
387 password => $password,
388 _password => $password,
389 email_name => $email_name,
398 sub success_default { #html to use if you don't specify a success file
400 <HTML><HEAD><TITLE>Signup successful</TITLE></HEAD>
401 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Signup successful</FONT><BR><BR>
402 Thanks for signing up!
404 Signup information for <%= $email_name %>:
406 Username: <%= $username %><BR>
407 Password: <%= $password %><BR>
408 Access number: (<%= $ac %>) / <%= $exch %> - <%= $local %><BR>
409 Package: <%= $pkg %><BR>
414 sub decline_default { #html to use if there is a decline
416 <HTML><HEAD><TITLE>Processing error</TITLE></HEAD>
417 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Processing error</FONT><BR><BR>
418 There has been an error processing your account. Please contact customer
424 # subs for the templates...
426 package FS::SelfService::_signupcgi;
428 use FS::SelfService qw(regionselector expselect popselector);