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 $collect_html $collect_template
12 $decline_html $decline_template
15 use subs qw( print_form print_okay print_decline
16 success_default collect_default decline_default
19 #use CGI::Carp qw(fatalsToBrowser);
22 use Business::CreditCard;
23 use HTTP::BrowserDetect;
24 use HTML::Widgets::SelectLayers;
25 use FS::SelfService qw( signup_info new_customer );
27 #acceptable payment methods
29 #@payby = qw( CARD BILL COMP );
30 #@payby = qw( CARD BILL );
32 @payby = qw( CARD PREPAY );
34 $ieak_file = '/usr/local/freeside/ieak.template';
35 $signup_html = -e 'signup.html'
37 : '/usr/local/freeside/signup.html';
38 $success_html = -e 'success.html'
40 : '/usr/local/freeside/success.html';
41 $collect_html = -e 'collect.html'
43 : '/usr/local/freeside/collect.html';
44 $decline_html = -e 'decline.html'
46 : '/usr/local/freeside/decline.html';
49 if ( -e $ieak_file ) {
50 my $ieak_txt = Text::Template::_load_text($ieak_file)
51 or die $Text::Template::ERROR;
52 $ieak_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
54 $ieak_txt =~ s/\r//g; # don't double \r on old templates
55 $ieak_txt =~ s/\n/\r\n/g;
56 $ieak_template = new Text::Template ( TYPE => 'STRING', SOURCE => $ieak_txt )
57 or die $Text::Template::ERROR;
63 if ( -e $signup_html ) {
64 my $signup_txt = Text::Template::_load_text($signup_html)
65 or die $Text::Template::ERROR;
66 $signup_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
68 $signup_template = new Text::Template ( TYPE => 'STRING',
69 SOURCE => $signup_txt,
70 DELIMITERS => [ '<%=', '%>' ]
72 or die $Text::Template::ERROR;
74 /<\s*INPUT TYPE="?hidden"?\s+NAME="?agentnum"?\s+VALUE="?(\d+)"?\s*\/?\s*>/si
79 #too much maintenance hassle to keep in this file
80 die "can't find ./signup.html or /usr/local/freeside/signup.html";
81 #$signup_template = new Text::Template ( TYPE => 'STRING',
82 # SOURCE => &signup_default,
83 # DELIMITERS => [ '<%=', '%>' ]
85 # or die $Text::Template::ERROR;
88 if ( -e $success_html ) {
89 my $success_txt = Text::Template::_load_text($success_html)
90 or die $Text::Template::ERROR;
91 $success_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
93 $success_template = new Text::Template ( TYPE => 'STRING',
94 SOURCE => $success_txt,
95 DELIMITERS => [ '<%=', '%>' ],
97 or die $Text::Template::ERROR;
99 $success_template = new Text::Template ( TYPE => 'STRING',
100 SOURCE => &success_default,
101 DELIMITERS => [ '<%=', '%>' ],
103 or die $Text::Template::ERROR;
106 if ( -e $collect_html ) {
107 my $collect_txt = Text::Template::_load_text($collect_html)
108 or die $Text::Template::ERROR;
109 $collect_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
111 $collect_template = new Text::Template ( TYPE => 'STRING',
112 SOURCE => $collect_txt,
113 DELIMITERS => [ '<%=', '%>' ],
115 or die $Text::Template::ERROR;
117 $collect_template = new Text::Template ( TYPE => 'STRING',
118 SOURCE => &collect_default,
119 DELIMITERS => [ '<%=', '%>' ],
121 or die $Text::Template::ERROR;
124 if ( -e $decline_html ) {
125 my $decline_txt = Text::Template::_load_text($decline_html)
126 or die $Text::Template::ERROR;
127 $decline_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
129 $decline_template = new Text::Template ( TYPE => 'STRING',
130 SOURCE => $decline_txt,
131 DELIMITERS => [ '<%=', '%>' ],
133 or die $Text::Template::ERROR;
135 $decline_template = new Text::Template ( TYPE => 'STRING',
136 SOURCE => &decline_default,
137 DELIMITERS => [ '<%=', '%>' ],
139 or die $Text::Template::ERROR;
144 $init_data = signup_info( 'agentnum' => $agentnum || scalar($cgi->param('agentnum')),
145 'promo_code' => scalar($cgi->param('promo_code')),
146 'reg_code' => uc(scalar($cgi->param('reg_code'))),
149 my $magic = $cgi->param('magic') || '';
150 my $action = $cgi->param('action') || '';
152 if ( $magic eq 'process' || $action eq 'process_signup' ) {
156 $cgi->param('agentnum', $agentnum) if $agentnum;
157 $cgi->param('reg_code', uc(scalar($cgi->param('reg_code'))) );
159 #false laziness w/agent.cgi, identical except for agentnum
160 my $payby = $cgi->param('payby');
161 if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) {
162 #$payinfo = join('@', map { $cgi->param( $payby. "_payinfo$_" ) } (1,2) );
163 $cgi->param('payinfo' => $cgi->param($payby. '_payinfo1'). '@'.
164 $cgi->param($payby. '_payinfo2')
167 $cgi->param('payinfo' => $cgi->param( $payby. '_payinfo' ) );
169 $cgi->param('paydate' => $cgi->param( $payby. '_month' ). '-'.
170 $cgi->param( $payby. '_year' )
172 $cgi->param('payname' => $cgi->param( $payby. '_payname' ) );
173 $cgi->param('paycvv' => defined $cgi->param( $payby. '_paycvv' )
174 ? $cgi->param( $payby. '_paycvv' )
177 $cgi->param('paytype' => defined $cgi->param( $payby. '_paytype' )
178 ? $cgi->param( $payby. '_paytype' )
181 $cgi->param('paystate' => defined $cgi->param( $payby. '_paystate' )
182 ? $cgi->param( $payby. '_paystate' )
186 if ( $cgi->param('invoicing_list') ) {
187 $cgi->param('invoicing_list' => $cgi->param('invoicing_list'). ', POST')
188 if $cgi->param('invoicing_list_POST');
190 $cgi->param('invoicing_list' => 'POST' );
193 #if ( $svc_x eq 'svc_acct' ) {
194 if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
195 $error = $init_data->{msgcat}{passwords_dont_match}; #msgcat
196 $cgi->param('_password', '');
197 $cgi->param('_password2', '');
200 if ( $payby =~ /^(CARD|DCRD)$/ && $cgi->param('CARD_type') ) {
201 my $payinfo = $cgi->param('payinfo');
204 $payinfo =~ /^(\d{13,16})$/
205 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
208 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
209 cardtype($payinfo) eq $cgi->param('CARD_type')
210 or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
213 if ($init_data->{emailinvoiceonly} && (length $cgi->param('invoicing_list') < 1)) {
214 $error ||= $init_data->{msgcat}{illegal_or_empty_text};
219 $rv = new_customer( {
220 ( map { $_ => scalar($cgi->param($_)) }
221 qw( last first ss company
222 address1 address2 city county state zip country
223 daytime night fax stateid stateid_state
225 ship_last ship_first ship_company
226 ship_address1 ship_address2 ship_city ship_county ship_state
227 ship_zip ship_country
228 ship_daytime ship_night ship_fax
230 payby payinfo paycvv paydate payname paystate paytype
231 invoicing_list referral_custnum promo_code reg_code
232 pkgpart refnum agentnum
233 username sec_phrase _password popnum
235 countrycode phonenum sip_password pin prepaid_shortform
237 grep { /^snarf_/ } $cgi->param
239 'payip' => $cgi->remote_host(),
241 $error = $rv->{'error'};
245 if ( $error eq '_decline' ) {
247 } elsif ( $error eq '_collect' ) {
248 map { $cgi->param($_, $rv->{$_}) }
249 qw( popup_url reference amount );
252 #fudge the snarf info
254 ${$_} = $cgi->param($_) foreach grep { /^snarf_/ } $cgi->param;
258 'pkgpart' => scalar($cgi->param('pkgpart')),
263 } elsif ( $magic eq 'success' || $action eq 'success' ) {
265 $cgi->param('username', 'username'); #hmmm temp kludge
266 $cgi->param('_password', 'password');
267 print_okay( map { /^([\w ]+)$/ ? ( $_ => $1 ) : () } $cgi->param ); #hmmm
269 } elsif ( $magic eq 'decline' || $action eq 'decline' ) {
280 $error = "Error: $error" if $error;
288 $r->{pkgpart} ||= $r->{default_pkgpart};
290 $r->{referral_custnum} = $r->{'ref'};
291 #$cgi->delete('ref');
292 #$cgi->delete('init_popstate');
293 $r->{self_url} = $cgi->self_url;
295 $r->{prepaid_shortform} = $cgi->param('prepaid_shortform');
297 print $cgi->header( '-expires' => 'now' ),
298 $signup_template->fill_in( PACKAGE => 'FS::SelfService::_signupcgi',
305 $error = "Error: $error" if $error;
307 my $rv = shift || {};
315 $r->{pkgpart} ||= $r->{default_pkgpart};
317 $r->{referral_custnum} = $r->{'ref'};
318 $r->{self_url} = $cgi->self_url;
320 print $cgi->header( '-expires' => 'now' ),
322 $collect_template->fill_in( PACKAGE => 'FS::SelfService::_signupcgi',
332 print $cgi->header( '-expires' => 'now' ),
333 $decline_template->fill_in( PACKAGE => 'FS::SelfService::_signupcgi',
340 my $user_agent = new HTTP::BrowserDetect $ENV{HTTP_USER_AGENT};
342 my( $username, $password ) = ( '', '' );
343 my( $countrycode, $phonenum, $sip_password, $pin ) = ( '', '', '', '' );
345 my $svc_x = $param{signup_service} || 'svc_acct'; #just in case
346 if ( $svc_x eq 'svc_acct' ) {
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";
355 } elsif ( $svc_x eq 'svc_phone' ) {
357 $countrycode = $param{countrycode};
358 $phonenum = $param{phonenum};
359 $sip_password = $param{sip_password};
363 die "unknown signup service $svc_x";
366 ( $cgi->param('first'). ' '. $cgi->param('last') ) =~ /^(.*)$/
367 or die "fatal: invalid email_name got past FS::SelfService::new_customer";
368 my $email_name = $1; #global for template
372 foreach ( @{ $init_data->{'svc_acct_pop'} } ) {
373 #push @{ $pop{ $_->{state} }->{ $_->{ac} } }, $_;
374 $popnum2pop{$_->{popnum}} = $_;
377 my( $ac, $exch, $loc);
378 my $pop = $popnum2pop{$cgi->param('popnum')};
379 #or die "fatal: invalid popnum got past FS::SelfService::new_customer";
381 ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
383 ( $ac, $exch, $loc ) = ( '', '', ''); #presumably you're not using them.
387 my $part_pkg = ( grep { $_->{'pkgpart'} eq $param{'pkgpart'} }
388 @{ $init_data->{'part_pkg'} }
390 my $pkg = $part_pkg->{'pkg'};
392 if ( $ieak_template && $user_agent->windows && $user_agent->ie ) {
395 print $cgi->header('application/x-Internet-signup'),
396 $ieak_template->fill_in();
398 } else { #send a simple confirmation
400 print $cgi->header( '-expires' => 'now' ),
401 $success_template->fill_in( HASH => {
405 email_name => $email_name,
407 part_pkg => \$part_pkg,
409 signup_service => $svc_x,
412 username => $username,
413 password => $password,
414 _password => $password,
415 ac => $ac, #for dialup POP
420 countrycode => $countrycode,
421 phonenum => $phonenum,
422 sip_password => $sip_password,
430 sub success_default { #html to use if you don't specify a success file
432 <HTML><HEAD><TITLE>Signup successful</TITLE></HEAD>
433 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Signup successful</FONT><BR><BR>
434 Thanks for signing up!
436 Signup information for <%= $email_name %>:
438 Username: <%= $username %><BR>
439 Password: <%= $password %><BR>
440 Access number: (<%= $ac %>) / <%= $exch %> - <%= $local %><BR>
441 Package: <%= $pkg %><BR>
446 sub collect_default { #html to use if there is a collect phase
448 <HTML><HEAD><TITLE>Pay now</TITLE></HEAD>
449 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Pay now</FONT><BR><BR>
451 #<SCRIPT TYPE="text/javascript">
452 # function popcollect() {
453 # overlib( OLiframeContent('<%= $popup_url %>', 336, 550, 'Secure Payment Area', 0, 'auto' ), CAPTION, 'Pay now', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK, BGCOLOR, '#333399', CGCOLOR, '#333399', CLOSETEXT, 'Close' );
457 #<SCRIPT TYPE="text/javascript" SRC="overlibmws.js"></SCRIPT>
458 #<SCRIPT TYPE="text/javascript" SRC="overlibmws_iframe.js"></SCRIPT>
459 #<SCRIPT TYPE="text/javascript" SRC="overlibmws_draggable.js"></SCRIPT>
460 #<SCRIPT TYPE="text/javascript" SRC="overlibmws_crossframe.js"></SCRIPT>
461 #<SCRIPT TYPE="text/javascript" SRC="iframecontentmws.js"></SCRIPT>
463 You are about to contact our payment processor to pay <%= $amount %> for
465 Your transaction reference number is <%= $reference %><BR><BR>
466 <FORM NAME="collect_popper" method="post" action="<%= $popup_url %>">
468 my %itemhash = @collectitems ;
469 foreach my $input (keys %itemhash) {
470 $OUT .= qq!<INPUT NAME="$input" TYPE="hidden" VALUE="$itemhash{$input}">!;
473 <INPUT NAME="submit" type="submit" value="Pay now">
479 sub decline_default { #html to use if there is a decline
481 <HTML><HEAD><TITLE>Processing error</TITLE></HEAD>
482 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Processing error</FONT><BR><BR>
483 There has been an error processing your account. Please contact customer
489 # subs for the templates...
491 package FS::SelfService::_signupcgi;
493 use FS::SelfService qw(regionselector expselect popselector didselector);