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);
21 use Business::CreditCard;
22 use HTTP::BrowserDetect;
23 use FS::SelfService qw( signup_info new_customer );
25 #acceptable payment methods
27 #@payby = qw( CARD BILL COMP );
28 #@payby = qw( CARD BILL );
30 @payby = qw( CARD PREPAY );
32 $ieak_file = '/usr/local/freeside/ieak.template';
33 $signup_html = -e 'signup.html'
35 : '/usr/local/freeside/signup.html';
36 $success_html = -e 'success.html'
38 : '/usr/local/freeside/success.html';
39 $collect_html = -e 'collect.html'
41 : '/usr/local/freeside/collect.html';
42 $decline_html = -e 'decline.html'
44 : '/usr/local/freeside/decline.html';
47 if ( -e $ieak_file ) {
48 my $ieak_txt = Text::Template::_load_text($ieak_file)
49 or die $Text::Template::ERROR;
50 $ieak_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
52 $ieak_txt =~ s/\r//g; # don't double \r on old templates
53 $ieak_txt =~ s/\n/\r\n/g;
54 $ieak_template = new Text::Template ( TYPE => 'STRING', SOURCE => $ieak_txt )
55 or die $Text::Template::ERROR;
61 if ( -e $signup_html ) {
62 my $signup_txt = Text::Template::_load_text($signup_html)
63 or die $Text::Template::ERROR;
64 $signup_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
66 $signup_template = new Text::Template ( TYPE => 'STRING',
67 SOURCE => $signup_txt,
68 DELIMITERS => [ '<%=', '%>' ]
70 or die $Text::Template::ERROR;
72 /<\s*INPUT TYPE="?hidden"?\s+NAME="?agentnum"?\s+VALUE="?(\d+)"?\s*\/?\s*>/si
77 #too much maintenance hassle to keep in this file
78 die "can't find ./signup.html or /usr/local/freeside/signup.html";
79 #$signup_template = new Text::Template ( TYPE => 'STRING',
80 # SOURCE => &signup_default,
81 # DELIMITERS => [ '<%=', '%>' ]
83 # or die $Text::Template::ERROR;
86 if ( -e $success_html ) {
87 my $success_txt = Text::Template::_load_text($success_html)
88 or die $Text::Template::ERROR;
89 $success_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
91 $success_template = new Text::Template ( TYPE => 'STRING',
92 SOURCE => $success_txt,
93 DELIMITERS => [ '<%=', '%>' ],
95 or die $Text::Template::ERROR;
97 $success_template = new Text::Template ( TYPE => 'STRING',
98 SOURCE => &success_default,
99 DELIMITERS => [ '<%=', '%>' ],
101 or die $Text::Template::ERROR;
104 if ( -e $collect_html ) {
105 my $collect_txt = Text::Template::_load_text($collect_html)
106 or die $Text::Template::ERROR;
107 $collect_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
109 $collect_template = new Text::Template ( TYPE => 'STRING',
110 SOURCE => $collect_txt,
111 DELIMITERS => [ '<%=', '%>' ],
113 or die $Text::Template::ERROR;
115 $collect_template = new Text::Template ( TYPE => 'STRING',
116 SOURCE => &collect_default,
117 DELIMITERS => [ '<%=', '%>' ],
119 or die $Text::Template::ERROR;
122 if ( -e $decline_html ) {
123 my $decline_txt = Text::Template::_load_text($decline_html)
124 or die $Text::Template::ERROR;
125 $decline_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
127 $decline_template = new Text::Template ( TYPE => 'STRING',
128 SOURCE => $decline_txt,
129 DELIMITERS => [ '<%=', '%>' ],
131 or die $Text::Template::ERROR;
133 $decline_template = new Text::Template ( TYPE => 'STRING',
134 SOURCE => &decline_default,
135 DELIMITERS => [ '<%=', '%>' ],
137 or die $Text::Template::ERROR;
142 $init_data = signup_info( 'agentnum' => $agentnum,
143 'promo_code' => scalar($cgi->param('promo_code')),
144 'reg_code' => uc(scalar($cgi->param('reg_code'))),
147 my $magic = $cgi->param('magic') || '';
148 my $action = $cgi->param('action') || '';
150 if ( $magic eq 'process' || $action eq 'process_signup' ) {
154 $cgi->param('agentnum', $agentnum) if $agentnum;
155 $cgi->param('reg_code', uc(scalar($cgi->param('reg_code'))) );
157 #false laziness w/agent.cgi, identical except for agentnum
158 my $payby = $cgi->param('payby');
159 if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) {
160 #$payinfo = join('@', map { $cgi->param( $payby. "_payinfo$_" ) } (1,2) );
161 $cgi->param('payinfo' => $cgi->param($payby. '_payinfo1'). '@'.
162 $cgi->param($payby. '_payinfo2')
165 $cgi->param('payinfo' => $cgi->param( $payby. '_payinfo' ) );
167 $cgi->param('paydate' => $cgi->param( $payby. '_month' ). '-'.
168 $cgi->param( $payby. '_year' )
170 $cgi->param('payname' => $cgi->param( $payby. '_payname' ) );
171 $cgi->param('paycvv' => defined $cgi->param( $payby. '_paycvv' )
172 ? $cgi->param( $payby. '_paycvv' )
175 $cgi->param('paytype' => defined $cgi->param( $payby. '_paytype' )
176 ? $cgi->param( $payby. '_paytype' )
179 $cgi->param('paystate' => defined $cgi->param( $payby. '_paystate' )
180 ? $cgi->param( $payby. '_paystate' )
184 if ( $cgi->param('invoicing_list') ) {
185 $cgi->param('invoicing_list' => $cgi->param('invoicing_list'). ', POST')
186 if $cgi->param('invoicing_list_POST');
188 $cgi->param('invoicing_list' => 'POST' );
191 #if ( $svc_x eq 'svc_acct' ) {
192 if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
193 $error = $init_data->{msgcat}{passwords_dont_match}; #msgcat
194 $cgi->param('_password', '');
195 $cgi->param('_password2', '');
198 if ( $payby =~ /^(CARD|DCRD)$/ && $cgi->param('CARD_type') ) {
199 my $payinfo = $cgi->param('payinfo');
202 $payinfo =~ /^(\d{13,16})$/
203 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
206 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
207 cardtype($payinfo) eq $cgi->param('CARD_type')
208 or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
211 if ($init_data->{emailinvoiceonly} && (length $cgi->param('invoicing_list') < 1)) {
212 $error ||= $init_data->{msgcat}{illegal_or_empty_text};
217 $rv = new_customer( {
218 ( map { $_ => scalar($cgi->param($_)) }
219 qw( last first ss company
220 address1 address2 city county state zip country
221 daytime night fax stateid stateid_state
223 ship_last ship_first ship_company
224 ship_address1 ship_address2 ship_city ship_county ship_state
225 ship_zip ship_country
226 ship_daytime ship_night ship_fax
228 payby payinfo paycvv paydate payname paystate paytype
229 invoicing_list referral_custnum promo_code reg_code
230 pkgpart refnum agentnum
231 username sec_phrase _password popnum
232 countrycode phonenum sip_password pin
234 grep { /^snarf_/ } $cgi->param
236 'payip' => $cgi->remote_host(),
238 $error = $rv->{'error'};
242 if ( $error eq '_decline' ) {
244 } elsif ( $error eq '_collect' ) {
245 map { $cgi->param($_, $rv->{$_}) }
246 qw( popup_url reference collectitems amount );
249 #fudge the snarf info
251 ${$_} = $cgi->param($_) foreach grep { /^snarf_/ } $cgi->param;
255 'pkgpart' => scalar($cgi->param('pkgpart')),
260 } elsif ( $magic eq 'success' || $action eq 'success' ) {
262 $cgi->param('username', 'username'); #hmmm temp kludge
263 $cgi->param('_password', 'password');
264 print_okay( map { /^([\w ]+)$/ ? ( $_ => $1 ) : () } $cgi->param ); #hmmm
266 } elsif ( $magic eq 'decline' || $action eq 'decline' ) {
277 $error = "Error: $error" if $error;
285 $r->{pkgpart} ||= $r->{default_pkgpart};
287 $r->{referral_custnum} = $r->{'ref'};
288 #$cgi->delete('ref');
289 #$cgi->delete('init_popstate');
290 $r->{self_url} = $cgi->self_url;
292 print $cgi->header( '-expires' => 'now' ),
293 $signup_template->fill_in( PACKAGE => 'FS::SelfService::_signupcgi',
300 $error = "Error: $error" if $error;
308 $r->{pkgpart} ||= $r->{default_pkgpart};
310 $r->{referral_custnum} = $r->{'ref'};
311 $r->{self_url} = $cgi->self_url;
313 print $cgi->header( '-expires' => 'now' ),
314 $collect_template->fill_in( PACKAGE => 'FS::SelfService::_signupcgi',
320 print $cgi->header( '-expires' => 'now' ),
321 $decline_template->fill_in();
326 my $user_agent = new HTTP::BrowserDetect $ENV{HTTP_USER_AGENT};
328 my( $username, $password ) = ( '', '' );
329 my( $countrycode, $phonenum, $sip_password, $pin ) = ( '', '', '', '' );
331 my $svc_x = $param{signup_service} || 'svc_acct'; #just in case
332 if ( $svc_x eq 'svc_acct' ) {
334 $cgi->param('username') =~ /^(.+)$/
335 or die "fatal: invalid username got past FS::SelfService::new_customer";
337 $cgi->param('_password') =~ /^(.+)$/
338 or die "fatal: invalid password got past FS::SelfService::new_customer";
341 } elsif ( $svc_x eq 'svc_phone' ) {
343 $countrycode = $param{countrycode};
344 $phonenum = $param{phonenum};
345 $sip_password = $param{sip_password};
349 die "unknown signup service $svc_x";
352 ( $cgi->param('first'). ' '. $cgi->param('last') ) =~ /^(.*)$/
353 or die "fatal: invalid email_name got past FS::SelfService::new_customer";
354 my $email_name = $1; #global for template
358 foreach ( @{ $init_data->{'svc_acct_pop'} } ) {
359 #push @{ $pop{ $_->{state} }->{ $_->{ac} } }, $_;
360 $popnum2pop{$_->{popnum}} = $_;
363 my( $ac, $exch, $loc);
364 my $pop = $popnum2pop{$cgi->param('popnum')};
365 #or die "fatal: invalid popnum got past FS::SelfService::new_customer";
367 ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
369 ( $ac, $exch, $loc ) = ( '', '', ''); #presumably you're not using them.
373 my $part_pkg = ( grep { $_->{'pkgpart'} eq $param{'pkgpart'} }
374 @{ $init_data->{'part_pkg'} }
376 my $pkg = $part_pkg->{'pkg'};
378 if ( $ieak_template && $user_agent->windows && $user_agent->ie ) {
381 print $cgi->header('application/x-Internet-signup'),
382 $ieak_template->fill_in();
384 } else { #send a simple confirmation
386 print $cgi->header( '-expires' => 'now' ),
387 $success_template->fill_in( HASH => {
389 email_name => $email_name,
391 part_pkg => \$part_pkg,
393 signup_service => $svc_x,
396 username => $username,
397 password => $password,
398 _password => $password,
399 ac => $ac, #for dialup POP
404 countrycode => $countrycode,
405 phonenum => $phonenum,
406 sip_password => $sip_password,
414 sub success_default { #html to use if you don't specify a success file
416 <HTML><HEAD><TITLE>Signup successful</TITLE></HEAD>
417 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Signup successful</FONT><BR><BR>
418 Thanks for signing up!
420 Signup information for <%= $email_name %>:
422 Username: <%= $username %><BR>
423 Password: <%= $password %><BR>
424 Access number: (<%= $ac %>) / <%= $exch %> - <%= $local %><BR>
425 Package: <%= $pkg %><BR>
430 sub collect_default { #html to use if there is a collect phase
432 <HTML><HEAD><TITLE>Pay now</TITLE></HEAD>
433 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Pay now</FONT><BR><BR>
434 <SCRIPT TYPE="text/javascript">
435 function popcollect() {
436 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' );
440 <SCRIPT TYPE="text/javascript" SRC="overlibmws.js"></SCRIPT>
441 <SCRIPT TYPE="text/javascript" SRC="overlibmws_iframe.js"></SCRIPT>
442 <SCRIPT TYPE="text/javascript" SRC="overlibmws_draggable.js"></SCRIPT>
443 <SCRIPT TYPE="text/javascript" SRC="overlibmws_crossframe.js"></SCRIPT>
444 <SCRIPT TYPE="text/javascript" SRC="iframecontentmws.js"></SCRIPT>
445 You are about to contact our payment processor to pay <%= $amount %> for
447 Your transaction reference number is <%= $reference %><BR><BR>
448 <FORM NAME="collect_popper" method="post" action="javascript:void(0)" onSubmit="popcollect()">
450 my %itemhash = @collectitems;
451 foreach my $input (keys %itemhash) {
452 $OUT .= qq!<INPUT NAME="$input" TYPE="hidden" VALUE="$itemhash{$input}">!;
455 <INPUT NAME="submit" type="submit" value="Pay now">
461 sub decline_default { #html to use if there is a decline
463 <HTML><HEAD><TITLE>Processing error</TITLE></HEAD>
464 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Processing error</FONT><BR><BR>
465 There has been an error processing your account. Please contact customer
471 # subs for the templates...
473 package FS::SelfService::_signupcgi;
475 use FS::SelfService qw(regionselector expselect popselector didselector);