MediaWiki:DonationForm.js: Difference between revisions

Content deleted Content added
fix use of frb
hacky use of hpcSet for Major Gifts amount changes
 
(164 intermediate revisions by 3 users not shown)
Line 1:
/* jshint strict:false */
/** MediaWiki:DonationForm.js - loaded on all donation forms
* TODO: lots of cleanup
Line 5 ⟶ 6:
var donationForm = {};
 
donationForm.minimumsloadedTime = {Date.now();
donationForm.extraData = {};
/* From https://github.com/wikimedia/wikimedia-fundraising-SmashPig/blob/master/PaymentData/ReferenceData/CurrencyRates.php */
 
'ADF' : 5.65,
donationForm.country = mw.util.getParamValue('country').toUpperCase();
'ADP' : 143,
try {
donationForm.currency = document.forms.donateForm.currency_code.value;
} catch (error) {
donationForm.currency = 'USD';
}
 
/**
* Make language and country into a standard javascript Intl locale identifier
*
* @param {string} language
* @param {string} country
* @return {string} locale identifier e.g. en-GB
*/
donationForm.getLocale = function( language, country ) {
// Sometimes in email testing links the uselang is a variable contiaining %
// In that case fall back to English so locale code doesn't break form
if ( language.match('%') ) {
language = 'en';
}
if ( language === 'en-gb' ) {
language = 'en';
}
if ( language === 'es-419' ) {
language = 'es';
}
if ( language === 'pt-br' ) {
language = 'pt';
}
return language + '-' + country;
};
 
donationForm.locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country );
 
 
// Don't offer recurring at all in these countries
donationForm.noRecurringCountries = [ 'AR', 'IN' ];
 
donationForm.noRecurringPaypalCountries = [ 'CL', 'CO', 'PE', 'UY', 'BR' ];
 
donationForm.currencyRates = {
// From https://github.com/wikimedia/wikimedia-fundraising-SmashPig/blob/master/PaymentData/ReferenceData/CurrencyRates.php
// Updated 2024-07-31
'ADF' : 6.04,
'ADP' : 153,
'AED' : 3.67,
'AFA' : 7370,
'AFN' : 7370,
'ALL' : 10990,
'AMD' : 477368,
'ANG' : 1.79,
'AOA' : 278844,
'AON' : 278844,
'ATSARS' : 12887,
'AUDATS' : 1.3913,
'AWGAUD' : 1.785,
'AZMAWG' : 84861.79,
'AZM' : 8500,
'AZN' : 1.7,
'BAM' : 1.698,
'BBD' : 2,
'BDT' : 83116,
'BEF' : 3537,
'BGL' : 1.698,
'BGN' : 1.698,
'BHD' : 0.3837355757356689,
'BIF' : 17482842,
'BMD' : 1,
'BND' : 1.3835,
'BOB' : 6.871,
'BRL' : 45.151,
'BSD' : 1,
'BTN' : 7283,
'BWP' : 1113,
'BYR' : 2103532642,
'BZD' : 1.98,
'CAD' : 1.3236,
'CDF' : 15732786,
'CHF' : 0.989094629289448,
'CNYCLP' : 6.83890,
'CRCCNY' : 5727.23,
'COP' : 3803,
'CRC' : 498,
'CUC' : 1,
'CUP' : 25,
'CVE' : 95101,
'CYP' : 0.5153848627984321,
'CZK' : 2223,
'DEM' : 1.698,
'DJF' : 178,
'DKK' : 6.4286,
'DOP' : 5058,
'DZD' : 118133,
'ECS' : 24094,
'EEK' : 1314,
'EGP' : 1847,
'ESP' : 143153,
'ETB' : 2757,
'EUR' : 0.8792005843390143,
'FIM' : 5.1247,
'FJD' : 2.123,
'FKP' : 0.7878703952551207,
'FRF' : 56.6504,
'GBP' : 0.7878703952551207,
'GEL' : 2.5271,
'GHC' : 47467143125,
'GHS' : 4.7514,
'GIP' : 0.7878703952551207,
'GMD' : 4868,
'GNF' : 89838493,
'GRD' : 294314,
'GTQ' : 7.557,
'GYD' : 204200,
'HKD' : 7.858,
'HNL' : 24,
'HRK' : 6.493,
'HTG' : 68132,
'HUF' : 282355,
'IDR' : 1496615986,
'IEP' : 0.6872460490043714,
'ILS' : 3.6169,
'INR' : 7283,
'IQD' : 11781290,
'IRR' : 4200042009,
'ISK' : 109138,
'ITL' : 16691781,
'JMD' : 136154,
'JOD' : 0.7170900000000001,
'JPY' : 112156,
'KES' : 100130,
'KGS' : 6988,
'KHR' : 40253993,
'KMF' : 424453,
'KPW' : 135,
'KRW' : 11201358,
'KWD' : 0.3130629670764681,
'KYD' : 0.8483333299999999,
'KZT' : 369442,
'LAK' : 839321103,
'LBP' : 150889393,
'LKR' : 162298,
'LRD' : 154193,
'LSL' : 1518,
'LTL' : 23.9818,
'LUF' : 3537,
'LVL' : 0.6164662074757963,
'LYD' : 14.378,
'MAD' : 9.3979,
'MDL' : 17,
'MGA' : 33114379,
'MGF' : 9150,
'MKD' : 5356,
'MMK' : 15292075,
'MNT' : 24602620,
'MOP' : 8.0803,
'MRO' : 357391,
'MTL' : 0.3739498108567387,
'MUR' : 3345,
'MVR' : 15,
'MWK' : 7171720,
'MYRMXN' : 4.1517,
'MZMMYR' : 597544.68,
'MZNMZM' : 6063200,
'NADMZN' : 1563,
'NGNNAD' : 35918,
'NIONGN' : 321505,
'NLGNIO' : 1.936,
'NOKNLG' : 82.403,
'NPRNOK' : 11411,
'NZDNPR' : 1.52131,
'OMRNZD' : 01.3963,
'OMR' : 0.38377594841305,
'PAB' : 1,
'PEN' : 3.367,
'PGK' : 3.2676,
'PHP' : 5458,
'PKR' : 123277,
'PLN' : 3.7291,
'PTE' : 173184,
'PYG' : 57637355,
'QAR' : 3.5756,
'ROL' : 3988945713,
'RON' : 34.9957,
'RSD' : 101108,
'RUB' : 6891,
'RWF' : 8621277,
'SAR' : 3.75,
'SBD' : 78.637,
'SCR' : 13,
'SDD' : 179559800,
'SDG' : 18598,
'SDP' : 2261,
'SEK' : 9.0811,
'SGD' : 1.3835,
'SHP' : 0.7878703952551207,
'SIT' : 207220,
'SKK' : 2628,
'SLL' : 843019750,
'SOS' : 542549,
'SRD' : 7.4133,
'SRG' : 740833320,
'STD' : 2107022477,
'SVC' : 8.75,
'SYP' : 215513,
'SZL' : 1518,
'THB' : 3336,
'TJS' : 9.3611,
'TMM' : 1705016750,
'TMT' : 3.4135,
'TND' : 23.7611,
'TOP' : 2.2932,
'TRL' : 662922332168418,
'TRY' : 6.6332,
'TTD' : 6.64,
'TWD' : 3132,
'TZS' : 22812587,
'UAH' : 2839,
'UGX' : 37493760,
'USD' : 1,
'UZSUYU' : 778038,
'VEBUZS' : 605084113612662,
'VEFVEB' : 60508413651907631,
'VNDVEF' : 231503651908,
'VUVVND' : 11125451,
'WSTVUV' : 2.64112,
'XAFWST' : 5652.67,
'XAF' : 604,
'XAG' : 0.031347411860134,
'XAU' : 0.00041128929241299,
'XCD' : 2.7,
'XOFXEU' : 5650.92005843390143,
'XPFXOF' : 103604,
'YERXPD' : 2500.00098009826645798,
'YUNXPF' : 101110,
'ZARXPT' : 150.00093444018680404,
'YER' : 249,
'YUN' : 108,
'ZAR' : 18,
'ZMK' : 5176,
'ZWD' : 373,
};
/* Astropay currencies have higher minimums - 1.50 USD */
 
'ARS' : 58.5,
/* Amount and currency formatting */
'BRL' : 6.23,
let formatters = {
'CLP' : 1035,
// Amounts without currency symbol
'COP' : 4640,
amountFraction: new Intl.NumberFormat( donationForm.locale,
'MXN' : 28.5
{ minimumFractionDigits: 2, maximumFractionDigits: 2 }
),
amountWhole: new Intl.NumberFormat( donationForm.locale,
{}
)
}
 
// currencyDisplay: 'narrowSymbol' fixes some issues like en-CO showing the ISO code
// but browser support is lacking, so wrap in a try/catch
try {
formatters.currencyFraction = new Intl.NumberFormat( donationForm.locale,
{ style: 'currency', currency: donationForm.currency, currencyDisplay: 'narrowSymbol' }
);
formatters.currencyWhole = new Intl.NumberFormat( donationForm.locale,
{ style: 'currency', currency: donationForm.currency, currencyDisplay: 'narrowSymbol', minimumFractionDigits: 0 }
);
} catch(e) {
formatters.currencyFraction = new Intl.NumberFormat( donationForm.locale,
{ style: 'currency', currency: donationForm.currency }
);
formatters.currencyWhole = new Intl.NumberFormat( donationForm.locale,
{ style: 'currency', currency: donationForm.currency, minimumFractionDigits: 0 }
);
}
 
donationForm.formatCurrency = function( amount ) {
if ( amount % 1 !== 0 ) { // Not a whole number
return formatters.currencyFraction.format( amount );
} else {
return formatters.currencyWhole.format( amount );
}
};
 
donationForm.formatAmount = function( amount ) {
var formatterOptions, output;
if ( amount % 1 !== 0 ) { // Not a whole number
return formatters.amountFraction.format( amount );
} else {
return formatters.amountWhole.format( amount );
}
};
 
/* Localize the amount errors. Call when initialising form. */
donationForm.localizeErrors = function() {
var currency = document.paypalcontribution.currency_codedonationForm.valuecurrency;
var minAmount = donationForm.minimums[ currency ];
 
$('.lp-error-smallamount').text( function( index, oldText ) {
return oldText.replace( '$1', minAmountdonationForm.formatAmount( donationForm.minLocal ) + ' \xa0' + currency );
});
 
if ( currency === 'USD' ) {
// we don't need to include the conversion
$('.lp-error-bigamount').text( function( index, oldText ) {
return oldText.replace( '($1 $2) ', '' )
.replace( '($1 $2) ', '' );
});
}
 
$('.lp-error-bigamount').text( function( index, oldText ) {
return oldText.replace( '$1', 10000donationForm.formatAmount( *donationForm.maxLocal minAmount) )
.replace( '$2', currency )
.replace( '$3', 'benefactors@wikimedia.org' );
.replace( '$4', donationForm.formatAmount( donationForm.maxUSD ) );
});
};
 
function getQuerystring( key ) {
// TODO: Replace with mw.util.getParamValue() everywhere, and remove
// note might be relying on different behaviour when parameter not present
key = key.replace( /[\[]/, '\\\[' ).replace( /[\]]/, '\\\]' );
var regex = new RegExp( '[\\?&]' + key + '=([a-zA-Z0-9\.\_\-]*)' );
var qs = regex.exec( window.location.search );
return qs === null ? '' : qs[1];
}
 
function adjustHPC() {
Line 232 ⟶ 327:
TODO: split data out? */
 
var hpcSet = mw.util.getParamValue('hpcSet');
// Look for 'hpc' parameter, then 'mrc'. If neither, then bail out.
 
// Look for 'hpc' parameter, then 'mrc'
var hpc = parseFloat( mw.util.getParamValue('hpc') );
if( isNaN(hpc) ) {
hpc = parseFloat( mw.util.getParamValue('mrc') );
if( isNaN(hpc) ) {
return;if ( hpcSet ) {
// Allow using hpcSet even without hpc, for MG appeals
hpc = 0;
} else {
return;
}
}
}
 
var hpcSetcurrency = mwdonationForm.util.getParamValue('hpcSet')currency;
 
var currency = $("input[name='currency_code']").val();
var language = mw.config.get('wgUserLanguage');
 
// If changing, please update https://docs.google.com/spreadsheets/d/1e02TsZ_bKDAS1BMVBCdyo9D7RGln_wCGnkg7IF5kU5s/edit
var radioAmountsData = {
'"USD'" : { // also used for CAD, AUD, NZD
'"default'" : [
[ 0, [ 2.75, 5, 10, 20, 25, 35, 50, 10050 ] ],
[ 5, [ 5, 10, 15, 20, 35, 50, 100, 150100 ] ],
[ 10, [ 10, 15, 20, 25, 35, 50, 100, 150100 ] ],
[ 15, [ 15, 20, 25, 35, 50, 75, 100, 250100 ] ],
[ 20, [ 20, 25, 35, 50, 75, 100, 150, 250150 ] ],
[ 25, [ 25, 30, 40, 50, 75, 100, 150, 250150 ] ],
[ 35, [ 25 35, 50, 75, 100, 200, 250 300, 300 500 ] ],
[ 7550, [ 25, 50, 75, 100, 200, 300, 500, 750 ] ],
[ 100 75, [ 25, 5075, 100, 150, 250, 500, 750, 1000 ] ],
[ 150100, [ 50, 100, 150, 200 250, 350 500, 500 750, 1000, 2500 ] ],
[ 200150, [ 100, 150, 200, 300, 400 500, 500 750, 1000, 2000 ] ],
[ 500200, [ 100 200, 250 300, 500, 750, 1000, 1500 2500, 2000 5000 ] ],
[ 1000 500, [ 500, 1000 750, 2000 1000, 2500, 3000 5000, 4000 7500, 500010000 ] ],
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ],
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
'LTLA'"FY2425_E1_T11_USD" : [ // Upgrade recurring +1 for lowest ask
[ 0, [ 3.75, 10 5, 15 10, 20, 35 25, 50 35, 100 50 ] ],
[ 5, [ 5, 10, 15, 20, 35, 50, 100, 150100 ] ],
[ 10, [ 10, 20 15, 35 20, 50 25, 75 35, 100 50, 150 100 ] ],
[ 15, [ 15, 20, 25, 35, 50, 75, 100, 250100 ] ],
[ 20, [ 20, 30 25, 35, 50, 75, 100, 150, 250150 ] ],
[ 25, [ 25, 35 30, 40, 50, 75, 100, 150, 250150 ] ],
[ 35, [ 25 35, 50, 75, 100, 200, 250 300, 300 500 ] ],
[ 7550, [ 25, 50, 75, 100, 200, 300, 500, 750 ] ],
[ 100 75, [ 25, 5075, 100, 150, 250, 500, 750, 1000 ] ],
[ 150100, [ 50, 100, 150, 200 250, 350 500, 500 750, 1000, 2500 ] ],
[ 200150, [ 100, 150, 200, 300, 400 500, 500 750, 1000, 2000 ] ],
[ 500200, [ 100 200, 250 300, 500, 750, 1000, 1500 2500, 2000 5000 ] ],
[ 1000 500, [ 500, 1000 750, 2000 1000, 2500, 3000 5000, 4000 7500, 500010000 ] ],
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ],
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
'midtier2018'"FY2425_E1_T14_USD" : [ // Upgrade recurring amount dynamically
[ 0, [ 32.75, 5, 10, 20, 30 25, 50 35, 100 50 ] ],
[ 5, [ 2.75, 5, 10, 20, 35 25, 50 35, 100, 15050 ] ],
[ 10, [ 2.75, 10, 15, 20, 35 25, 50 35, 100, 15050 ] ],
[ 15, [ 153.50, 2010, 25 20, 35 30, 50, 100 75, 150 100 ] ],
[ 20, [ 203.75, 10, 25, 35, 50, 75, 100, 150100 ] ],
[ 25, [ 354.50, 5010, 75 25, 100 35, 150 50, 250 75, 500 100 ] ],
[ 35, [ 506.75, 7515, 100 30, 150 50, 250 75, 350 100, 500 150 ] ],
[ 5075, [ 15.75, 10050, 150 75, 200 100, 250 200, 350 300, 500 ] ],
[ 75100, [ 10024.75, 15050, 200 75, 300 100, 400 200, 500 300, 1000 500 ] ],
[ 100150, [ 44.75, 150 100, 200150, 250, 300, 400500, 500 750, 1000 ] ],
[ 150200, [ 200 50, 250100, 300 150, 400 250, 500, 1000 750, 2500 1000 ] ],
[ 200500, [ 500 150, 750250, 1000 300, 2000 500, 3500 750, 50001000, 7500 2000 ] ],
[ 5001000, [ 750 250, 1000500, 1500 750, 25001000, 5000 2500, 7500 5000, 10000 ] ],
[ 10003000, [ 500, 1000, 2000, 3000, 40003500, 5000, 7500, 10000 ] ]
],
'LT2018'"FY2425_E1_T21_USD" : [ // Give less reactivation amount
[ 0, [ 2.75, 5, 10, 20.18, 25, 35, 50, 100 ] ],
[ 5, [ 2.75, 10 5, 15 10, 20.18, 35 25, 50 35, 100, 15050 ] ],
[ 10, [ 15 5, 20.18 10, 25 15, 35 20, 50 35, 100 50, 150 100 ] ],
[ 15, [ 20.18 10, 25 15, 35 20, 50 25, 75 35, 100 50, 250 100 ] ],
[ 20, [ 25 15, 35 20, 50 25, 75 35, 100 50, 150 75, 250 100 ] ],
[ 25, [ 30 20, 40 25, 35, 50, 75, 100, 150, 250150 ] ],
[ 35, [ 25, 50 30, 75 40, 100 50, 200 75, 250 100, 300 150 ] ],
[ 75, [ 25 35, 50, 75, 100, 200, 300, 500 ] ],
[ 100, [ 25, 5075, 100, 150, 250, 500, 750, 1000 ] ],
[ 150, [ 50, 100, 150, 200 250, 350 500, 500 750, 1000, 2500 ] ],
[ 200, [ 100, 150, 200, 300, 400 500, 500 750, 1000, 2000 ] ],
[ 500, [ 100 200, 250 300, 500, 750, 1000, 1500 2500, 2018 5000 ] ],
[ 1000, [ 500, 1000 750, 2018 1000, 2500, 3000 5000, 4000 7500, 500010000 ] ],
[ 3000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ]
]
},
'BRL'"EUR" : [{
["default" 0,: [ 15, 25, 50, 75, 100, 150, 300 ] ],
[ 50, [ 2.50, 25, 355, 50 10, 75 20, 100 25, 200 35, 300 50 ] ],
[ 10 5, [ 30 5, 50 10, 75 15, 100 20, 150 35, 300 50, 500100 ] ],
[ 1510, [ 5010, 75 15, 100 20, 150 25, 225 35, 300 50, 500100 ] ],
[ 2015, [ 5015, 100 20, 150 25, 225 35, 300 50, 400 75, 500100 ] ],
[ 2520, [ 7520, 125 25, 200 35, 250 50, 300 75, 400100, 500150 ] ],
[ 3525, [ 100 25, 150 30, 225 40, 300 50, 500 75, 750100, 1000 150 ] ],
[ 7535, [ 100 35, 150 50, 225 75, 300 100, 500200, 1000 300, 1500 500 ] ],
[ 100 50, [ 100 50, 150 75, 300 100, 500 200, 1000 300, 1500 500, 3000 750 ] ],
[ 150 75, [ 250 75, 500 100, 750 150, 1000 250, 1500 500, 3000 750, 50001000 ] ],
[ 200100, [ 500100, 1000 150, 2000 250, 3000 500, 4000 750, 50001000, 10000 2500 ] ],
[ 500150, [ 1000 150, 2500 200, 5000 300, 7500 500, 10000 750, 12500 1000, 15000 2000 ] ],
[ 1000 200, [ 1000 200, 2500 300, 5000 500, 7500 750, 10000 1000, 12500 2500, 15000 5000 ] ],
[ 500, [ 500, 750, 1000, 2500, 5000, 7500, 10000 ] ],
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ],
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
"FY2425_E1_T11_EUR" : [ // Upgrade recurring +1 for lowest ask
[ 0, [ 3.50, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 5, 10, 15, 20, 35, 50, 100 ] ],
[ 10, [ 10, 15, 20, 25, 35, 50, 100 ] ],
[ 15, [ 15, 20, 25, 35, 50, 75, 100 ] ],
[ 20, [ 20, 25, 35, 50, 75, 100, 150 ] ],
[ 25, [ 25, 30, 40, 50, 75, 100, 150 ] ],
[ 35, [ 35, 50, 75, 100, 200, 300, 500 ] ],
[ 50, [ 50, 75, 100, 200, 300, 500, 750 ] ],
[ 75, [ 75, 100, 150, 250, 500, 750, 1000 ] ],
[ 100, [ 100, 150, 250, 500, 750, 1000, 2500 ] ],
[ 150, [ 150, 200, 300, 500, 750, 1000, 2000 ] ],
[ 200, [ 200, 300, 500, 750, 1000, 2500, 5000 ] ],
[ 500, [ 500, 750, 1000, 2500, 5000, 7500, 10000 ] ],
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ],
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
"FY2425_E1_T14_EUR" : [ // Upgrade recurring amount dynamically
[ 0, [ 2.50, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 2.50, 5, 10, 20, 25, 35, 50 ] ],
[ 10, [ 2.50, 10, 15, 20, 25, 35, 50 ] ],
[ 15, [ 2.50, 10, 20, 30, 50, 75, 100 ] ],
[ 20, [ 3.50, 10, 25, 35, 50, 75, 100 ] ],
[ 25, [ 4.25, 10, 25, 35, 50, 75, 100 ] ],
[ 35, [ 6.25, 15, 30, 50, 75, 100, 150 ] ],
[ 75, [ 15, 50, 75, 100, 200, 300, 500 ] ],
[ 100, [ 25, 50, 75, 100, 200, 300, 500 ] ],
[ 150, [ 45, 100, 150, 250, 500, 750, 1000 ] ],
[ 200, [ 50, 100, 150, 250, 500, 750, 1000 ] ],
[ 500, [ 150, 250, 300, 500, 750, 1000, 2000 ] ],
[ 1000, [ 250, 500, 750, 1000, 2500, 5000, 10000 ] ],
[ 3000, [ 500, 1000, 2000, 3500, 5000, 7500, 10000 ] ]
],
"FY2425_E1_T21_EUR" : [ // Give less reactivation amount
[ 0, [ 2.50, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 2.50, 5, 10, 20, 25, 35, 50 ] ],
[ 10, [ 5, 10, 15, 20, 35, 50, 100 ] ],
[ 15, [ 10, 15, 20, 25, 35, 50, 100 ] ],
[ 20, [ 15, 20, 25, 35, 50, 75, 100 ] ],
[ 25, [ 20, 25, 35, 50, 75, 100, 150 ] ],
[ 35, [ 25, 30, 40, 50, 75, 100, 150 ] ],
[ 75, [ 35, 50, 75, 100, 200, 300, 500 ] ],
[ 100, [ 75, 100, 150, 250, 500, 750, 1000 ] ],
[ 150, [ 100, 150, 250, 500, 750, 1000, 2500 ] ],
[ 200, [ 150, 200, 300, 500, 750, 1000, 2000 ] ],
[ 500, [ 200, 300, 500, 750, 1000, 2500, 5000 ] ],
[ 1000, [ 500, 750, 1000, 2500, 5000, 7500, 10000 ] ],
[ 3000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ]
]
},
"GBP" : {
"default" : [
[ 0, [ 2, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 5, 10, 15, 20, 35, 50, 100 ] ],
[ 10, [ 10, 15, 20, 25, 35, 50, 100 ] ],
[ 15, [ 15, 20, 25, 35, 50, 75, 100 ] ],
[ 20, [ 20, 25, 35, 50, 75, 100, 150 ] ],
[ 25, [ 25, 30, 40, 50, 75, 100, 150 ] ],
[ 35, [ 35, 50, 75, 100, 200, 300, 500 ] ],
[ 50, [ 50, 75, 100, 200, 300, 500, 750 ] ],
[ 75, [ 75, 100, 150, 250, 500, 750, 1000 ] ],
[ 100, [ 100, 150, 250, 500, 750, 1000, 2500 ] ],
[ 150, [ 150, 200, 300, 500, 750, 1000, 2000 ] ],
[ 200, [ 200, 300, 500, 750, 1000, 2500, 5000 ] ],
[ 500, [ 500, 750, 1000, 2500, 5000, 7500, 10000 ] ],
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ],
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
"FY2425_E1_T11_GBP" : [ // Upgrade recurring +1 for lowest ask
[ 0, [ 3, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 5, 10, 15, 20, 35, 50, 100 ] ],
[ 10, [ 10, 15, 20, 25, 35, 50, 100 ] ],
[ 15, [ 15, 20, 25, 35, 50, 75, 100 ] ],
[ 20, [ 20, 25, 35, 50, 75, 100, 150 ] ],
[ 25, [ 25, 30, 40, 50, 75, 100, 150 ] ],
[ 35, [ 35, 50, 75, 100, 200, 300, 500 ] ],
[ 50, [ 50, 75, 100, 200, 300, 500, 750 ] ],
[ 75, [ 75, 100, 150, 250, 500, 750, 1000 ] ],
[ 100, [ 100, 150, 250, 500, 750, 1000, 2500 ] ],
[ 150, [ 150, 200, 300, 500, 750, 1000, 2000 ] ],
[ 200, [ 200, 300, 500, 750, 1000, 2500, 5000 ] ],
[ 500, [ 500, 750, 1000, 2500, 5000, 7500, 10000 ] ],
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ],
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
"FY2425_E1_T14_GBP" : [ // Upgrade recurring amount dynamically
[ 0, [ 2, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 2, 5, 10, 20, 25, 35, 50 ] ],
[ 10, [ 2, 10, 15, 20, 25, 35, 50 ] ],
[ 15, [ 2, 10, 20, 30, 50, 75, 100 ] ],
[ 20, [ 3, 10, 25, 35, 50, 75, 100 ] ],
[ 25, [ 4, 10, 25, 35, 50, 75, 100 ] ],
[ 35, [ 6, 15, 30, 50, 75, 100, 150 ] ],
[ 75, [ 15, 50, 75, 100, 200, 300, 500 ] ],
[ 100, [ 20, 50, 75, 100, 200, 300, 500 ] ],
[ 150, [ 40, 100, 150, 250, 500, 750, 1000 ] ],
[ 200, [ 45, 100, 150, 250, 500, 750, 1000 ] ],
[ 500, [ 125, 250, 300, 500, 750, 1000, 2000 ] ],
[ 1000, [ 200, 500, 750, 1000, 2500, 5000, 10000 ] ],
[ 3000, [ 400, 1000, 2000, 3500, 5000, 7500, 10000 ] ]
],
"FY2425_E1_T21_GBP" : [ // Give less reactivation amount
[ 0, [ 2, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 2, 5, 10, 20, 25, 35, 50 ] ],
[ 10, [ 5, 10, 15, 20, 35, 50, 100 ] ],
[ 15, [ 10, 15, 20, 25, 35, 50, 100 ] ],
[ 20, [ 15, 20, 25, 35, 50, 75, 100 ] ],
[ 25, [ 20, 25, 35, 50, 75, 100, 150 ] ],
[ 35, [ 25, 30, 40, 50, 75, 100, 150 ] ],
[ 75, [ 35, 50, 75, 100, 200, 300, 500 ] ],
[ 100, [ 75, 100, 150, 250, 500, 750, 1000 ] ],
[ 150, [ 100, 150, 250, 500, 750, 1000, 2500 ] ],
[ 200, [ 150, 200, 300, 500, 750, 1000, 2000 ] ],
[ 500, [ 200, 300, 500, 750, 1000, 2500, 5000 ] ],
[ 1000, [ 500, 750, 1000, 2500, 5000, 7500, 10000 ] ],
[ 3000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ]
]
},
"JPY" : [
[ 0, [ 500, 1000, 2000, 2500, 4000, 5000, 10000 ] ],
[ 1000, [ 1000, 1500, 2500, 4000, 5000, 10000, 15000 ] ],
[ 1500, [ 1500, 2000, 3000, 4000, 5000, 10000, 15000 ] ],
[ 2000, [ 2000, 2500, 3500, 5000, 7500, 10000, 25000 ] ],
[ 2500, [ 2500, 3500, 5000, 7500, 10000, 15000, 25000 ] ],
[ 3000, [ 3000, 4000, 5000, 7500, 10000, 15000, 25000 ] ],
[ 2500, [ 2500, 5000, 7500, 10000, 20000, 30000, 50000 ] ],
[ 2500, [ 2500, 5000, 7500, 10000, 20000, 50000, 100000 ] ],
[ 5000, [ 5000, 10000, 15000, 20000, 35000, 50000, 100000 ] ],
[ 10000, [ 10000, 25000, 50000, 75000, 100000, 150000, 200000 ] ]
],
'JPY'"SEK" : [
[ 0, [ 50030, 1000100, 2000150, 2500200, 4000500, 5000750, 100001000 ] ],
[ 550, [ 100050, 1500100, 2500150, 4000200, 5000300, 10000750, 150001000 ] ],
[ 10200, [ 150050, 2000100, 3000200, 4000300, 5000500, 10000750, 150001000 ] ],
[ 15, [ 2000, 2500, 3500, 5000, 7500, 10000, 25000 ] ],
[ 20, [ 2500, 3500, 5000, 7500, 10000, 15000, 25000 ] ],
[ 25, [ 3000, 4000, 5000, 7500, 10000, 15000, 25000 ] ],
[ 35, [ 2500, 5000, 7500, 10000, 20000, 30000, 50000 ] ],
[ 75, [ 2500, 5000, 7500, 10000, 20000, 50000, 100000 ] ],
[ 100, [ 5000, 10000, 15000, 20000, 35000, 50000, 100000 ] ],
[ 500, [ 10000, 25000, 50000, 75000, 100000, 150000, 200000 ] ]
],
'SEK' : [
[ 0, [ 20, 50, 100, 200, 300, 500, 1000 ] ],
[ 3, [ 30, 50, 100, 200, 300, 500, 1000 ] ],
[ 5, [ 50, 100, 150, 200, 300, 500, 1000 ] ],
[ 23, [ 50, 100, 200, 300, 500, 750, 1000 ] ]
]
};
radioAmountsData.AUD = radioAmountsData.USD;
radioAmountsData.CAD = radioAmountsData.USD;
radioAmountsData.GBP = radioAmountsData.USD;
radioAmountsData.NZD = radioAmountsData.USD;
 
radioAmountsData.EUR = radioAmountsData.USD;
// Major gifts appeals, hacky but this is easier than adding a load of new forms to maintain
var currencyList = [ 'USD', 'CAD', 'AUD', 'NZD', 'GBP', 'EUR' ]; // close enough
for ( let i = 0; i < currencyList.length; i++ ) {
radioAmountsData[ currencyList[i] ].MG_2024_500 = [ [ 0, [ 500, 750, 1000, 1250, 1500, 1750, 2000 ] ] ];
radioAmountsData[ currencyList[i] ].MG_2024_650 = [ [ 0, [ 650, 750, 1000, 1250, 1500, 1750, 2000 ] ] ];
}
 
var appealAmountsData = {
'"USD'" : [ // also used for CAD, AUD, NZD, GBP, EUR
[ 0, [ 5, 10, 20 ] ],
[ 10, [ 10, 20, 50 ] ],
Line 362 ⟶ 592:
[ 200, [ 100, 200, 300 ] ]
],
'"JPY'" : [
[ 0, [ 300, 500, 1000 ] ],
[ 3, [ 500, 1000, 1500 ] ],
Line 371 ⟶ 601:
[ 100, [ 5000, 10000, 15000 ] ]
],
'"SEK'" : [
[ 0, [ 20, 50, 100 ] ],
[ 3, [ 30, 50, 100 ] ],
Line 387 ⟶ 617:
appealAmountsData.NZD = appealAmountsData.USD;
appealAmountsData.EUR = appealAmountsData.USD;
 
var formats = {
"USD" : "$\t",
"EUR" : {
"en" : "€\t",
"cy" : "€\t",
"ga" : "€\t",
"mt" : "€\t",
"nl" : "€ \t",
"lv" : "€ \t",
"tr" : "€ \t",
"default" : "\t €"
},
"AUD" : "$\t",
"CAD" : {
"fr" : "\t $",
"default" : "$\t"
},
"GBP" : "£\t",
"NZD" : "$\t",
"JPY" : "¥\t",
"SEK" : "\t kr",
"BRL" : "R$\t"
};
 
var format = formats[currency][language] || formats[currency]["default"] || formats[currency] || '\t';
 
// Radio button amounts
Line 422 ⟶ 626:
var $label = $("label[for='input_amount_" + j + "']");
$radio.val( radioAmounts[j] );
$label.text( formatdonationForm.replaceformatCurrency('\t', radioAmounts[j] ) );
}
}
Line 429 ⟶ 633:
var appealAmounts = pickAmountArray( appealAmountsData, currency, hpc, hpcSet );
if ( appealAmounts.length ) {
var appealAmountString = appealAmounts.map( donationForm.formatCurrency ).join( ', ');
// Build string
var appealAmountString = '';
for( var k = 0; k < appealAmounts.length; k++ ) {
appealAmountString += format.replace('\t', appealAmounts[k]) + ', ';
}
appealAmountString = appealAmountString.trim();
 
$('.consider-amounts').html(appealAmountString);
}
Line 484 ⟶ 682:
/* Check for a 'preSelect' url parameter, and select that option.
If there isn't an option, add it to the "Other" box and select that */
var preSelectAmount = parseFloat( mw.util.getParamValue('preSelect') );
if ( preSelectAmount > 0 ) {
var $preSelectOption = $('input[name="amount"][value="' + preSelectAmount + '"]');
if ( $preSelectOption.length ) {
// Select existing input
Line 494 ⟶ 692:
$('#input_amount_other').prop('checked', true);
}
donationForm.updateFeeDisplay();
}
}
Line 515 ⟶ 714:
'BE' : 'vmaj',
'ES' : 'vmaj',
'FR' : 'CBvmavma', // Adyen - Carte Bancaire was removed
'IT' : 'vmaj',
'LU' : 'vmaj',
Line 522 ⟶ 721:
'PT' : 'vmaj',
'SK' : 'vmaj',
'GR' : 'vma',
// Others
'CZ' : 'vmad',
'DK' : 'vma',
'HU' : 'vma',
Line 533 ⟶ 734:
'SE' : 'vma',
'UA' : 'vma', // Adyen
'ZA' : 'vm',
'ZZ' : 'vmad' // For testing
};
if ( cardTypes[country] ) {
$('.paymentmethod-cc').addClass('cctypes-' + cardTypes[country] );
$('.cc-text-label').addClass('sr-only');
}
}
Line 542 ⟶ 745:
/* Form functions */
function clearOther(box) {
document.getElementById("'input_amount_other"').checked = true;
box.value = "";
}
 
function selectOther() {
document.getElementById("'input_amount_other"').checked = true;
}
 
function selectAmount() {
$('#input_amount_other_box').val('');
$('input[name="amountGiven"]').val('');
}
 
/* -- Moved from Template:2012FR/Form-section/Processing/Default -- */
/**
donationForm.redirectPayment = function(paymentMethod, paymentSubMethod, skipValidation) {
* Validate form, and prep most of the parameters
*
* @param {string} paymentMethod - method e.g. 'cc', 'paypal'
* @param {string} paymentSubMethod - submethod e.g. 'rtbt_ideal' (a submethod of 'rtbt')
* @param {string} skipAmountValidation - skip validating amount for PayPal forced to USD
*/
donationForm.redirectPayment = function( paymentMethod, paymentSubMethod, skipAmountValidation ) {
 
if ( donationForm.validate( skipAmountValidation ) ) {
var form = document.paypalcontribution; // we should really change this some day
 
var params = {};
if ( skipValidation || donationForm.validate() ) {
 
params.currency = donationForm.currency;
if (typeof paymentSubMethod == 'undefined') {
paymentSubMethodparams.country = ''donationForm.country;
 
// Overrides for specific cc gateways
if ( paymentMethod === 'cc-adyen' ) {
params.payment_method = 'cc';
params.gateway = 'adyen';
} else if ( paymentMethod === 'cc-dlocal' ) {
params.payment_method = 'cc';
params.gateway = 'astropay';
} else {
params.payment_method = paymentMethod;
}
var paymentsURL = 'https://payments.wikimedia.org/index.php/Special:GatewayFormChooser';
 
if ( params.payment_method === 'cc' && params.country === 'ZA' ) {
form.action = paymentsURL;
params.gateway = 'astropay';
 
if (typeof paymentSubMethod == 'undefined') {
paymentSubMethod = '';
}
 
//if WorldPay( overridepaymentSubMethod for) cc{
params.payment_submethod = paymentSubMethod;
if( paymentMethod === 'cc-wp' ) {
paymentMethod = 'cc';
form.payment_method.value = 'cc';
form.gateway.value = 'worldpay';
form.ffname.value = 'worldpay';
}
 
var frequency = $('input[name="frequency"]:checked').val();
// Adyen override for cc
if ( paymentMethodfrequency =!== 'cc-adyenmonthly' ) {
paymentMethodparams.recurring = 'cc'false;
} else {
form.payment_method.value = 'cc';
formparams.gateway.valuerecurring = 'adyen'true;
form.ffname.value = 'adyen';
}
 
params.uselang = mw.config.get('wgPageContentLanguage'); // see T281285 for why not wgUserLanguage
/* Temporary redirect variant for 3DS issues - https://phabricator.wikimedia.org/T219445 */
 
var country = form.country.value;
if ( paymentMethodparams.uselang === 'ccpt' && params.country === 'BR' ) {
if ( countryparams.uselang === 'NOpt-br' || country === 'SE' || country === 'PL' ) {;
}
form.variant.value = 'redirect';
if ( params.uselang === }'es' &&
( params.country === 'AR' || params.country === 'CL' ||
params.country === 'CO' || params.country === 'MX' ||
params.country === 'PE' || params.country === 'UY' ||
params.country === 'US' )
) {
params.uselang = 'es-419';
}
 
var frequencyamount = $("input[name='frequency']:checked")donationForm.valgetAmount();
if ( frequency !== $('monthly#ptf-checkbox').prop('checked') ) {
frequencyamount = 'onetime'amount + donationForm.calculateFee( amount );
formdonationForm.recurringextraData.valueptf = 'false'1;
} else {
form.recurring.value = 'true';
}
params.amount = amount;
 
// Email optin
form.payment_method.value = paymentMethod;
if ( $('input[name="opt_in"]').length > 0 ) {
form.payment_submethod.value = paymentSubMethod;
var opt_inValue = $('input[name="opt_in"]:checked').val();
params.opt_in = opt_inValue; // donationForm.validate() already checked it's 1 or 0
}
 
if ( mw.util.getParamValue( 'pym_variant' ) ) {
donationForm.addAnalytics();
params.variant = mw.util.getParamValue( 'pym_variant' );
 
var full_dotted_payment_method = paymentMethod;
if ( form.recurring.value == 'true' ) {
full_dotted_payment_method = 'r' + full_dotted_payment_method;
}
if ( params.recurring && params.variant && params.variant.match( /monthlyConvert/ ) ) {
if ( paymentSubMethod ) {
// Post-payments monthly convert makes no sense if it's already recurring
full_dotted_payment_method = form.payment_method.value + '.' + paymentSubMethod;
// Avoid things like T312905
delete params.variant;
}
 
if ( mw.util.getParamValue( 'pym_appeal' ) ) {
form.utm_source.value += '.' + full_dotted_payment_method;
params.appeal = mw.util.getParamValue( 'pym_appeal' );
}
 
form.method// =Monthly "GET";convert
if ( mc ) { // check just in-case this wasn't loaded for some reason
form.submit();
mc.main( params, donationForm.finalStep );
} else {
donationForm.finalStep( params );
}
 
} else {
donationForm.extraData.validateError = 1; // Flag they had an error, even if fixed later
}
 
Line 627 ⟶ 854:
};
 
/**
donationForm.addAnalytics = function() {
* Build final // stuffstracking parameters, intoand utm_sourcesubmit to make them available for analyticspayments
* @param {Object} params
// TODO: replace getQueryString with mw.util.getParamValue()
*/
donationForm.finalStep = function( params ) {
 
var uri = new mw.Uri('https://payments.wikimedia.org/index.php/Special:GatewayChooser');
var form = document.paypalcontribution;
 
// Skip form chooser for Apple Pay / Google Pay
form.utm_source.value = getQuerystring( 'utm_source' ) + '.';
if ( params.payment_method === 'apple' || params.payment_method === 'google' ) {
 
uri = new mw.Uri('https://payments.wikimedia.org/index.php/Special:AdyenCheckoutGateway');
if(getQuerystring( 'template' ) == '') {
form.utm_source.value += 'default' + '~';
} else {
form.utm_source.value += getQuerystring( 'template' ).replace("Lp-layout-","") + '~';
}
 
// Skip form chooser for Venmo
if(getQuerystring( 'appeal-template' ) == '') {
if ( form.utm_sourceparams.valuepayment_method +=== 'defaultvenmo' +) '~';{
uri = new mw.Uri('https://payments.wikimedia.org/index.php/Special:BraintreeGateway');
} else {
form.utm_source.value += getQuerystring( 'appeal-template' ).replace("Appeal-template-","") + '~';
}
 
donationForm.extraData.time = Math.round( (Date.now() - donationForm.loadedTime)/1000 );
if(getQuerystring( 'appeal' ) == '') {
 
form.utm_source.value += 'default' + '~';
}// elseTracking {data
params.wmf_medium = mw.util.getParamValue( 'wmf_medium' ) || mw.util.getParamValue( 'utm_medium' );
form.utm_source.value += getQuerystring( 'appeal' ).replace("Appeal-","") + '~';
params.wmf_campaign = mw.util.getParamValue( 'wmf_campaign' ) || mw.util.getParamValue( 'utm_campaign' );
params.wmf_source = donationForm.buildTrackingSource( params );
params.wmf_key = donationForm.buildTrackingKey( donationForm.extraData );
if ( document.referrer ) { // TODO: do we need this?
// Strip protocol to stop firewall complaining
params.referrer = document.referrer.replace(/https?:\/\//i, '');
}
 
uri.extend( params );
if(getQuerystring( 'form-template' ) == '') {
 
form.utm_source.value += 'default' + '~';
if ( window.top !== window.self ) {
// In a frame, open payments in a new tab
window.open( uri.toString() );
} else {
window.location.href = uri.toString();
form.utm_source.value += getQuerystring( 'form-template' ).replace("Form-template-","") + '~';
}
};
 
/**
if(getQuerystring( 'form-countryspecific' ) == '') {
* Build a wmf_source value, including the landing page info.
form.utm_source.value += 'control';
*
} else {
* Own function so it can be overriden for weird tests
form.utm_source.value += getQuerystring( 'form-countryspecific' ).replace("Form-countryspecific-","");
*
* @param {Object} params
* @return {string} wmf_source
*/
donationForm.buildTrackingSource = function( params ) {
 
var wmf_source = mw.util.getParamValue( 'wmf_source' ) || mw.util.getParamValue( 'utm_source' );
wmf_source += '.';
 
var fullDottedPaymentMethod = params.payment_method;
if ( params.recurring ) {
fullDottedPaymentMethod = 'r' + fullDottedPaymentMethod;
}
if ( params.payment_submethod ) {
fullDottedPaymentMethod = fullDottedPaymentMethod + '.' + params.payment_submethod;
}
 
/* Get URL parameter, but remove parts using old format. Allow fallback to a default value */
form.utm_campaign.value = getQuerystring( 'utm_campaign' );
var getParam = function( param, removeText, dflt ) {
if ( mw.util.getParamValue( param ) ) {
return mw.util.getParamValue( param ).replace( removeText, '' );
} else {
return dflt;
}
};
 
/* The landing page info, separated by ~. This mostly exists for legacy reasons */
wmf_source += getParam( 'template' , 'Lp-layout' , 'default' ) + '~';
wmf_source += getParam( 'appeal-template' , 'Appeal-template-' , 'default' ) + '~';
wmf_source += getParam( 'appeal' , 'Appeal-' , 'default' ) + '~';
wmf_source += getParam( 'form-template' , 'Form-template-' , 'default' ) + '~';
wmf_source += getParam( 'form-countryspecific', 'Form-countryspecific-', 'control' );
 
wmf_source += '.' + fullDottedPaymentMethod;
 
return wmf_source;
 
};
 
/**
* Build a string for wmf_key from extra tracking data
*
* @param {Object} data
* @return {string} wmf_key
*/
donationForm.buildTrackingKey = function(data) {
var existingKey = mw.util.getParamValue( 'wmf_key' ) || mw.util.getParamValue( 'utm_key' ),
dataArray = [];
 
if ( existingKey ) {
dataArray.push( existingKey );
}
for (var key in data) {
if (data.hasOwnProperty(key)) {
dataArray.push( key + '_' + data[key] );
}
}
return dataArray.join('~');
};
 
/* Return amount selected or input */
donationForm.getAmount = function() {
var form = document.paypalcontribution;forms.donateForm,
var amount = null;
donationForm.extraData.otherAmt = 0;
 
// If there are some amount radio buttons, then look for the checked one
Line 677 ⟶ 968:
for ( var i = 0; i < form.amount.length; i++ ) {
if ( form.amount[i].checked ) {
amount = parseFloat( form.amount[i].value );
}
}
}
 
// Check the "other" amount box
if ( document.getElementById('input_amount_other').checked ) {
if ( form.input_amount_other_box.value !== '' ) {
var otherAmountamount = donationForm.parseOtherAmount( form.input_amount_other_box.value );
donationForm.extraData.otherAmt = 1;
otherAmount = otherAmount.replace(/[,.](\d)$/, '\:$10');
otherAmount = otherAmount.replace(/[,.](\d)(\d)$/, '\:$1$2');
otherAmount = otherAmount.replace(/[\$£€¥,.]/g, '');
otherAmount = otherAmount.replace(/:/, '.');
form.amountGiven.value = otherAmount; // TODO: change this
amount = otherAmount;
}
 
amount =return parseFloat(amount);
 
};
if ( isNaN(amount) ) {
 
/**
* Parse Other field value into amount
*
* Does some awful regex stuff to rm symbols and turn the string into a number
* Remember some locales flip . & , for decimal point/thousands separator
*
* @param {string} value Value of "Other" field
* @return {float} Float with amount, or 0 if NaN
*/
donationForm.parseOtherAmount = function( value ) {
var amount;
 
value = value.replace(/[,.](\d)$/, '\:$10');
value = value.replace(/[,.](\d)(\d)$/, '\:$1$2');
value = value.replace(/[\$£€¥,.]/g, '');
value = value.replace(/:/, '.');
 
amount = parseFloat( value );
if ( isNaN( amount ) ) {
return 0;
} else {
return amount;
}
};
 
}
 
 
/**
* Validate the form.
*/
donationForm.validate = function( skipAmountValidation ) {
 
var error = false;
var form = document.paypalcontributionforms.donateForm;
 
// Reset all errors
Line 716 ⟶ 1,019:
$('.lp-error').hide();
 
if ( !skipAmountValidation && !donationForm.validateAmount() ) {
error = true;
}
 
if ( form.opt_in ) {
if ( $("'input[name='"opt_in'"]:checked"').val() === undefined ) {
$('#error-optin').show();
error = true;
} else {
$('#error-optin').hide();
form.variant.value = 'emailExplain';
}
}
 
return !error;
};
 
/**
Line 740 ⟶ 1,042:
 
var amount = donationForm.getAmount();
var currency = document.paypalcontribution.currency_code.value;
var minAmount = donationForm.minimums[ currency ] || 1;
 
if ( amount === null || isNaN(amount) || amount <= 0 || amount < minAmountdonationForm.minLocal ) {
$('.amount-options').addClass('lp-haserror');
$('.lp-error-bigamount').hide();
$('.lp-error-smallamount').show();
return false;
} else if ( amount > 10000 * minAmountdonationForm.maxLocal ) {
$('.amount-options').addClass('lp-haserror');
$('.lp-error-bigamount').show();
Line 757 ⟶ 1,058:
}
 
};
 
donationForm.toggleMonthly = function(monthly) {
Line 766 ⟶ 1,067:
}
};
/* End form functions */
 
donationForm.updateFeeDisplay = function() {
var selectedAmount = donationForm.getAmount(),
feeAmount = donationForm.calculateFee( selectedAmount ),
feeText;
 
feeText = donationForm.formatCurrency( feeAmount );
 
$('.ptf label span').text( feeText );
if ( selectedAmount + feeAmount <= donationForm.maxLocal ) {
$('.ptf').slideDown();
}
};
 
/**
* Calculate approximate transaction fee on given amount
* @param {number} amount
* @return {number} Rounded to 2 decimal places
*/
donationForm.calculateFee = function( amount ) {
 
// Minimum fee/PTF amounts. Default is 0.35.
// Updated 2019-05-21 to approx 0.35 USD equivalent
var feeMinimums = {
'DKK' : 2,
'HUF' : 100,
'ILS' : 1.2,
'INR' : 4,
'JPY' : 35,
'MYR' : 1,
'NOK' : 3,
'PLN' : 1.35,
'CZK' : 7.5,
'RON' : 1.5,
'SEK' : 3,
'UAH' : 10,
'ZAR' : 5,
// Latin America // Updated 2024-08-22 to approx 0.35 USD equivalent
'BRL' : 1.75,
'ARS' : 300,
'CLP' : 300,
'COP' : 1400,
'MXN' : 6,
'PEN' : 1.2,
'UYU' : 14
};
 
var feeMultiplier = 0.04,
feeMinimum = feeMinimums[ donationForm.currency ] || 0.35,
feeAmount = amount * feeMultiplier;
 
if ( feeAmount < feeMinimum ) {
feeAmount = feeMinimum;
}
return parseFloat( feeAmount.toFixed(2) );
};
 
 
donationForm.initOptin = function() {
$('.optin-options').on('change', function(e) {
 
$('#error-optin').hide();
 
// Only do all this if we have translated prompts
if ( $('.optin-no-prompt').data('is-translated') === 'yes' ) {
if ( e.target.id === 'optin-no' ) {
$('.optin-no-prompt').removeClass('is-positive');
if ( !$('.optin-no-prompt').is(':visible') ) {
$('.optin-no-prompt').slideDown();
}
} else {
$('.optin-no-prompt').addClass('is-positive');
}
}
});
};
 
/**
* Block typing letters and symbols in given input. Used for Other amount inputs
*
* If we don't do this, Safari allows typing them and then chokes on submit
* https://phabricator.wikimedia.org/T118741, https://phabricator.wikimedia.org/T173431
*
* @param {Element} inputElement The element to block typing on
*/
donationForm.otherInputControl = function( inputElement ) {
if ( inputElement ) {
inputElement.onkeypress = function(e) {
// Allow special keys in Firefox
if ((e.code == 'ArrowLeft') || (e.code == 'ArrowRight') ||
(e.code == 'ArrowUp') || (e.code == 'ArrowDown') ||
(e.code == 'Delete') || (e.code == 'Backspace')) {
return;
}
var chr = String.fromCharCode(e.which);
if ('0123456789., '.indexOf(chr) === -1) {
return false;
}
};
}
};
 
/**
* Should we show Apple Pay?
*
* Note there is a ~500ms delay in Safari when checking, so only call this if needed
*
* @param {string} country
* @return {boolean}
*/
donationForm.shouldShowApplePay = function ( country ) {
if ( location.search.match('forceApplePay') ) {
return true;
}
if ( window.ApplePaySession ) {
if ( ApplePaySession.canMakePayments() ) {
return true;
}
}
return false;
};
 
/*
Based on github:braintree/braintree-web/src/venmo/shared/supports-venmo.js
See also on meta: MediaWiki:FundraisingBanners/VenmoBrowserCheck.js
*/
donationForm.isVenmoSupported = function(options) {
var options = options || {
allowNewBrowserTab: false,
allowWebviews: true,
allowDesktop: true,
allowDesktopWebLogin: true
};
var ua = window.navigator.userAgent;
 
var merchantAllowsReturningToNewBrowserTab,
merchantAllowsWebviews,
merchantAllowsDesktopBrowsers;
var isMobileDevice = isAndroid() || isIos();
var isAndroidChrome = isAndroid() && isChrome();
var isMobileDeviceThatSupportsReturnToSameTab = isIosSafari() || isAndroidChrome;
var isKnownUnsupportedMobileBrowser = isIosChrome() || isFacebookOwnedBrowserOnAndroid() || isSamsung();
 
options = options || {};
// NEXT_MAJOR_VERSION allowDesktop will default to true, but can be opted out
merchantAllowsDesktopBrowsers =
(options.allowDesktopWebLogin || options.allowDesktop) === true;
merchantAllowsReturningToNewBrowserTab = options.hasOwnProperty(
"allowNewBrowserTab"
)
? options.allowNewBrowserTab
: true;
// NEXT_MAJOR_VERSION webviews are not supported, except for the case where
// the merchant themselves is presenting venmo in a webview using the deep
// link url to get back to their app. For the next major version, we should
// just not have this option and instead require the merchant to determine
// if the venmo button should be displayed when presenting it in the
// merchant's app via a webview.
merchantAllowsWebviews = options.hasOwnProperty("allowWebviews")
? options.allowWebviews
: true;
 
if (isKnownUnsupportedMobileBrowser) {
return false;
}
 
if (
!merchantAllowsWebviews &&
(isAndroidWebview() || isIosWebview())
) {
return false;
}
 
if (!isMobileDevice) {
return merchantAllowsDesktopBrowsers;
}
 
if (!merchantAllowsReturningToNewBrowserTab) {
return isMobileDeviceThatSupportsReturnToSameTab;
}
 
return isMobileDevice;
 
/* -- functions mostly from github:braintree/browser-detection library -- */
 
function isAndroid() {
return /Android/i.test(ua);
}
 
function isIos(checkIpadOS = true) {
const iOsTest = /iPhone|iPod|iPad/i.test(ua);
return checkIpadOS ? iOsTest || isIpadOS() : iOsTest;
}
 
function isIpadOS() {
// "ontouchend" is used to determine if a browser is on an iPad, otherwise
// user-agents for iPadOS behave/identify as a desktop browser
return /Mac|iPad/i.test(ua) && "ontouchend" in window.document;
}
 
function isEdge() {
return ua.indexOf("Edge/") !== -1 || ua.indexOf("Edg/") !== -1;
}
 
function isSamsung() {
return /SamsungBrowser/i.test(ua);
}
 
function isDuckDuckGo() {
return ua.indexOf("DuckDuckGo/") !== -1;
}
 
function isOpera() {
return (
ua.indexOf("OPR/") !== -1 ||
ua.indexOf("Opera/") !== -1 ||
ua.indexOf("OPT/") !== -1
);
}
 
function isSilk() {
return ua.indexOf("Silk/") !== -1;
}
 
function isChrome() {
return (
(ua.indexOf("Chrome") !== -1 || ua.indexOf("CriOS") !== -1) &&
!isEdge() &&
!isSamsung() &&
!isDuckDuckGo() &&
!isOpera() &&
!isSilk()
);
}
 
function isIosFirefox() {
return /FxiOS/i.test(ua);
}
 
function isWebkit() {
const webkitRegexp = /webkit/i;
return webkitRegexp.test(ua);
}
 
function isIosChrome() {
return ua.indexOf("CriOS") > -1;
}
 
function isFacebook() {
return ua.indexOf("FBAN") > -1;
}
 
function isIosSafari() {
return (
isIos() &&
isWebkit() &&
!isIosChrome() &&
!isIosFirefox() &&
!isFacebook()
);
}
 
function isFacebookOwnedBrowserOnAndroid() {
var e = ua.toLowerCase();
return -1 < e.indexOf("huawei") && -1 < e.indexOf("fban") || isAndroid() && (-1 < e.indexOf("fb_iab") || -1 < e.indexOf("instagram"));
}
 
function isSamsungBrowser() {
return /SamsungBrowser/i.test(ua);
}
 
function isAndroidWebview() {
return isAndroid() && -1 < ua.toLowerCase().indexOf("wv");
}
 
function isGoogleSearchApp() {
return /\bGSA\b/.test(ua);
}
 
function isIosGoogleSearchApp() {
return isIos() && isGoogleSearchApp();
}
 
function isIosWebview() {
if (isIos()) {
// The Google Search iOS app is technically a webview and doesn't support popups.
if (isIosGoogleSearchApp()) {
return true;
}
// Historically, a webview could be identified by the presence of AppleWebKit and _no_ presence of Safari after.
return /.+AppleWebKit(?!.*Safari)/i.test(ua);
}
return false;
}
};
 
/* End form functions */
 
$(document).ready(function() {
Line 773 ⟶ 1,369:
mw.loader.using( ['mediawiki.util'] ).done( function() {
 
var form = document.forms.donateForm;
// Block typing symbols in input field, otherwise Safari allows them and then chokes
// https://phabricator.wikimedia.org/T118741, https://phabricator.wikimedia.org/T173431
 
// Minimum amount is usually about 1 USD
var amountOtherInput = document.getElementById('input_amount_other_box');
donationForm.minLocal = donationForm.currencyRates[ donationForm.currency ];
if ( amountOtherInput ) {
donationForm.minLocal = Math.ceil( donationForm.minLocal * 100 ) / 100; // Round it up
amountOtherInput.onkeypress = function(e) {
donationForm.maxUSD = 25000;
// Allow special keys in Firefox
donationForm.maxLocal = Math.floor( donationForm.currencyRates[ donationForm.currency ] * donationForm.maxUSD );
if ((e.code == 'ArrowLeft') || (e.code == 'ArrowRight') ||
 
(e.code == 'ArrowUp') || (e.code == 'ArrowDown') ||
// Overrides for India
(e.code == 'Delete') || (e.code == 'Backspace')) {
if ( donationForm.currency === 'INR' ) return;{
donationForm.minLocal = }10;
// Until var chr = Stringhttps://phabricator.fromCharCode(ewikimedia.which);org/T370583 fixed?
donationForm.maxUSD if ("0123456789., ".indexOf(chr) === -1) {3000;
donationForm.maxLocal = return false250000;
}
};
}
 
// ValidateBlock amounttyping whensymbols selected/enteredin Other field
donationForm.otherInputControl( document.getElementById('input_amount_other_box') );
$('.amount-options').on( 'input change', donationForm.validateAmount );
 
// Validate amount and update fee when selected/entered
$('.amount-options').on( 'input change', function() {
donationForm.validateAmount();
donationForm.updateFeeDisplay();
});
 
// Disable submitting form with Enter key
$('form[name="paypalcontributiondonateForm"]').on('keypress', function(e) {
var code = ( e.keyCode ? e.keyCode : e.which );
if ( code == 13 ) {
Line 810 ⟶ 1,409:
});
 
if ( document.paypalcontributionform ) {
document.paypalcontribution.utm_medium.value = mw.util.getParamValue( 'utm_medium' );
document.paypalcontribution.utm_campaign.value = mw.util.getParamValue( 'utm_campaign' );
document.paypalcontribution.utm_key.value = mw.util.getParamValue( 'utm_key' );
 
// Striphide protocolfrequency tooptions stopfor firewallsome throwing fitscountries
if ( donationForm.noRecurringCountries.indexOf( donationForm.country ) !== -1 ) {
document.paypalcontribution.referrer.value = document.referrer.replace(/https?:\/\//i, "");
$('#frequency_onetime').prop('checked', true);
$('.frequency-options, #cancel-monthly, #donate-recurring-smallprint').hide();
}
 
if ( donationForm.noRecurringPaypalCountries.indexOf( donationForm.country ) !== -1 ) {
// hide frequency options in India, where we can only handle one-time donations
$( '.paymentmethod-pp, .paymentmethod-pp-usd' ).addClass( 'not-monthly-capable' );
if (document.paypalcontribution.country.value === 'IN') {
$("#frequency_onetime").prop('checked', true);
$(".frequency-options").hide();
$("#cancel-monthly").hide();
}
// Format amounts on buttons
$( '.amount-options li' ).each( function( index ) {
let amount = this.querySelector( 'input' ).value;
if ( amount !== 'Other' ) {
this.querySelector( 'label' ).innerText = donationForm.formatCurrency( amount );
}
});
 
addCardTypesClass(document.paypalcontribution donationForm.country.value );
 
// Only show Amazon for links from Ways to give
if (
mw.util.getParamValue( 'wmf_source' ) === 'Waystogive' ||
mw.util.getParamValue( 'wmf_source' ) === 'Ways_to_Give'
) {
$('.paymentmethod-amazon').show();
}
 
// Apple Pay
if ( $('.paymentmethod-applepay').length > 0 ) {
if ( !donationForm.shouldShowApplePay( donationForm.country ) ) {
$('.paymentmethod-applepay').remove();
}
}
 
// Venmo browser check
if ( $('.paymentmethod-venmo').length > 0 ) {
if ( !donationForm.isVenmoSupported() || donationForm.country !== 'US' ) {
$('.paymentmethod-venmo').remove();
}
}
}
 
Line 832 ⟶ 1,458:
 
// Disable logo link
$("'#p-logo a"').attr(" { href",: "'#"', title: '' } );
$("#p-logo a").attr("title", "");
 
// These don't need to be tabbable on the landing page
$('#searchInput, .mw-jump-link').attr('tabindex', '-1');
 
$("'.input_amount_other"').click(function() {
$("'#input_amount_other_box"').focus();
});
 
// Allow preselecting monthly
if (
mw.util.getParamValue('monthly') ) {
&& mw.util.getParamValue('monthly') !== '0'
&& donationForm.noRecurringCountries.indexOf( donationForm.country ) === -1
&& mw.util.getParamValue('utm_medium') !== 'endowment'
&& mw.util.getParamValue('wmf_medium') !== 'endowment'
) {
$('#frequency_monthly').click();
}
 
donationForm.initOptin();
// If the optin section has some javascript to run, do that
if ( typeof initOptin === 'function' ) {
initOptin();
}
 
try {
adjustHPC();
preSelect(); // Make sure to do this *after* other fiddling with values
donationForm.localizeErrors();
}
finally {
$('.frb-monthly-pitch, .frb-monthly-pitch-thanks').appendTo('.frequency-options');
$('.ptf').appendTo('.amount-options');
$('.optin-options').insertAfter('.amount-options');
$('.consider-amounts').show();