4 # $Id: signup.cgi,v 1.2 2005-03-12 14:35:12 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 use subs qw( print_form print_okay print_decline
17 success_default decline_default
20 #use CGI::Carp qw(fatalsToBrowser);
22 use Business::CreditCard;
23 use HTTP::BrowserDetect;
24 use FS::SelfService qw( signup_info new_customer );
26 #acceptable payment methods
28 #@payby = qw( CARD BILL COMP );
29 #@payby = qw( CARD BILL );
31 @payby = qw( CARD PREPAY );
33 $ieak_file = '/usr/local/freeside/ieak.template';
34 $signup_html = -e 'signup.html'
36 : '/usr/local/freeside/signup.html';
37 $success_html = -e 'success.html'
39 : '/usr/local/freeside/success.html';
40 $decline_html = -e 'decline.html'
42 : '/usr/local/freeside/decline.html';
45 if ( -e $ieak_file ) {
46 my $ieak_txt = Text::Template::_load_text($ieak_file)
47 or die $Text::Template::ERROR;
48 $ieak_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
50 $ieak_txt =~ s/\r//g; # don't double \r on old templates
51 $ieak_txt =~ s/\n/\r\n/g;
52 $ieak_template = new Text::Template ( TYPE => 'STRING', SOURCE => $ieak_txt )
53 or die $Text::Template::ERROR;
59 if ( -e $signup_html ) {
60 my $signup_txt = Text::Template::_load_text($signup_html)
61 or die $Text::Template::ERROR;
62 $signup_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
64 $signup_template = new Text::Template ( TYPE => 'STRING',
65 SOURCE => $signup_txt,
66 DELIMITERS => [ '<%=', '%>' ]
68 or die $Text::Template::ERROR;
70 /<\s*INPUT TYPE="?hidden"?\s+NAME="?agentnum"?\s+VALUE="?(\d+)"?\s*>/si
75 #too much maintenance hassle to keep in this file
76 die "can't find ./signup.html or /usr/local/freeside/signup.html";
77 #$signup_template = new Text::Template ( TYPE => 'STRING',
78 # SOURCE => &signup_default,
79 # DELIMITERS => [ '<%=', '%>' ]
81 # or die $Text::Template::ERROR;
84 if ( -e $success_html ) {
85 my $success_txt = Text::Template::_load_text($success_html)
86 or die $Text::Template::ERROR;
87 $success_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
89 $success_template = new Text::Template ( TYPE => 'STRING',
90 SOURCE => $success_txt,
91 DELIMITERS => [ '<%=', '%>' ],
93 or die $Text::Template::ERROR;
95 $success_template = new Text::Template ( TYPE => 'STRING',
96 SOURCE => &success_default,
97 DELIMITERS => [ '<%=', '%>' ],
99 or die $Text::Template::ERROR;
102 if ( -e $decline_html ) {
103 my $decline_txt = Text::Template::_load_text($decline_html)
104 or die $Text::Template::ERROR;
105 $decline_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
107 $decline_template = new Text::Template ( TYPE => 'STRING',
108 SOURCE => $decline_txt,
109 DELIMITERS => [ '<%=', '%>' ],
111 or die $Text::Template::ERROR;
113 $decline_template = new Text::Template ( TYPE => 'STRING',
114 SOURCE => &decline_default,
115 DELIMITERS => [ '<%=', '%>' ],
117 or die $Text::Template::ERROR;
122 $init_data = signup_info( 'agentnum' => $agentnum,
123 'promo_code' => scalar($cgi->param('promo_code')),
124 'reg_code' => uc(scalar($cgi->param('reg_code'))),
127 if ( ( defined($cgi->param('magic')) && $cgi->param('magic') eq 'process' )
128 || ( defined($cgi->param('action')) && $cgi->param('action') eq 'process_signup' )
133 $cgi->param('agentnum', $agentnum) if $agentnum;
134 $cgi->param('reg_code', uc(scalar($cgi->param('reg_code'))) );
136 #false laziness w/agent.cgi, identical except for agentnum
137 my $payby = $cgi->param('payby');
138 if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) {
139 #$payinfo = join('@', map { $cgi->param( $payby. "_payinfo$_" ) } (1,2) );
140 $cgi->param('payinfo' => $cgi->param($payby. '_payinfo1'). '@'.
141 $cgi->param($payby. '_payinfo2')
144 $cgi->param('payinfo' => $cgi->param( $payby. '_payinfo' ) );
146 $cgi->param('paydate' => $cgi->param( $payby. '_month' ). '-'.
147 $cgi->param( $payby. '_year' )
149 $cgi->param('payname' => $cgi->param( $payby. '_payname' ) );
150 $cgi->param('paycvv' => defined $cgi->param( $payby. '_paycvv' )
151 ? $cgi->param( $payby. '_paycvv' )
155 if ( $cgi->param('invoicing_list') ) {
156 $cgi->param('invoicing_list' => $cgi->param('invoicing_list'). ', POST')
157 if $cgi->param('invoicing_list_POST');
159 $cgi->param('invoicing_list' => 'POST' );
162 if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
163 $error = $init_data->{msgcat}{passwords_dont_match}; #msgcat
164 $cgi->param('_password', '');
165 $cgi->param('_password2', '');
168 if ( $payby =~ /^(CARD|DCRD)$/ && $cgi->param('CARD_type') ) {
169 my $payinfo = $cgi->param('payinfo');
172 $payinfo =~ /^(\d{13,16})$/
173 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
176 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
177 cardtype($payinfo) eq $cgi->param('CARD_type')
178 or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
182 my $rv = new_customer( {
183 map { $_ => scalar($cgi->param($_)) }
184 qw( last first ss company
185 address1 address2 city county state zip country
188 ship_last ship_first ship_company
189 ship_address1 ship_address2 ship_city ship_county ship_state
190 ship_zip ship_country
191 ship_daytime ship_night ship_fax
193 payby payinfo paycvv paydate payname invoicing_list
194 referral_custnum promo_code reg_code
195 pkgpart username sec_phrase _password popnum refnum
198 grep { /^snarf_/ } $cgi->param
200 $error = $rv->{'error'};
204 if ( $error eq '_decline' ) {
207 #fudge the snarf info
209 ${$_} = $cgi->param($_) foreach grep { /^snarf_/ } $cgi->param;
213 'pkgpart' => scalar($cgi->param('pkgpart')),
224 $error = "Error: $error" if $error;
232 $r->{referral_custnum} = $r->{'ref'};
233 #$cgi->delete('ref');
234 #$cgi->delete('init_popstate');
235 $r->{self_url} = $cgi->self_url;
237 print $cgi->header( '-expires' => 'now' ),
238 $signup_template->fill_in( PACKAGE => 'FS::SelfService::_signupcgi',
244 print $cgi->header( '-expires' => 'now' ),
245 $decline_template->fill_in();
250 my $user_agent = new HTTP::BrowserDetect $ENV{HTTP_USER_AGENT};
252 $cgi->param('username') =~ /^(.+)$/
253 or die "fatal: invalid username got past FS::SelfService::new_customer";
255 $cgi->param('_password') =~ /^(.+)$/
256 or die "fatal: invalid password got past FS::SelfService::new_customer";
258 ( $cgi->param('first'). ' '. $cgi->param('last') ) =~ /^(.*)$/
259 or die "fatal: invalid email_name got past FS::SelfService::new_customer";
260 my $email_name = $1; #global for template
264 foreach ( @{ $init_data->{'svc_acct_pop'} } ) {
265 #push @{ $pop{ $_->{state} }->{ $_->{ac} } }, $_;
266 $popnum2pop{$_->{popnum}} = $_;
269 my( $ac, $exch, $loc);
270 my $pop = $popnum2pop{$cgi->param('popnum')};
271 #or die "fatal: invalid popnum got past FS::SelfService::new_customer";
273 ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
275 ( $ac, $exch, $loc ) = ( '', '', ''); #presumably you're not using them.
279 my $pkg = ( grep { $_->{'pkgpart'} eq $param{'pkgpart'} }
280 @{ $init_data->{'part_pkg'} }
283 if ( $ieak_template && $user_agent->windows && $user_agent->ie ) {
285 print $cgi->header('application/x-Internet-signup'),
286 $ieak_template->fill_in();
287 } else { #send a simple confirmation
288 print $cgi->header( '-expires' => 'now' ),
289 $success_template->fill_in( HASH => {
290 username => $username,
291 password => $password,
292 _password => $password,
293 email_name => $email_name,
302 sub success_default { #html to use if you don't specify a success file
304 <HTML><HEAD><TITLE>Signup successful</TITLE></HEAD>
305 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Signup successful</FONT><BR><BR>
306 Thanks for signing up!
308 Signup information for <%= $email_name %>:
310 Username: <%= $username %><BR>
311 Password: <%= $password %><BR>
312 Access number: (<%= $ac %>) / <%= $exch %> - <%= $local %><BR>
313 Package: <%= $pkg %><BR>
318 sub decline_default { #html to use if there is a decline
320 <HTML><HEAD><TITLE>Processing error</TITLE></HEAD>
321 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Processing error</FONT><BR><BR>
322 There has been an error processing your account. Please contact customer
328 # subs for the templates...
330 package FS::SelfService::_signupcgi;
332 use FS::SelfService qw(regionselector expselect popselector);