MediaWiki:DonationForm.js: Difference between revisions

Content deleted Content added
enable paypal recurring for Mexico: phab:T360214
hacky use of hpcSet for Major Gifts amount changes
 
(27 intermediate revisions by 2 users not shown)
Line 8:
donationForm.loadedTime = Date.now();
donationForm.extraData = {};
 
donationForm.country = mw.util.getParamValue('country').toUpperCase();
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' ]; // is this still needed?
 
donationForm.noRecurringPaypalCountries = [ 'CL', 'CO', 'PE', 'UY', 'BR' ];
 
donationForm.maxUSDcurrencyRates = 25000;{
 
donationForm.minimums = {
// From https://github.com/wikimedia/wikimedia-fundraising-SmashPig/blob/master/PaymentData/ReferenceData/CurrencyRates.php
// Updated 2024-0107-1931
'ADF' : 6.0804,
'ADP' : 154153,
'AED' : 3.67,
'AFA' : 6870,
'AFN' : 6870,
'ALL' : 9490,
'AMD' : 388368,
'ANG' : 1.79,
'AOA' : 828844,
'AON' : 828844,
'ARS' : 366887,
'ATS' : 13,
'AUD' : 1.525,
'AWG' : 1.79,
'AZM' : 8500,
'AZN' : 1.7,
'BAM' : 1.818,
'BBD' : 2,
'BDT' : 109116,
'BEF' : 37,
'BGL' : 1.818,
'BGN' : 1.818,
'BHD' : 0.3745280208054737355757356689,
'BIF' : 28262842,
'BMD' : 1,
'BND' : 1.3435,
'BOB' : 6.7371,
'BRL' : 45.951,
'BSD' : 1,
'BTN' : 83,
'BWP' : 1413,
'BYR' : 3290032642,
'BZD' : 1.9798,
'CAD' : 1.36,
'CDF' : 26112786,
'CHF' : 0.876203623890759094629289448,
'CLP' : 880890,
'CNY' : 7.1723,
'COP' : 39703803,
'CRC' : 520498,
'CUC' : 1,
'CUP' : 25,
'CVE' : 102101,
'CYP' : 0.5426483597987453848627984321,
'CZK' : 23,
'DEM' : 1.818,
'DJF' : 178,
'DKK' : 6.9186,
'DOP' : 5658,
'DZD' : 134133,
'ECS' : 24094,
'EEK' : 1514,
'EGP' : 3147,
'ESP' : 154153,
'ETB' : 5657,
'EUR' : 0.9271697697125192005843390143,
'FIM' : 5.5147,
'FJD' : 2.2223,
'FKP' : 0.7958197171863878703952551207,
'FRF' : 6.0804,
'GBP' : 0.7958197171863878703952551207,
'GEL' : 2.6471,
'GHC' : 120114143125,
'GHS' : 1214,
'GIP' : 0.7958197171863878703952551207,
'GMD' : 6768,
'GNF' : 85228493,
'GRD' : 316314,
'GTQ' : 7.6457,
'GYD' : 200,
'HKD' : 7.818,
'HNL' : 24,
'HRK' : 6.9993,
'HTG' : 131132,
'HUF' : 355,
'IDR' : 1559315986,
'IEP' : 0.7302055325139172460490043714,
'ILS' : 3.7169,
'INR' : 1083,
'IQD' : 12921290,
'IRR' : 4200042009,
'ISK' : 140138,
'ITL' : 17951781,
'JMD' : 154,
'JOD' : 0.70900000000001,
'JPY' : 146156,
'KES' : 153130,
'KGS' : 8988,
'KHR' : 40513993,
'KMF' : 456453,
'KPW' : 135,
'KRW' : 13131358,
'KWD' : 0.3076216472886530629670764681,
'KYD' : 0.83333299999999,
'KZT' : 456442,
'LAK' : 2057721103,
'LBP' : 1500089393,
'LKR' : 325298,
'LRD' : 187193,
'LSL' : 1918,
'LTL' : 3.218,
'LUF' : 37,
'LVL' : 0.6516186228330464662074757963,
'LYD' : 4.8,
'MAD' : 109.79,
'MDL' : 1817,
'MGA' : 45494379,
'MGF' : 9150,
'MKD' : 5756,
'MMK' : 20802075,
'MNT' : 2620,
'MOP' : 8.0403,
'MRO' : 392391,
'MTL' : 0.3980339821375939498108567387,
'MUR' : 4345,
'MVR' : 15,
'MWK' : 16741720,
'MXN' : 17,
'MYR' : 4.68,
'MZM' : 63200,
'MZN' : 63,
'NAD' : 1918,
'NGN' : 7911505,
'NIO' : 36,
'NLG' : 2.0403,
'NOK' : 11,
'NPR' : 132131,
'NZD' : 1.63,
'OMR' : 0.3838121251183638377594841305,
'PAB' : 1,
'PEN' : 3.7467,
'PGK' : 3.6476,
'PHP' : 5658,
'PKR' : 283277,
'PLN' : 43.0291,
'PTE' : 186184,
'PYG' : 72447355,
'QAR' : 3.6456,
'ROL' : 4606345713,
'RON' : 4.6157,
'RSD' : 108,
'RUB' : 9091,
'RWF' : 12371277,
'SAR' : 3.75,
'SBD' : 8.3537,
'SCR' : 13,
'SDD' : 59800,
'SDG' : 598,
'SDP' : 2261,
'SEK' : 1011,
'SGD' : 1.3435,
'SHP' : 0.7958197171863878703952551207,
'SIT' : 222220,
'SKK' : 28,
'SLL' : 19750,
'SOS' : 562549,
'SRD' : 3733,
'SRG' : 3735633320,
'STD' : 2255222477,
'SVC' : 8.75,
'SYP' : 513,
'SZL' : 1918,
'THB' : 36,
'TJS' : 11,
Line 187 ⟶ 220:
'TND' : 3.11,
'TOP' : 2.32,
'TRL' : 2900900732168418,
'TRY' : 2932,
'TTD' : 6.6564,
'TWD' : 3132,
'TZS' : 24982587,
'UAH' : 3739,
'UGX' : 37843760,
'USD' : 1,
'UYU' : 3938,
'UZS' : 1230212662,
'VEB' : 35538253263651907631,
'VEF' : 35538253651908,
'VND' : 2425925451,
'VUV' : 112,
'WST' : 2.6867,
'XAF' : 608604,
'XAG' : 0.043725386677957031347411860134,
'XAU' : 0.00050403891928600041128929241299,
'XCD' : 2.7,
'XEU' : 0.9271697697125192005843390143,
'XOF' : 608604,
'XPD' : 0.00102593750718600098009826645798,
'XPF' : 111110,
'XPT' : 0.00108407857295400093444018680404,
'YER' : 250249,
'YUN' : 108,
'ZAR' : 1918,
'ZMK' : 5176,
'ZWD' : 373
};
 
/* Amount and currency formatting */
let formatters = {
// Amounts without currency symbol
amountFraction: new Intl.NumberFormat( donationForm.locale,
{ 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 = donationForm.currency,;
minAmount = donationForm.minimums[ currency ],
locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country );
 
// Round up
minAmount = Math.ceil( minAmount * 100 ) / 100;
 
$('.lp-error-smallamount').text( function( index, oldText ) {
return oldText.replace( '$1', donationForm.formatAmount( minAmount, localedonationForm.minLocal ) + '\xa0' + currency );
});
 
Line 240 ⟶ 314:
 
$('.lp-error-bigamount').text( function( index, oldText ) {
return oldText.replace( '$1', donationForm.formatAmount( donationForm.maxUSD * minAmount, localemaxLocal ) )
.replace( '$2', currency )
.replace( '$3', 'benefactors@wikimedia.org' )
.replace( '$4', donationForm.formatAmount( donationForm.maxUSD, locale ) );
});
};
Line 253 ⟶ 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 hpcSet = mw.util.getParamValue('hpcSet');
 
var currency = donationForm.currency;
var language = mw.config.get('wgPageContentLanguage');
 
// If changing, please update https://docs.google.com/spreadsheets/d/1e02TsZ_bKDAS1BMVBCdyo9D7RGln_wCGnkg7IF5kU5s/edit
Line 287 ⟶ 365:
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
"midtier2018FY2425_E1_T11_USD" : [ // Upgrade recurring +1 for lowest ask
[ 0, [ 3.75, 5, 10, 20, 3025, 5035, 100 50 ] ],
[ 5, [ 5, 10, 2015, 3520, 5035, 100 50, 150100 ] ],
[ 10, [ 10, 15, 20, 3525, 5035, 100 50, 150100 ] ],
[ 15, [ 15, 20, 25, 35, 50, 100 75, 150100 ] ],
[ 20, [ 20, 25, 35, 50, 75, 100, 150 ] ],
[ 25, [ 3525, 5030, 7540, 100 50, 150 75, 250100, 500150 ] ],
[ 35, [ 5035, 7550, 100 75, 150100, 250200, 350300, 500 ] ],
[ 50, [ 7550, 100 75, 150100, 200, 250300, 350500, 500750 ] ],
[ 75, [ 100 75, 150100, 200150, 300250, 400500, 500750, 1000 ] ],
[ 100, [ 150100, 200150, 250, 300500, 400750, 5001000, 10002500 ] ],
[ 150, [ 200150, 250200, 300, 400500, 500750, 1000, 25002000 ] ],
[ 200, [ 500200, 750300, 1000 500, 2000 750, 35001000, 50002500, 75005000 ] ],
[ 500, [ 750500, 1000 750, 15001000, 2500, 5000, 7500, 10000 ] ],
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ],
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
"FY2425_E1_T14_USD" : [ // Upgrade recurring amount dynamically
[ 0, [ 2.75, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 2.75, 5, 10, 20, 25, 35, 50 ] ],
[ 10, [ 2.75, 10, 15, 20, 25, 35, 50 ] ],
[ 15, [ 3.50, 10, 20, 30, 50, 75, 100 ] ],
[ 20, [ 3.75, 10, 25, 35, 50, 75, 100 ] ],
[ 25, [ 4.50, 10, 25, 35, 50, 75, 100 ] ],
[ 35, [ 6.75, 15, 30, 50, 75, 100, 150 ] ],
[ 75, [ 15.75, 50, 75, 100, 200, 300, 500 ] ],
[ 100, [ 24.75, 50, 75, 100, 200, 300, 500 ] ],
[ 150, [ 44.75, 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_USD" : [ // Give less reactivation amount
[ 0, [ 2.75, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 2.75, 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 ] ]
]
},
"EUR" : [ // also used for GBP{
"default" : [
0, [ 0, [ 2.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_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 ] ],
Line 343 ⟶ 573:
radioAmountsData.NZD = radioAmountsData.USD;
 
// Major gifts appeals, hacky but this is easier than adding a load of new forms to maintain
radioAmountsData.GBP = radioAmountsData.EUR;
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 = {
Line 382 ⟶ 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;
if ( formats[currency] ) {
format = formats[currency][language] || formats[currency]['default'] || formats[currency];
} else {
format = '\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 677 ⟶ 875:
 
// Tracking data
params.utm_mediumwmf_medium = mw.util.getParamValue( 'wmf_medium' ) || mw.util.getParamValue( 'utm_medium' );
params.utm_campaignwmf_campaign = mw.util.getParamValue( 'wmf_campaign' ) || mw.util.getParamValue( 'utm_campaign' );
params.utm_sourcewmf_source = donationForm.buildUtmSourcebuildTrackingSource( params );
params.utm_keywmf_key = donationForm.buildUtmKeybuildTrackingKey( donationForm.extraData );
if ( document.referrer ) { // TODO: do we need this?
// Strip protocol to stop firewall complaining
Line 697 ⟶ 895:
 
/**
* Build a utm_sourcewmf_source value, including the landing page info.
*
* Own function so it can be overriden for weird tests
*
* @param {Object} params
* @return {string} utm_sourcewmf_source
*/
donationForm.buildUtmSourcebuildTrackingSource = function( params ) {
 
var utm_sourcewmf_source = mw.util.getParamValue( 'utm_sourcewmf_source' ) +|| 'mw.util.getParamValue( 'utm_source' );
wmf_source += '.';
 
var fullDottedPaymentMethod = params.payment_method;
Line 726 ⟶ 925:
 
/* The landing page info, separated by ~. This mostly exists for legacy reasons */
utm_sourcewmf_source += getParam( 'template' , 'Lp-layout' , 'default' ) + '~';
utm_sourcewmf_source += getParam( 'appeal-template' , 'Appeal-template-' , 'default' ) + '~';
utm_sourcewmf_source += getParam( 'appeal' , 'Appeal-' , 'default' ) + '~';
utm_sourcewmf_source += getParam( 'form-template' , 'Form-template-' , 'default' ) + '~';
utm_sourcewmf_source += getParam( 'form-countryspecific', 'Form-countryspecific-', 'control' );
 
utm_sourcewmf_source += '.' + fullDottedPaymentMethod;
 
return utm_sourcewmf_source;
 
};
 
/**
* Build a string for utm_keywmf_key from extra tracking data
*
* @param {Object} data
* @return {string} utm_keywmf_key
*/
donationForm.buildUtmKeybuildTrackingKey = function(data) {
var existingUtmKeyexistingKey = mw.util.getParamValue( 'wmf_key' ) || mw.util.getParamValue( 'utm_key' ),
dataArray = [];
 
if ( existingUtmKeyexistingKey ) {
dataArray.push( existingUtmKeyexistingKey );
}
for (var key in data) {
Line 843 ⟶ 1,042:
 
var amount = donationForm.getAmount();
var minAmount = donationForm.minimums[ donationForm.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 > donationForm.maxUSD * minAmountmaxLocal ) {
$('.amount-options').addClass('lp-haserror');
$('.lp-error-bigamount').show();
Line 873 ⟶ 1,071:
var selectedAmount = donationForm.getAmount(),
feeAmount = donationForm.calculateFee( selectedAmount ),
feeText;
minAmount = donationForm.minimums[ donationForm.currency ] || 1,
maxAmount = donationForm.maxUSD * minAmount,
feeText, locale;
 
localefeeText = donationForm.getLocaleformatCurrency( mw.config.get('wgPageContentLanguage'), donationForm.countryfeeAmount );
feeText = donationForm.formatAmount( feeAmount, locale );
 
$('.ptf label span').text( feeText );
if ( selectedAmount + feeAmount <= maxAmountdonationForm.maxLocal ) {
$('.ptf').slideDown();
}
Line 909 ⟶ 1,104:
'UAH' : 10,
'ZAR' : 5,
// Latin America // Updated 20232024-0108-1722 to approx 0.35 USD equivalent
'BRL' : 1.75,
'ARS' : 32300,
'CLP' : 322300,
'COP' : 13851400,
'MXN' : 6,
'PEN' : 1.32,
'UYU' : 13.714
};
 
Line 972 ⟶ 1,167:
};
}
};
 
/**
* 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 ) {
if ( language === 'en-gb' ) {
language = 'en';
}
if ( language === 'es-419' ) {
language = 'es';
}
if ( language === 'pt-br' ) {
language = 'pt';
}
return language + '-' + country;
};
 
Line 1,012 ⟶ 1,187:
}
return false;
};
 
/**
* Format an amount for a given locale
*
* 2 decimal places if it has a fractional part, 0 if not
* Note this doesn't include any currency symbol
*
* @param {number} amount
* @param {string} locale To determine correct separators
* @return {string}
*/
donationForm.formatAmount = function( amount, locale ) {
var formatterOptions, output;
if ( amount % 1 !== 0 ) { // Not a whole number
formatterOptions = { minimumFractionDigits: 2, maximumFractionDigits: 2 };
} else {
formatterOptions = {};
}
try {
output = amount.toLocaleString( locale, formatterOptions );
} catch(e) {
output = amount.toFixed(2);
}
return output;
};
 
Line 1,221 ⟶ 1,371:
var form = document.forms.donateForm;
 
// TheseMinimum getamount usedis inusually quiteabout a1 few placesUSD
donationForm.minLocal = donationForm.currencyRates[ donationForm.currency ];
try {
donationForm.currencyminLocal = formMath.currency_codeceil( donationForm.valueminLocal * 100 ) / 100; // Round it up
}donationForm.maxUSD catch (error) {= 25000;
donationForm.maxLocal = Math.floor( donationForm.currencyRates[ donationForm.currency =] * donationForm.maxUSD 'USD');
 
// Overrides for India
if ( donationForm.currency === 'INR' ) {
donationForm.minLocal = 10;
// Until https://phabricator.wikimedia.org/T370583 fixed?
donationForm.maxUSD = 3000;
donationForm.maxLocal = 250000;
}
donationForm.country = mw.util.getParamValue('country').toUpperCase();
 
// Block typing symbols in Other field
Line 1,264 ⟶ 1,420:
$( '.paymentmethod-pp, .paymentmethod-pp-usd' ).addClass( 'not-monthly-capable' );
}
// 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( donationForm.country );
Line 1,269 ⟶ 1,433:
// Only show Amazon for links from Ways to give
if (
mw.util.getParamValue( 'utm_sourcewmf_source' ) === 'Waystogive' ||
mw.util.getParamValue( 'utm_sourcewmf_source' ) === 'Ways_to_Give'
) {
$('.paymentmethod-amazon').show();
}
 
Line 1,304 ⟶ 1,468:
 
// Allow preselecting monthly
if (
mw.util.getParamValue('monthly')
&& mw.util.getParamValue('monthly') !== '0'
&& donationForm.noRecurringCountries.indexOf( donationForm.country ) === -1 ) {
&& donationForm.noRecurringCountries.indexOf( donationForm.country ) === -1
&& mw.util.getParamValue('utm_medium') !== 'endowment'
&& mw.util.getParamValue('wmf_medium') !== 'endowment'
) {
$('#frequency_monthly').click();
}