Template:2012FR/Form-section/Processing/Default: Difference between revisions

Content deleted Content added
rename redirectPayment, add way to skip validation (for USD methods where there's no need to select an amount)
note why this is kept
 
(26 intermediate revisions by 2 users not shown)
Line 1:
<!-- Merged to MediaWiki:DonationForm.js. Kept this page for the history. -->
<html>
<script>
var donationForm = {};
 
function redirectPayment (legacyPaymentMethod) {
// wrapper for new function
// using old method parameters
// until buttons can be updated
 
switch (legacyPaymentMethod) {
case 'cc':
donationForm.redirectPayment('cc');
break;
 
case 'paypal':
case 'pp':
case 'ew-pp':
case 'ew-rpp':
case 'ew-pp-usd':
case 'ew-pp-eur':
donationForm.redirectPayment('paypal');
break;
 
case 'dd':
donationForm.redirectPayment('dd');
break;
 
case 'rtbt-id':
donationForm.redirectPayment('rtbt', 'rtbt_ideal');
break;
 
case 'ew-yd':
donationForm.redirectPayment('ew', 'ew_yandex');
break;
 
case 'rtbt-sf':
donationForm.redirectPayment('rtbt', 'rtbt_sofortuberweisung');
break;
 
case 'ew-amazon':
donationForm.redirectPayment('amazon');
break;
 
case 'obt-bp':
donationForm.redirectPayment('obt', 'bpay');
break;
 
case 'ew-wm':
donationForm.redirectPayment('ew', 'ew_webmoney');
break;
 
case 'cash-bl':
donationForm.redirectPayment('cash', 'boleto');
break;
 
case 'rtbt-en':
donationForm.redirectPayment('rtbt', 'rtbt_enets');
break;
}
 
}
 
donationForm.redirectPayment = function(paymentMethod, paymentSubMethod, skipValidation) {
 
// set up inputs
document.getElementsByName("currency_code")[0].value = '</html>{{{currency|USD}}}<html>';
 
if (typeof paymentSubMethod == 'undefined') {
paymentSubMethod = '';
}
var form = document.paypalcontribution; // we should really change this some day
var paymentsURL = 'https://payments.wikimedia.org/index.php/Special:GatewayFormChooser';
var params = {
'uselang' : $("input[name='language']").val(),
'language' : $("input[name='language']").val(),
'currency' : $("input[name='currency_code']").val(),
'country' : $("input[name='country']").val(),
'paymentmethod' : paymentMethod
};
if( paymentSubMethod != '' ){
params['submethod'] = paymentSubMethod;
}
// Testing for Adyen
if( paymentMethod === 'adyen-cc' ) {
paymentMethod = 'cc';
params.paymentmethod = 'cc';
params.gateway = 'adyen';
}
var frequency = $("input[name='frequency']:checked").val();
if( frequency !== 'monthly' ){
frequency = 'onetime';
// commented out below as it breaks eNETS for some reason
// params['recurring'] = 'false';
} else {
params['recurring'] = 'true';
// the following causes tons of errors. Don't.
// paymentMethod = 'r' + paymentMethod;
}
form.action = paymentsURL + '?' + $.param(params);
form.payment_method.value = paymentMethod;
if( paymentSubMethod != '' ){
form.payment_method.value = form.payment_method.value + '.' + paymentSubMethod;
}
 
donationForm.addAnalytics();
if (validateForm(form) || skipValidation) {
form.method = "POST";
form.submit();
}
}
 
donationForm.addAnalytics = function() {
// stuffs parameters into utm_source to make them available for analytics
 
var form = document.paypalcontribution;
 
form.utm_source.value = getQuerystring( 'utm_source' ) + '.';
 
if(getQuerystring( 'template' ) == '') {
form.utm_source.value += 'default' + '~';
} else {
form.utm_source.value += getQuerystring( 'template' ).replace("Lp-layout-","") + '~';
}
 
if(getQuerystring( 'appeal-template' ) == '') {
form.utm_source.value += 'default' + '~';
} else {
form.utm_source.value += getQuerystring( 'appeal-template' ).replace("Appeal-template-","") + '~';
}
 
if(getQuerystring( 'appeal' ) == '') {
form.utm_source.value += 'default' + '~';
} else {
form.utm_source.value += getQuerystring( 'appeal' ).replace("Appeal-","") + '~';
}
 
if(getQuerystring( 'form-template' ) == '') {
form.utm_source.value += 'default' + '~';
} else {
form.utm_source.value += getQuerystring( 'form-template' ).replace("Form-template-","") + '~';
}
 
if(getQuerystring( 'form-countryspecific' ) == '') {
form.utm_source.value += 'control';
} else {
form.utm_source.value += getQuerystring( 'form-countryspecific' ).replace("Form-countryspecific-","");
}
 
form.utm_source.value += '.' + form.payment_method.value;
form.utm_campaign.value = getQuerystring( 'utm_campaign' );
}
 
donationForm.toggleMonthly = function(monthly) {
if (monthly) {
$('#form-wrapper').addClass('form-monthly');
} else {
$('#form-wrapper').removeClass('form-monthly');
}
}
</script>
</html>