MediaWiki:DonationForm.js: Difference between revisions

Content deleted Content added
improved rounding for error amounts
No edit summary
 
(70 intermediate revisions by the same user not shown)
Line 7:
 
donationForm.loadedTime = Date.now();
donationForm.extraData = {};
'vw' : window.innerWidth,
'vh' : window.innerHeight
};
 
// Don't offer recurring at all in these countries
if ( navigator.brave !== undefined ) { // T283367
donationForm.extraData.bravenoRecurringCountries = [ '1AR' ]; // is this still needed?
}
 
donationForm.noRecurringPaypalCountries = [ 'CL', 'CO', 'PE', 'UY', 'BR' ];
// Don't offer recurring at all in these countries
 
donationForm.noRecurringCountries = [ 'AR', 'CL', 'CO', 'MX', 'PE', 'UY', 'BR', 'IN' ];
donationForm.maxUSD = 25000;
 
donationForm.maxUSD = 12000;
donationForm.minimums = {
/*/ From https://github.com/wikimedia/wikimedia-fundraising-SmashPig/blob/master/PaymentData/ReferenceData/CurrencyRates.php */
'ADF'// :Updated 5.45,2024-01-19
'ADPADF' : 1386.08,
'ADP' : 154,
'AED' : 3.67,
'AFA' : 7768,
'AFN' : 7768,
'ALL' : 10294,
'AMD' : 522388,
'ANG' : 1.79,
'AOA' : 622828,
'AON' : 622828,
'ARS' : 90366,
'ATS' : 1113,
'AUD' : 1.2952,
'AWG' : 1.79,
'AZM' : 8500,
'AZN' : 1.7,
'BAM' : 1.6381,
'BBD' : 2,
'BDT' : 83109,
'BEF' : 3437,
'BGL' : 1.6381,
'BGN' : 1.6381,
'BHD' : 0.3750371223512937452802080547,
'BIF' : 19272826,
'BMD' : 1,
'BND' : 1.3334,
'BOB' : 6.7473,
'BRL' : 54.6295,
'BSD' : 1,
'BTN' : 7383,
'BWP' : 1114,
'BYR' : 2606532900,
'BZD' : 1.97,
'CAD' : 1.2636,
'CDF' : 19752611,
'CHF' : 0.9237362764319187620362389075,
'CLP' : 729880,
'CNY' : 67.4717,
'COP' : 36603970,
'CRC' : 601520,
'CUC' : 1,
'CUP' : 25,
'CVE' : 92102,
'CYP' : 0.486622099303154264835979874,
'CZK' : 2223,
'DEM' : 1.6381,
'DJF' : 178,
'DKK' : 6.1891,
'DOP' : 5756,
'DZD' : 133134,
'ECS' : 24094,
'EEK' : 1315,
'EGP' : 1631,
'ESP' : 138154,
'ETB' : 4056,
'EUR' : 0.8314432202747892716976971251,
'FIM' : 45.9451,
'FJD' : 2.0222,
'FKP' : 0.7174344223174579581971718638,
'FRF' : 56.4508,
'GBP' : 0.7174344223174579581971718638,
'GEL' : 32.364,
'GHC' : 57159120114,
'GHS' : 5.7212,
'GIP' : 0.7174344223174579581971718638,
'GMD' : 5167,
'GNF' : 100418522,
'GRD' : 283316,
'GTQ' : 7.5364,
'GYD' : 201200,
'HKD' : 7.7681,
'HNL' : 24,
'HRK' : 6.399,
'HTG' : 76131,
'HUF' : 303355,
'IDR' : 1427915593,
'IEP' : 0.6548147483324873020553251391,
'ILS' : 3.371,
'INR' : 7310,
'IQD' : 14421292,
'IRR' : 4201042000,
'ISK' : 127140,
'ITL' : 16101795,
'JMD' : 149154,
'JOD' : 0.70900000000001,
'JPY' : 107146,
'KES' : 109153,
'KGS' : 8589,
'KHR' : 40194051,
'KMF' : 409456,
'KPW' : 135,
'KRW' : 11261313,
'KWD' : 0.3019115390725730762164728865,
'KYD' : 0.83333299999999,
'KZT' : 418456,
'LAK' : 917020577,
'LBP' : 150815000,
'LKR' : 194325,
'LRD' : 173187,
'LSL' : 1519,
'LTL' : 23.872,
'LUF' : 3437,
'LVL' : 0.5843416209819865161862283304,
'LYD' : 4.428,
'MAD' : 8.8210,
'MDL' : 1718,
'MGA' : 37164549,
'MGF' : 9150,
'MKD' : 5157,
'MMK' : 13922080,
'MNT' : 2620,
'MOP' : 78.9904,
'MRO' : 357392,
'MTL' : 0.3569385744639639803398213759,
'MUR' : 3943,
'MVR' : 15,
'MWK' : 7701674,
'MXN' : 2117,
'MYR' : 4.0568,
'MZM' : 7388063200,
'MZN' : 7463,
'NAD' : 1519,
'NGN' : 380791,
'NIO' : 3536,
'NLG' : 12.8304,
'NOK' : 8.5211,
'NPR' : 115132,
'NZD' : 1.3863,
'OMR' : 0.3838395736509838381212511836,
'PAB' : 1,
'PEN' : 3.6374,
'PGK' : 3.4364,
'PHP' : 4956,
'PKR' : 157283,
'PLN' : 34.7802,
'PTE' : 167186,
'PYG' : 65417244,
'QAR' : 3.6164,
'ROL' : 4051746063,
'RON' : 4.0561,
'RSD' : 97108,
'RUB' : 7490,
'RWF' : 9731237,
'SAR' : 3.75,
'SBD' : 78.8935,
'SCR' : 2013,
'SDD' : 3446759800,
'SDG' : 345598,
'SDP' : 2261,
'SEK' : 8.4510,
'SGD' : 1.3334,
'SHP' : 0.7174344223174579581971718638,
'SIT' : 199222,
'SKK' : 2528,
'SLL' : 1010519750,
'SOS' : 558562,
'SRD' : 1437,
'SRG' : 1401837356,
'STD' : 2030422552,
'SVC' : 8.75,
'SYP' : 513,
'SZL' : 1519,
'THB' : 3036,
'TJS' : 11,
'TMM' : 1677016750,
'TMT' : 3.35,
'TND' : 23.6911,
'TOP' : 2.2232,
'TRL' : 745695129009007,
'TRY' : 7.4629,
'TTD' : 6.6665,
'TWD' : 2831,
'TZS' : 23092498,
'UAH' : 2837,
'UGX' : 36413784,
'USD' : 1,
'UYU' : 4339,
'UZS' : 1042712302,
'VEB' : 1.86275657102E+143553825326,
'VEF' : 1862756571023553825,
'VND' : 2294024259,
'VUV' : 112,
'WST' : 2.4368,
'XAF' : 545608,
'XAG' : 0.038609238198237043725386677957,
'XAU' : 0.000584537038152000504038919286,
'XCD' : 2.7,
'XEU' : 0.8314432202747892716976971251,
'XOF' : 545608,
'XPD' : 0.000423507866364001025937507186,
'XPF' : 99111,
'XPT' : 0.00085367167460603001084078572954,
'YER' : 250,
'YUN' : 97108,
'ZAR' : 1519,
'ZMK' : 5176,
'ZWD' : 373
Line 223 ⟶ 220:
/* Localize the amount errors. Call when initialising form. */
donationForm.localizeErrors = function() {
var currency = donationForm.currency;,
var minAmount = donationForm.minimums[ currency ];,
locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country );
/* T287706 - round to 2 decimal places (rounding up) */
 
var numFormat = function( amount ) {
// Round up
return Math.ceil( amount * 100 ) / 100;
minAmount = Math.ceil( minAmount * 100 ) / 100;
};
 
$('.lp-error-smallamount').text( function( index, oldText ) {
return oldText.replace( '$1', numFormatdonationForm.formatAmount( minAmount, locale ) + ' \xa0' + currency );
});
 
Line 243 ⟶ 240:
 
$('.lp-error-bigamount').text( function( index, oldText ) {
return oldText.replace( '$1', numFormatdonationForm.formatAmount( donationForm.maxUSD * minAmount, locale ) )
.replace( '$2', currency )
.replace( '$3', 'benefactors@wikimedia.org' )
.replace( '$4', donationForm.formatAmount( donationForm.maxUSD, locale ) );
});
};
Line 270 ⟶ 267:
var language = mw.config.get('wgPageContentLanguage');
 
// 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 ] ],
[ 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 ] ],
[ 7550, [ 50, 75, 100, 150200, 250 300, 500, 750, 1000750 ] ],
[ 100 75, [ 75, 100, 150, 250, 500, 750, 1000, 2500 ] ],
[ 150100, [ 150100, 200 150, 300 250, 500, 750, 1000, 2000 2500 ] ],
[ 200150, [ 150, 200, 300, 500, 750, 1000, 2500, 50002000 ] ],
[ 500200, [ 200, 300, 500, 750, 1000, 2500, 5000, 7500, 100005000 ] ],
[ 1000 500, [ 1000 500, 2000 750, 3000 1000, 4000 2500, 5000, 7500, 10000 ] ],
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ],
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
'2incvar'"midtier2018" : [
[ 0, [ 13, 5, 10, 15, 20, 30, 50, 100 ] ],
[ 35, [ 3, 5, 10, 20, 35, 50, 75100, 150 ] ],
[ 610, [ 610, 10 15, 20, 35, 50, 75100, 100 150 ] ],
[ 1015, [ 1015, 15 20, 25, 50 35, 75 50, 100, 125 150 ] ],
[ 1320, [ 1320, 20 25, 35, 50, 75, 100, 125 150 ] ],
[ 1625, [ 1635, 25, 50, 75, 100, 150, 200 250, 500 ] ],
[ 2035, [ 2050, 35 75, 50100, 75150, 125 250, 150 350, 200 500 ] ],
[ 2350, [ 2375, 35100, 50150, 75200, 125 250, 175 350, 250 500 ] ],
[ 2675, [ 26100, 35150, 50200, 75300, 125 400, 175 500, 2501000 ] ],
[ 30100, [ 30150, 40200, 50250, 75300, 125 400, 175 500, 2501000 ] ],
[ 35150, [ 35200, 45250, 50300, 100 400, 125 500, 1751000, 2502500 ] ],
[ 40200, [ 40500, 50750, 751000, 1002000, 1503500, 2505000, 3007500 ] ],
[ 45500, [ 45750, 501000, 751500, 1002500, 1505000, 2507500, 50010000 ] ],
[ 501000, [ 501000, 602000, 1003000, 1254000, 1755000, 2507500, 50010000 ] ],
[ 60, [ 60, 75, 100, 125, 175, 250, 500 ] ],
[ 70, [ 70, 85, 100, 125, 175, 250, 500 ] ],
[ 80, [ 80, 100, 125, 150, 200, 300, 500 ] ],
[ 90, [ 90, 100, 125, 150, 200, 300, 500 ] ],
[ 100, [ 100, 125, 175, 250, 350, 500, 750 ] ],
[ 125, [ 125, 150, 200, 300, 500, 750, 1000 ] ],
[ 150, [ 150, 175, 250, 400, 500, 750, 1000 ] ],
[ 175, [ 175, 200, 300, 400, 500, 750, 1000 ] ],
[ 200, [ 200, 250, 300, 400, 500, 750, 1000 ] ],
],
'3incvarsv' : [
[ 0, [ 1, 5, 7.50, 10, 15, 20, 30 ] ],
[ 3, [ 3, 5, 10, 15, 20, 25, 40 ] ],
[ 6, [ 6, 10, 15, 20, 30, 40, 50 ] ],
[ 10, [ 10, 15, 20, 25, 30, 40, 50 ] ],
[ 13, [ 13, 20, 25, 35, 45, 55, 75 ] ],
[ 16, [ 16, 20, 25, 35, 45, 55, 75 ] ],
[ 20, [ 20, 25, 35, 45, 55, 75, 100 ] ],
[ 23, [ 23, 30, 37, 45, 55, 75, 100 ] ],
[ 26, [ 26, 30, 37, 45, 55, 75, 100 ] ],
[ 30, [ 30, 35, 40, 45, 55, 75, 100 ] ],
[ 35, [ 35, 40, 45, 50, 65, 75, 100 ] ],
[ 40, [ 40, 45, 50, 65, 75, 100, 125 ] ],
[ 45, [ 45, 50, 55, 65, 75, 100, 125 ] ],
[ 50, [ 50, 60, 75, 100, 125, 150, 200 ] ],
[ 60, [ 60, 70, 80, 100, 125, 150, 200 ] ],
[ 70, [ 70, 80, 100, 125, 150, 200, 250 ] ],
[ 80, [ 80, 90, 100, 125, 150, 200, 250 ] ],
[ 90, [ 90, 100, 125, 150, 200, 250, 300 ] ],
[ 100, [ 100, 110, 150, 200, 250, 300, 350 ] ],
[ 125, [ 125, 150, 200, 250, 300, 400, 500 ] ],
[ 150, [ 150, 175, 200, 250, 300, 400, 500 ] ],
[ 175, [ 175, 200, 250, 300, 400, 500, 750 ] ],
[ 200, [ 200, 250, 300, 350, 400, 500, 750 ] ],
],
'4HA7' : [
[ 0, [ 2.75, 5, 10, 20, 25, 35, 100 ] ],
[ 5, [ 5, 10, 15, 20, 35, 50, 200 ] ],
[ 10, [ 10, 15, 20, 25, 35, 50, 250 ] ],
[ 15, [ 15, 20, 25, 35, 50, 75, 300 ] ],
[ 20, [ 20, 25, 35, 50, 75, 100, 500 ] ],
[ 25, [ 25, 30, 40, 50, 75, 100, 500 ] ],
[ 35, [ 35, 50, 75, 100, 200, 300, 1000 ] ],
[ 75, [ 75, 100, 150, 250, 500, 750, 2000 ] ],
[ 100, [ 100, 150, 250, 500, 750, 1000, 5000 ] ],
[ 150, [ 150, 200, 300, 500, 750, 1000, 7500 ] ],
[ 200, [ 200, 300, 500, 750, 1000, 2500, 10000 ] ],
[ 500, [ 500, 750, 1000, 2500, 5000, 7500, 12000 ] ],
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 12000 ] ]
],
'5LA1' : [
[ 0, [ 1, 5, 10, 15, 20, 30, 50 ] ],
[ 3, [ 3, 5, 10, 20, 35, 50, 75 ] ],
[ 6, [ 5, 10, 20, 35, 50, 75, 100 ] ],
[ 10, [ 10, 15, 25, 50, 75, 100, 125 ] ],
[ 13, [ 10, 20, 35, 50, 75, 100, 125 ] ],
[ 16, [ 15, 25, 50, 75, 100, 150, 200 ] ],
[ 20, [ 20, 35, 50, 75, 125, 150, 200 ] ],
[ 23, [ 20, 35, 50, 75, 125, 175, 250 ] ],
[ 26, [ 25, 35, 50, 75, 125, 175, 250 ] ],
[ 30, [ 30, 40, 50, 75, 125, 175, 250 ] ],
[ 35, [ 35, 45, 50, 100, 125, 175, 300 ] ],
[ 40, [ 40, 50, 75, 100, 150, 200, 300 ] ],
[ 45, [ 45, 50, 75, 100, 150, 250, 500 ] ],
[ 50, [ 50, 75, 100, 125, 175, 250, 500 ] ],
[ 60, [ 60, 75, 100, 125, 175, 250, 500 ] ],
[ 70, [ 70, 85, 100, 125, 175, 250, 500 ] ],
[ 80, [ 80, 100, 125, 150, 200, 300, 500 ] ],
[ 90, [ 90, 100, 125, 150, 200, 300, 500 ] ],
[ 100, [ 100, 125, 175, 250, 350, 500, 750 ] ],
[ 125, [ 125, 150, 200, 300, 500, 750, 1000 ] ],
[ 150, [ 150, 200, 300, 400, 500, 750, 1000 ] ],
[ 175, [ 175, 200, 300, 400, 500, 750, 1000 ] ],
[ 200, [ 200, 225, 300, 400, 500, 750, 1000 ] ],
],
'2018control' : [
[ 0, [ 5, 10, 20, 25, 35, 50, 100 ] ],
[ 5, [ 10, 15, 20, 35, 50, 100, 150 ] ],
[ 10, [ 15, 20, 25, 35, 50, 100, 150 ] ],
[ 15, [ 20, 25, 35, 50, 75, 100, 250 ] ],
[ 20, [ 25, 35, 50, 75, 100, 150, 250 ] ],
[ 25, [ 30, 40, 50, 75, 100, 150, 250 ] ],
[ 35, [ 25, 50, 75, 100, 200, 250, 300 ] ],
[ 75, [ 25, 50, 75, 100, 200, 300, 500 ] ],
[ 100, [ 25, 50, 100, 150, 250, 500, 1000 ] ],
[ 150, [ 50, 100, 150, 200, 350, 500, 1000 ] ],
[ 200, [ 100, 150, 200, 300, 400, 500, 1000 ] ],
[ 500, [ 100, 250, 500, 750, 1000, 1500, 2000 ] ],
[ 1000, [ 500, 1000, 2000, 2500, 3000, 4000, 5000 ] ]
],
'LTLA' : [
[ 0, [ 3, 10, 15, 20, 35, 50, 100 ] ],
[ 5, [ 5, 10, 20, 35, 50, 100, 150 ] ],
[ 10, [ 10, 20, 35, 50, 75, 100, 150 ] ],
[ 15, [ 15, 25, 35, 50, 75, 100, 250 ] ],
[ 20, [ 20, 30, 50, 75, 100, 150, 250 ] ],
[ 25, [ 25, 35, 50, 75, 100, 150, 250 ] ],
[ 35, [ 25, 50, 75, 100, 200, 250, 300 ] ],
[ 75, [ 25, 50, 75, 100, 200, 300, 500 ] ],
[ 100, [ 25, 50, 100, 150, 250, 500, 1000 ] ],
[ 150, [ 50, 100, 150, 200, 350, 500, 1000 ] ],
[ 200, [ 100, 150, 200, 300, 400, 500, 1000 ] ],
[ 500, [ 100, 250, 500, 750, 1000, 1500, 2000 ] ],
[ 1000, [ 500, 1000, 2000, 2500, 3000, 4000, 5000 ] ]
],
'midtier2018' : [
[ 0, [ 3, 5, 10, 20, 30, 50, 100 ] ],
[ 5, [ 5, 10, 20, 35, 50, 100, 150 ] ],
[ 10, [ 10, 15, 20, 35, 50, 100, 150 ] ],
[ 15, [ 15, 20, 25, 35, 50, 100, 150 ] ],
[ 20, [ 20, 25, 35, 50, 75, 100, 150 ] ],
[ 25, [ 35, 50, 75, 100, 150, 250, 500 ] ],
[ 35, [ 50, 75, 100, 150, 250, 350, 500 ] ],
[ 50, [ 75, 100, 150, 200, 250, 350, 500 ] ],
[ 75, [ 100, 150, 200, 300, 400, 500, 1000 ] ],
[ 100, [ 150, 200, 250, 300, 400, 500, 1000 ] ],
[ 150, [ 200, 250, 300, 400, 500, 1000, 2500 ] ],
[ 200, [ 500, 750, 1000, 2000, 3500, 5000, 7500 ] ],
[ 500, [ 750, 1000, 1500, 2500, 5000, 7500, 10000 ] ],
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ]
],
'LT2018' : [
[ 0, [ 5, 10, 20.18, 25, 35, 50, 100 ] ],
[ 5, [ 10, 15, 20.18, 35, 50, 100, 150 ] ],
[ 10, [ 15, 20.18, 25, 35, 50, 100, 150 ] ],
[ 15, [ 20.18, 25, 35, 50, 75, 100, 250 ] ],
[ 20, [ 25, 35, 50, 75, 100, 150, 250 ] ],
[ 25, [ 30, 40, 50, 75, 100, 150, 250 ] ],
[ 35, [ 25, 50, 75, 100, 200, 250, 300 ] ],
[ 75, [ 25, 50, 75, 100, 200, 300, 500 ] ],
[ 100, [ 25, 50, 100, 150, 250, 500, 1000 ] ],
[ 150, [ 50, 100, 150, 200, 350, 500, 1000 ] ],
[ 200, [ 100, 150, 200, 300, 400, 500, 1000 ] ],
[ 500, [ 100, 250, 500, 750, 1000, 1500, 2018 ] ],
[ 1000, [ 500, 1000, 2018, 2500, 3000, 4000, 5000 ] ]
]
},
'JPY'"EUR" : [ // also used for GBP
[ 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 ] ]
],
"JPY" : [
[ 0, [ 500, 1000, 2000, 2500, 4000, 5000, 10000 ] ],
[ 1000, [ 1000, 1500, 2500, 4000, 5000, 10000, 15000 ] ],
Line 451 ⟶ 333:
[ 10000, [ 10000, 25000, 50000, 75000, 100000, 150000, 200000 ] ]
],
'"SEK'" : [
[ 0, [ 2030, 50100, 100150, 200, 300500, 500750, 1000 ] ],
[ 3050, [ 30, 50, 100, 150, 200, 300, 500750, 1000 ] ],
[ 50, [ 50, 100, 150, 200, 300, 500, 1000 ] ],
[ 200, [ 50, 100, 200, 300, 500, 750, 1000 ] ]
]
Line 460 ⟶ 341:
radioAmountsData.AUD = radioAmountsData.USD;
radioAmountsData.CAD = radioAmountsData.USD;
radioAmountsData.GBP = radioAmountsData.USD;
radioAmountsData.NZD = radioAmountsData.USD;
 
radioAmountsData.EUR = radioAmountsData.USD;
radioAmountsData.GBP = radioAmountsData.EUR;
 
var appealAmountsData = {
'"USD'" : [ // also used for CAD, AUD, NZD, GBP, EUR
[ 0, [ 5, 10, 20 ] ],
[ 10, [ 10, 20, 50 ] ],
Line 476 ⟶ 357:
[ 200, [ 100, 200, 300 ] ]
],
'"JPY'" : [
[ 0, [ 300, 500, 1000 ] ],
[ 3, [ 500, 1000, 1500 ] ],
Line 485 ⟶ 366:
[ 100, [ 5000, 10000, 15000 ] ]
],
'"SEK'" : [
[ 0, [ 20, 50, 100 ] ],
[ 3, [ 30, 50, 100 ] ],
Line 526 ⟶ 407:
};
 
var format;
if ( formats[currency] ) {
var format = formats[currency][language] || formats[currency]['default'] || formats[currency] || '\t';
} else {
format = '\t';
}
 
// Radio button amounts
Line 598 ⟶ 484:
/* 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 + '"]');
Line 637 ⟶ 523:
'PT' : 'vmaj',
'SK' : 'vmaj',
'GR' : 'vma',
// Others
'CZ' : 'vmad',
'DK' : 'vma',
'HU' : 'vma',
'IL' : 'vmad', // Adyen
'JP' : 'vmjvmaj',
'MY' : 'vmaj',
'NO' : 'vma',
Line 648 ⟶ 536:
'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 671 ⟶ 561:
/* -- Moved from Template:2012FR/Form-section/Processing/Default -- */
/**
* Validate form, and ifprep itmost looksof goodthe submit to paymentsparameters
*
* @param {string} paymentMethod - method e.g. 'cc', 'paypal'
Line 681 ⟶ 571:
if ( donationForm.validate( skipAmountValidation ) ) {
 
var uri = new mw.Uri('https://payments.wikimedia.org/index.php/Special:GatewayFormChooser');
var params = {};
 
params.currency = donationForm.currency;
params.country = donationForm.country;
 
// Overrides for specific cc gateways
Line 688 ⟶ 580:
params.payment_method = 'cc';
params.gateway = 'adyen';
params.ffname = 'adyen';
} else if ( paymentMethod === 'cc-dlocal' ) {
params.payment_method = 'cc';
Line 694 ⟶ 585:
} else {
params.payment_method = paymentMethod;
}
 
if ( params.payment_method === 'cc' && params.country === 'ZA' ) {
params.gateway = 'astropay';
}
 
Line 707 ⟶ 602:
}
 
params.currency_code = donationForm.currency;
params.country = donationForm.country;
params.uselang = mw.config.get('wgPageContentLanguage'); // see T281285 for why not wgUserLanguage
 
if ( params.uselang === 'pt' && params.country === 'BR' ) {
params.uselang = 'pt-br';
Line 717 ⟶ 610:
( 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';
Line 733 ⟶ 627:
var opt_inValue = $('input[name="opt_in"]:checked').val();
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';
}
 
Line 744 ⟶ 632:
params.variant = mw.util.getParamValue( 'pym_variant' );
}
if ( params.recurring && params.variant && params.variant.match( /monthlyConvert/ ) ) {
// Post-payments monthly convert makes no sense if it's already recurring
// Avoid things like T312905
delete params.variant;
}
 
if ( mw.util.getParamValue( 'pym_appeal' ) ) {
params.appeal = mw.util.getParamValue( 'pym_appeal' );
}
 
// Monthly convert
donationForm.extraData.time = Math.round( (Date.now() - donationForm.loadedTime)/1000 );
if ( mc ) { // check just in-case this wasn't loaded for some reason
 
mc.main( params, donationForm.finalStep );
// Tracking data
} else {
params.utm_medium = mw.util.getParamValue( 'utm_medium' );
donationForm.finalStep( params );
params.utm_campaign = mw.util.getParamValue( 'utm_campaign' );
params.utm_source = donationForm.buildUtmSource( params );
params.utm_key = donationForm.buildUtmKey( 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 );
donationForm.goToPayments( uri );
 
} else {
Line 770 ⟶ 656:
};
 
/**
* Build final tracking parameters, and submit to payments
* @param {Object} params
*/
donationForm.finalStep = function( params ) {
 
var uri = new mw.Uri('https://payments.wikimedia.org/index.php/Special:GatewayChooser');
 
// Skip form chooser for Apple Pay / Google Pay
if ( params.payment_method === 'apple' || params.payment_method === 'google' ) {
uri = new mw.Uri('https://payments.wikimedia.org/index.php/Special:AdyenCheckoutGateway');
}
 
// Skip form chooser for Venmo
if ( params.payment_method === 'venmo' ) {
uri = new mw.Uri('https://payments.wikimedia.org/index.php/Special:BraintreeGateway');
}
 
donationForm.extraData.time = Math.round( (Date.now() - donationForm.loadedTime)/1000 );
 
// Tracking data
params.wmf_medium = mw.util.getParamValue( 'wmf_medium' ) || mw.util.getParamValue( 'utm_medium' );
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 );
 
donationForm.goToPayments = function( uri ) {
if ( window.top !== window.self ) {
// In a frame, open payments in a new tab
Line 781 ⟶ 697:
 
/**
* 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 810 ⟶ 727:
 
/* 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 845 ⟶ 762:
/* Return amount selected or input */
donationForm.getAmount = function() {
var form = document.forms['.donateForm'];,
var amount = null;
donationForm.extraData.otherAmt = 0;
 
Line 853 ⟶ 770:
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 );
otherAmount = otherAmount.replace(/[,.](\d)$/, '\:$10');
otherAmount = otherAmount.replace(/[,.](\d)(\d)$/, '\:$1$2');
otherAmount = otherAmount.replace(/[\$£€¥,.]/g, '');
otherAmount = otherAmount.replace(/:/, '.');
amount = otherAmount;
donationForm.extraData.otherAmt = 1;
}
 
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;
}
 
};
 
 
/**
Line 886 ⟶ 815:
 
var error = false;
var form = document.forms['.donateForm'];
 
// Reset all errors
Line 943 ⟶ 872:
 
donationForm.updateFeeDisplay = function() {
var feeAmountselectedAmount = donationForm.calculateFee( donationForm.getAmount() );,
feeAmount = donationForm.calculateFee( selectedAmount ),
if ( feeAmount % 1 !== 0 ) { // Not a whole number
minAmount = donationForm.minimums[ donationForm.currency ] || 1,
feeAmount = feeAmount.toFixed(2);
maxAmount = donationForm.maxUSD * minAmount,
} else {
feeAmountfeeText, = feeAmount.toString()locale;
 
locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country );
feeText = donationForm.formatAmount( feeAmount, locale );
 
$('.ptf label span').text( feeText );
if ( selectedAmount + feeAmount <= maxAmount ) {
$('.ptf').slideDown();
}
$('.ptf label span').text( feeAmount );
$('.ptf').slideDown();
};
 
Line 966 ⟶ 900:
'HUF' : 100,
'ILS' : 1.2,
'INR' : 254,
'JPY' : 35,
'MYR' : 1,
'NOK' : 3,
'PLN' : 1.35,
'CZK' : 7.5,
'RON' : 1.5,
'SEK' : 3,
'UAH' : 10,
'ZAR' : 5,
// Latin America // Updated 2023-01-17 to approx 0.35 USD equivalent
'BRL' : 21.75,
'ARS' : 32,
'CLP' : 255322,
'COP' : 13001385,
'MXN' : 7.46,
'PEN' : 1.3,
'UYU' : 1513.57
};
 
Line 1,013 ⟶ 948:
}
});
};
 
/**
* 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;
}
};
}
};
 
/**
* 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;
};
 
/**
* 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;
};
 
/**
* 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;
};
 
/*
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;
}
};
 
Line 1,021 ⟶ 1,220:
mw.loader.using( ['mediawiki.util'] ).done( function() {
 
var form = document.forms['.donateForm'];
 
// These get used in quite a few places
try {
donationForm.currency = form.currency_code.value;
} catch (error) {
donationForm.country = mw.util.getParamValue('country');
donationForm.currency = 'USD';
}
donationForm.country = mw.util.getParamValue('country').toUpperCase();
 
// Block typing symbols in inputOther field, otherwise Safari allows them and then chokes
donationForm.otherInputControl( document.getElementById('input_amount_other_box') );
// https://phabricator.wikimedia.org/T118741, https://phabricator.wikimedia.org/T173431
var amountOtherInput = document.getElementById('input_amount_other_box');
if ( amountOtherInput ) {
amountOtherInput.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;
}
};
}
 
// Validate amount and update fee when selected/entered
Line 1,072 ⟶ 1,260:
$('#frequency_onetime').prop('checked', true);
$('.frequency-options, #cancel-monthly, #donate-recurring-smallprint').hide();
}
 
if ( donationForm.noRecurringPaypalCountries.indexOf( donationForm.country ) !== -1 ) {
$( '.paymentmethod-pp, .paymentmethod-pp-usd' ).addClass( 'not-monthly-capable' );
}
 
addCardTypesClass( donationForm.country );
 
// Only show Amazon for links from Ways to give
// TODO: remove utm_source when Ways to give has been updated
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 1,091 ⟶ 1,306:
 
// 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
) {
$('#frequency_monthly').click();
}
Line 1,104 ⟶ 1,322:
}
finally {
$('.frb-monthly-pitch, .frb-monthly-pitch-thanks').appendTo('.frequency-options');
$('.ptf').appendTo('.amount-options');
$('.optin-options').insertAfter('.amount-options');