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*>/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' )
153 if ( $cgi->param('invoicing_list') ) {
154 $cgi->param('invoicing_list' => $cgi->param('invoicing_list'). ', POST')
155 if $cgi->param('invoicing_list_POST');
157 $cgi->param('invoicing_list' => 'POST' );
160 if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
161 $error = $init_data->{msgcat}{passwords_dont_match}; #msgcat
162 $cgi->param('_password', '');
163 $cgi->param('_password2', '');
166 if ( $payby =~ /^(CARD|DCRD)$/ && $cgi->param('CARD_type') ) {
167 my $payinfo = $cgi->param('payinfo');
170 $payinfo =~ /^(\d{13,16})$/
171 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
174 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
175 cardtype($payinfo) eq $cgi->param('CARD_type')
176 or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
179 if ($init_data->{emailinvoiceonly} && (length $cgi->param('invoicing_list') < 1)) {
180 $error ||= $init_data->{msgcat}{illegal_or_empty_text};
184 my $rv = new_customer( {
185 map { $_ => scalar($cgi->param($_)) }
186 qw( last first ss company
187 address1 address2 city county state zip country
190 ship_last ship_first ship_company
191 ship_address1 ship_address2 ship_city ship_county ship_state
192 ship_zip ship_country
193 ship_daytime ship_night ship_fax
195 payby payinfo paycvv paydate payname invoicing_list
196 referral_custnum promo_code reg_code
197 pkgpart username sec_phrase _password popnum refnum
200 grep { /^snarf_/ } $cgi->param
202 $error = $rv->{'error'};
206 if ( $error eq '_decline' ) {
209 #fudge the snarf info
211 ${$_} = $cgi->param($_) foreach grep { /^snarf_/ } $cgi->param;
215 'pkgpart' => scalar($cgi->param('pkgpart')),
226 $error = "Error: $error" if $error;
234 $r->{referral_custnum} = $r->{'ref'};
235 #$cgi->delete('ref');
236 #$cgi->delete('init_popstate');
237 $r->{self_url} = $cgi->self_url;
239 print $cgi->header( '-expires' => 'now' ),
240 $signup_template->fill_in( PACKAGE => 'FS::SelfService::_signupcgi',
246 print $cgi->header( '-expires' => 'now' ),
247 $decline_template->fill_in();
252 my $user_agent = new HTTP::BrowserDetect $ENV{HTTP_USER_AGENT};
254 $cgi->param('username') =~ /^(.+)$/
255 or die "fatal: invalid username got past FS::SelfService::new_customer";
257 $cgi->param('_password') =~ /^(.+)$/
258 or die "fatal: invalid password got past FS::SelfService::new_customer";
260 ( $cgi->param('first'). ' '. $cgi->param('last') ) =~ /^(.*)$/
261 or die "fatal: invalid email_name got past FS::SelfService::new_customer";
262 my $email_name = $1; #global for template
266 foreach ( @{ $init_data->{'svc_acct_pop'} } ) {
267 #push @{ $pop{ $_->{state} }->{ $_->{ac} } }, $_;
268 $popnum2pop{$_->{popnum}} = $_;
271 my( $ac, $exch, $loc);
272 my $pop = $popnum2pop{$cgi->param('popnum')};
273 #or die "fatal: invalid popnum got past FS::SelfService::new_customer";
275 ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
277 ( $ac, $exch, $loc ) = ( '', '', ''); #presumably you're not using them.
281 my $pkg = ( grep { $_->{'pkgpart'} eq $param{'pkgpart'} }
282 @{ $init_data->{'part_pkg'} }
285 if ( $ieak_template && $user_agent->windows && $user_agent->ie ) {
287 print $cgi->header('application/x-Internet-signup'),
288 $ieak_template->fill_in();
289 } else { #send a simple confirmation
290 print $cgi->header( '-expires' => 'now' ),
291 $success_template->fill_in( HASH => {
292 username => $username,
293 password => $password,
294 _password => $password,
295 email_name => $email_name,
304 sub success_default { #html to use if you don't specify a success file
306 <HTML><HEAD><TITLE>Signup successful</TITLE></HEAD>
307 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Signup successful</FONT><BR><BR>
308 Thanks for signing up!
310 Signup information for <%= $email_name %>:
312 Username: <%= $username %><BR>
313 Password: <%= $password %><BR>
314 Access number: (<%= $ac %>) / <%= $exch %> - <%= $local %><BR>
315 Package: <%= $pkg %><BR>
320 sub decline_default { #html to use if there is a decline
322 <HTML><HEAD><TITLE>Processing error</TITLE></HEAD>
323 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Processing error</FONT><BR><BR>
324 There has been an error processing your account. Please contact customer
330 # subs for the templates...
332 package FS::SelfService::_signupcgi;
334 use FS::SelfService qw(regionselector expselect popselector);