MediaWiki:DonationForm T201415.js: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
only include referrer param if needed
currency, country, language, pym_variant, pym_appeal
Line 213: Line 213:
/* Localize the amount errors. Call when initialising form. */
/* Localize the amount errors. Call when initialising form. */
donationForm.localizeErrors = function() {
donationForm.localizeErrors = function() {
var form = document.forms['donateForm'];
var currency = donationForm.currency;
var currency = form.currency_code.value;
var minAmount = donationForm.minimums[ currency ];
var minAmount = donationForm.minimums[ currency ];


Line 253: Line 252:
var hpcSet = mw.util.getParamValue('hpcSet');
var hpcSet = mw.util.getParamValue('hpcSet');


var currency = $("input[name='currency_code']").val();
var currency = donationForm.currency;
var language = mw.config.get('wgUserLanguage');
var language = mw.config.get('wgUserLanguage');


Line 707: Line 706:
}
}


// Default to variant = panExplain for India
params.payment_method = paymentMethod;
if ( paymentSubMethod ) {
// TODO: make this default payments side - https://phabricator.wikimedia.org/T259146
params.payment_submethod = paymentSubMethod;
if ( mw.util.getParamValue('country') === 'IN' ) {
params.variant = 'panExplain';
}
}


Line 719: Line 717:
} else {
} else {
params.recurring = true;
params.recurring = true;
}

params.payment_method = paymentMethod;
if ( paymentSubMethod ) {
params.payment_submethod = paymentSubMethod;
}
}


Line 732: Line 725:
}
}
params.amount = amount;
params.amount = amount;

params.currency_code = donationForm.currency;
params.uselang = mw.config.get('wgUserLanguage');
params.country = donationForm.country;


/* Email optin */
/* Email optin */
Line 737: Line 734:
var opt_inValue = $('input[name="opt_in"]:checked').val();
var opt_inValue = $('input[name="opt_in"]:checked').val();
params.opt_in = opt_inValue; // donationForm.validate() already checked it's 1 or 0
params.opt_in = opt_inValue; // donationForm.validate() already checked it's 1 or 0
}

// Default to variant = panExplain for India
// TODO: make this default payments side - https://phabricator.wikimedia.org/T259146
if ( donationForm.country === 'IN' ) {
params.variant = 'panExplain';
}

if ( mw.util.getParamValue( 'pym_variant' ) ) {
params.variant = mw.util.getParamValue( 'pym_variant' );
}
if ( mw.util.getParamValue( 'pym_appeal' ) ) {
params.appeal = mw.util.getParamValue( 'pym_appeal' );
}
}


Line 907: Line 917:
donationForm.validateAmount = function() {
donationForm.validateAmount = function() {


var form = document.forms['donateForm'];
var amount = donationForm.getAmount();
var amount = donationForm.getAmount();
var minAmount = donationForm.minimums[ donationForm.currency ] || 1;
var currency = form.currency_code.value;
var minAmount = donationForm.minimums[ currency ] || 1;


if ( amount === null || isNaN(amount) || amount <= 0 || amount < minAmount ) {
if ( amount === null || isNaN(amount) || amount <= 0 || amount < minAmount ) {
Line 983: Line 991:


var feeMultiplier = 0.04,
var feeMultiplier = 0.04,
feeMinimum = feeMinimums[ form.currency_code.value ] || 0.35,
feeMinimum = feeMinimums[ donationForm.currency ] || 0.35,
feeAmount = amount * feeMultiplier;
feeAmount = amount * feeMultiplier;


Line 1,019: Line 1,027:


var form = document.forms['donateForm'];
var form = document.forms['donateForm'];

// These get used in quite a few places
donationForm.currency = form.currency_code.value;
donationForm.country = mw.util.getParamValue('country');


// Block typing symbols in input field, otherwise Safari allows them and then chokes
// Block typing symbols in input field, otherwise Safari allows them and then chokes
Line 1,062: Line 1,074:


// hide frequency options for some countries
// hide frequency options for some countries
if ( donationForm.noRecurringCountries.indexOf( form.country.value ) !== -1 ) {
if ( donationForm.noRecurringCountries.indexOf( donationForm.country ) !== -1 ) {
$('#frequency_onetime').prop('checked', true);
$('#frequency_onetime').prop('checked', true);
$('.frequency-options, #cancel-monthly, #donate-recurring-smallprint').hide();
$('.frequency-options, #cancel-monthly, #donate-recurring-smallprint').hide();
}
}


addCardTypesClass( form.country.value );
addCardTypesClass( donationForm.country );
}
}


Line 1,086: Line 1,098:
// Allow preselecting monthly
// Allow preselecting monthly
if( mw.util.getParamValue('monthly')
if( mw.util.getParamValue('monthly')
&& donationForm.noRecurringCountries.indexOf( form.country.value ) === -1 ) {
&& donationForm.noRecurringCountries.indexOf( donationForm.country ) === -1 ) {
$('#frequency_monthly').click();
$('#frequency_monthly').click();
}
}