diff --git a/cgi/procdonate.cgi b/cgi/procdonate.cgi index 2a768b2..f2860c6 100755 --- a/cgi/procdonate.cgi +++ b/cgi/procdonate.cgi @@ -1,793 +1,813 @@ #!/usr/bin/perl -T # procdonate.cgi - Donation payment processor for gnupg.org # Copyright (C) 2014 g10 Code GmbH # # This file is free software; as a special exception the author gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. use strict; use CGI; use Cwd qw(realpath); use IO::Socket::UNIX; realpath($0) =~ /^(.*)\/.*$/; my %config = do $1 . '/config.rc'; my $baseurl = $config{baseurl}; my $htdocs = $config{htdocs}; my $stripepubkey = $config{stripepubkey}; my $socket_name = $config{payprocd_socket}; my $error_marker = '* error'; # The form variables are accessed via Q. my $q = new CGI; # This is a multi-purpose CGI. The mode decides what to do. my $mode = $q->param("mode"); my $sessid = $q->param("sessid"); # Variables used in the template pages. my $amount = ""; my $paytype = ""; my $stripeamount = ""; my $euroamount = ""; my $currency = ""; my $recur = ""; my $name = ""; my $mail = ""; my $message = ""; my $separef = ""; my $errorstr = ""; # We use a dictionary to track error. Those errors will then be # inserted into the output by write_template. my %errdict = (); # Prototypes sub fail ($); sub get_paypal_approval (); sub complete_sepa (); # Write a template file. A template is a proper HTML file with # variables enclosed in HTML comments. To allow inserting data into # a value attribute of an input field, such a tag needs to be written as # # the result after processing will be # # assuming that the value of FOO is foo. Note that this substitution # rules work for all tags and thus you better take care to add an # extra space if you do not want this to happen. sub write_template ($) { my $fname = shift; my $errorpanel = $errorstr; my $err_amount = ''; my $err_name = ''; my $err_mail = ''; my $err_paytype = ''; my $check_checked = ' checked="checked"'; my $sel_eur = ''; my $sel_usd = ''; my $sel_gbp = ''; my $sel_jpy = ''; my $recur_none = ''; my $recur_month = ''; my $recur_quarter = ''; my $recur_year = ''; my $recur_text = ''; my $message_fmt; my $publishname; my $check_paytype = 'none'; my $stripe_data_email = ''; + my $stripe_data_label_value = 'Donate now'; # Avoid broken HTML attributes. $amount =~ s/\x22/\x27/g; $stripeamount =~ s/\x22/\x27/g; $currency =~ s/\x22/\x27/g; $recur =~ s/\x22/\x27/g; $name =~ s/\x22/\x27/g; $mail =~ s/\x22/\x27/g; $message =~ s/\x22/\x27/g; $separef =~ s/\x22/\x27/g; # Clean possible user provided data $sessid =~ s//g; if ( $currency =~ /EUR/i ) { $sel_eur = ' selected="selected"'; } elsif ( $currency =~ /USD/i ) { $sel_usd = ' selected="selected"'; } elsif ( $currency =~ /GBP/i ) { $sel_gbp = ' selected="selected"'; } elsif ( $currency =~ /JPY/i ) { $sel_jpy = ' selected="selected"'; } # For non-recurring Stripe donations we do not want to send a # data-email="$mail" # line to Stripe so to enable the user to use a a different mail # address for use with them. This is implemented using a # STRIPE_DATA_EMAIL template variable. $stripe_data_email = 'data-email="' . $mail . '"'; if ( $recur =~ /0/ ) { $stripe_data_email = ''; $recur_none = ' selected="selected"'; $recur_text = ''; } elsif ( $recur =~ /12/ ) { $recur_month = ' selected="selected"'; $recur_text = 'monthly'; + $stripe_data_label_value = 'Donate monthly'; } elsif ( $recur =~ /4/ ) { $recur_quarter = ' selected="selected"'; $recur_text = 'quarterly'; + $stripe_data_label_value = 'Donate quarterly'; } elsif ( $recur =~ /1/ ) { $recur_year = ' selected="selected"'; $recur_text = 'yearly'; + $stripe_data_label_value = 'Donate yearly'; } if ( $paytype eq "cc" ) { $check_paytype = "CC"; } elsif ( $paytype eq "pp" ) { $check_paytype = "PP"; } elsif ( $paytype eq "se" ) { $check_paytype = "SE"; } # Set var for the paypal button if ( $name eq 'Anonymous' or $name eq '') { $publishname = 'No'; } else { $publishname = 'Yes'; } # Build error strings. foreach (keys %errdict) { if (/amount/) { $err_amount = $error_marker; } elsif (/name/) { $err_name = $error_marker; } elsif (/mail/) { $err_mail = $error_marker; } elsif (/paytype/){ $err_paytype = $error_marker; } $errorpanel = $errorpanel . "Field $_: " . $errdict{$_} . "
\n" } if ( $errorpanel ne '' ) { $errorpanel = "

\n" . $errorpanel . "

\n"; } open TEMPLATE, $htdocs . $fname; while (