5 use vars qw( $cgi $self_url $error
6 $collect_html $collect_template
9 use subs qw( print_redirect print_collect collect_default );
12 use Business::CreditCard;
14 my $redirect_url = "http://127.0.0.1/selfservice/verify.cgi";
16 $collect_html = -e 'collect.html'
18 : '/usr/local/freeside/collect.html';
20 if ( -e $collect_html ) {
21 my $collect_txt = Text::Template::_load_text($collect_html)
22 or die $Text::Template::ERROR;
23 $collect_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
25 $collect_template = new Text::Template ( TYPE => 'STRING',
26 SOURCE => $collect_txt,
27 DELIMITERS => [ '<%=', '%>' ],
29 or die $Text::Template::ERROR;
31 $collect_template = new Text::Template ( TYPE => 'STRING',
32 SOURCE => &collect_default,
33 DELIMITERS => [ '<%=', '%>' ],
35 or die $Text::Template::ERROR;
40 if ( defined($cgi->param('magic')) && $cgi->param('magic') eq 'process' ) {
44 $cgi->param('paydate' => $cgi->param( 'month' ). '-'.
48 my $payinfo = $cgi->param('payinfo');
50 $payinfo =~ /^(\d{13,16})$/ or $error ||= "Invalid card";
52 validate($payinfo) or $error ||= "Invalid card";
54 my %rv = ( map { $_ => scalar($cgi->param($_)) } qw( reference amount ) );
57 $error = '_decline' unless $payinfo eq '4111111111111111';
60 if ( $error eq '_decline' ) {
62 $rv{message} = 'Declined';
63 print_redirect( %rv );
64 } elsif ( $error eq '_collect' ) {
70 $rv{message} = 'Approved';
71 print_redirect( %rv );
81 $error = "Error: $error" if $error;
83 my $r = { $cgi->Vars, 'error' => $error };
85 $r->{self_url} = $cgi->self_url;
87 print $cgi->header( '-expires' => 'now' ),
88 $collect_template->fill_in( PACKAGE => 'FS::SelfService::_signupcgi',
97 my $param = join('&', map { "$_=". $param{$_} } keys %param );
99 print $cgi->redirect( '-uri' => $redirect_url. '?'. $param );
102 sub collect_default { #html to use if there is a collect phase
104 <HTML><HEAD><TITLE>Pay now</TITLE></HEAD>
105 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Pay now</FONT><BR><BR>
106 <FONT SIZE="+1" COLOR="#FF00000"><%= $error %></FONT><BR>
107 You are about to contact our payment processor to pay <%= $amount %> for
109 Your transaction reference number is <%= $reference %><BR><BR>
110 <FORM NAME="collect_popper" method="post" action="<%= $self_url %>">
111 <INPUT NAME="magic" TYPE="hidden" VALUE="process">
112 <INPUT NAME="amount" TYPE="hidden" VALUE="<%= $amount %>">
113 <INPUT NAME="reference" TYPE="hidden" VALUE="<%= $reference %>">
114 Card Number:<INPUT NAME="payinfo" TYPE="text" VALUE=""><BR>
115 <INPUT NAME="submit" type="submit" value="Pay now">
121 # subs for the templates...
123 package FS::SelfService::_signupcgi;