MediaWiki:DonationForm.js: Difference between revisions

Content deleted Content added
force country to always uppercase
No edit summary
 
(55 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
// Updated 20222024-0201-0419
'ADF' : 56.6408,
'ADP' : 143154,
'AED' : 3.67,
'AFA' : 8968,
'AFN' : 8968,
'ALL' : 10494,
'AMD' : 456388,
'ANG' : 1.79,
'AOA' : 592828,
'AON' : 592828,
'ARS' : 99366,
'ATS' : 1213,
'AUD' : 1.3452,
'AWG' : 1.879,
'AZM' : 8500,
'AZN' : 1.7,
'BAM' : 1.6881,
'BBD' : 2,
'BDT' : 84109,
'BEF' : 3537,
'BGL' : 1.6881,
'BGN' : 1.6881,
'BHD' : 0.3738948752488637452802080547,
'BIF' : 19742826,
'BMD' : 1,
'BND' : 1.3534,
'BOB' : 6.73,
'BRL' : 54.6195,
'BSD' : 1,
'BTN' : 7583,
'BWP' : 1114,
'BYR' : 2413032900,
'BZD' : 1.97,
'CAD' : 1.2436,
'CDF' : 19862611,
'CHF' : 0.9180424035526787620362389075,
'CLP' : 812880,
'CNY' : 67.3817,
'COP' : 37623970,
'CRC' : 616520,
'CUC' : 1,
'CUP' : 25,
'CVE' : 95102,
'CYP' : 0.5033211200827254264835979874,
'CZK' : 2223,
'DEM' : 1.6881,
'DJF' : 178,
'DKK' : 6.491,
'DOP' : 56,
'DZD' : 137134,
'ECS' : 24094,
'EEK' : 1315,
'EGP' : 1631,
'ESP' : 143154,
'ETB' : 4756,
'EUR' : 0.859975191248492716976971251,
'FIM' : 5.1151,
'FJD' : 2.0622,
'FKP' : 0.7262200377571479581971718638,
'FRF' : 56.6408,
'GBP' : 0.7262200377571479581971718638,
'GEL' : 32.1164,
'GHC' : 60651120114,
'GHS' : 6.0712,
'GIP' : 0.7262200377571479581971718638,
'GMD' : 5267,
'GNF' : 95638522,
'GRD' : 293316,
'GTQ' : 7.5664,
'GYD' : 201200,
'HKD' : 7.7781,
'HNL' : 24,
'HRK' : 6.4799,
'HTG' : 98131,
'HUF' : 314355,
'IDR' : 1416615593,
'IEP' : 0.6772855015203673020553251391,
'ILS' : 3.271,
'INR' : 7510,
'IQD' : 14451292,
'IRR' : 42000,
'ISK' : 129140,
'ITL' : 16651795,
'JMD' : 151154,
'JOD' : 0.70900000000001,
'JPY' : 114146,
'KES' : 110153,
'KGS' : 8589,
'KHR' : 40214051,
'KMF' : 423456,
'KPW' : 135,
'KRW' : 11691313,
'KWD' : 0.3008498920668430762164728865,
'KYD' : 0.83333299999999,
'KZT' : 424456,
'LAK' : 1000220577,
'LBP' : 150815000,
'LKR' : 200325,
'LRD' : 158187,
'LSL' : 1519,
'LTL' : 23.972,
'LUF' : 3537,
'LVL' : 0.6043940043101765161862283304,
'LYD' : 4.518,
'MAD' : 8.9510,
'MDL' : 1718,
'MGA' : 39184549,
'MGF' : 9150,
'MKD' : 5257,
'MMK' : 18432080,
'MNT' : 2620,
'MOP' : 8.0104,
'MRO' : 359392,
'MTL' : 0.3691873496029639803398213759,
'MUR' : 4243,
'MVR' : 15,
'MWK' : 8081674,
'MXN' : 2017,
'MYR' : 4.1568,
'MZM' : 63200,
'MZN' : 63,
'NAD' : 1519,
'NGN' : 411791,
'NIO' : 3536,
'NLG' : 12.904,
'NOK' : 8.3511,
'NPR' : 118132,
'NZD' : 1.463,
'OMR' : 0.3836983029433138381212511836,
'PAB' : 1,
'PEN' : 3.9374,
'PGK' : 3.4364,
'PHP' : 5156,
'PKR' : 174283,
'PLN' : 34.9602,
'PTE' : 172186,
'PYG' : 67997244,
'QAR' : 3.6264,
'ROL' : 4250546063,
'RON' : 4.2561,
'RSD' : 101108,
'RUB' : 7090,
'RWF' : 9961237,
'SAR' : 3.75,
'SBD' : 8.0135,
'SCR' : 13,
'SDD' : 4367659800,
'SDG' : 437598,
'SDP' : 2261,
'SEK' : 8.5910,
'SGD' : 1.3534,
'SHP' : 0.7262200377571479581971718638,
'SIT' : 206222,
'SKK' : 2628,
'SLL' : 1068419750,
'SOS' : 562,
'SRD' : 2137,
'SRG' : 2136337356,
'STD' : 2082622552,
'SVC' : 8.75,
'SYP' : 513,
'SZL' : 1519,
'THB' : 3336,
'TJS' : 11,
'TMM' : 1679416750,
'TMT' : 3.3635,
'TND' : 23.8211,
'TOP' : 2.1932,
'TRL' : 965494229009007,
'TRY' : 9.6529,
'TTD' : 6.6765,
'TWD' : 2831,
'TZS' : 23032498,
'UAH' : 2637,
'UGX' : 35483784,
'USD' : 1,
'UYU' : 4339,
'UZS' : 1065412302,
'VEB' : 4207763103553825326,
'VEF' : 4207763553825,
'VND' : 2271024259,
'VUV' : 112,
'WST' : 2.5168,
'XAF' : 564608,
'XAG' : 0.04084236107244043725386677957,
'XAU' : 0.00055475059827898000504038919286,
'XCD' : 2.7,
'XEU' : 0.859975191248492716976971251,
'XOF' : 564608,
'XPD' : 0.000490118884148001025937507186,
'XPF' : 103111,
'XPT' : 0.00094617370232302001084078572954,
'YER' : 250,
'YUN' : 101108,
'ZAR' : 1519,
'ZMK' : 5176,
'ZWD' : 373
Line 224 ⟶ 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 244 ⟶ 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 273 ⟶ 269:
// 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, 150 200, 250 300, 500, 750, 1000 ] ],
[ 100 75, [ 75, 100, 150, 250, 500, 750, 1000, 2500 ] ],
[ 150100, [ 150100, 200 150, 300 250, 500, 750, 1000, 20002500 ] ],
[ 200150, [ 150, 200, 300, 500, 750, 1000, 25001000, 50002000 ] ],
[ 500200, [ 500200, 750 300, 1000 500, 2500 750, 5000 1000, 75002500, 10000 5000 ] ],
[ 1000 500, [ 1000 500, 2000 750, 3000 1000, 4000 2500, 5000, 7500, 10000 ] ],
[ 30001000, [ 1000, 2000, 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ],
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
'2incvar' : [
[ 0, [ 1, 5, 10, 15, 20, 30, 50 ] ],
[ 3, [ 3, 5, 10, 20, 35, 50, 75 ] ],
[ 6, [ 6, 10, 20, 35, 50, 75, 100 ] ],
[ 10, [ 10, 15, 25, 50, 75, 100, 125 ] ],
[ 13, [ 13, 20, 35, 50, 75, 100, 125 ] ],
[ 16, [ 16, 25, 50, 75, 100, 150, 200 ] ],
[ 20, [ 20, 35, 50, 75, 125, 150, 200 ] ],
[ 23, [ 23, 35, 50, 75, 125, 175, 250 ] ],
[ 26, [ 26, 35, 50, 75, 125, 175, 250 ] ],
[ 30, [ 30, 40, 50, 75, 125, 175, 250 ] ],
[ 35, [ 35, 45, 50, 100, 125, 175, 250 ] ],
[ 40, [ 40, 50, 75, 100, 150, 250, 300 ] ],
[ 45, [ 45, 50, 75, 100, 150, 250, 500 ] ],
[ 50, [ 50, 60, 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, 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'"midtier2018" : [
[ 0, [ 5 3, 10 5, 20.18 10, 25 20, 35 30, 50, 100 ] ],
[ 5, [ 10 5, 15 10, 20.18, 35, 50, 100, 150 ] ],
[ 10, [ 15 10, 20.18 15, 25 20, 35, 50, 100, 150 ] ],
[ 15, [ 15, 20.18, 25, 35, 50, 75, 100, 250 150 ] ],
[ 20, [ 20, 25, 35, 50, 75, 100, 150, 250150 ] ],
[ 25, [ 30, 4035, 50, 75, 100, 150, 250, 500 ] ],
[ 35, [ 25, 50, 75, 100, 200 150, 250, 300 350, 500 ] ],
[ 7550, [ 25 75, 50100, 75150, 100 200, 200 250, 300 350, 500 ] ],
[ 100 75, [ 25100, 50150, 100 200, 150 300, 250 400, 500, 1000 ] ],
[ 150100, [ 50150, 100 200, 150 250, 200 300, 350 400, 500, 1000 ] ],
[ 200150, [ 100, 150200, 200 250, 300, 400, 500, 1000, 2500 ] ],
[ 500200, [ 100 500, 250 750, 5001000, 7502000, 1000 3500, 1500 5000, 2018 7500 ] ],
[ 1000 500, [ 500 750, 1000, 2018 1500, 2500, 3000 5000, 4000 7500, 500010000 ] ],
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ]
]
},
'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 454 ⟶ 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 463 ⟶ 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 479 ⟶ 357:
[ 200, [ 100, 200, 300 ] ]
],
'"JPY'" : [
[ 0, [ 300, 500, 1000 ] ],
[ 3, [ 500, 1000, 1500 ] ],
Line 488 ⟶ 366:
[ 100, [ 5000, 10000, 15000 ] ]
],
'"SEK'" : [
[ 0, [ 20, 50, 100 ] ],
[ 3, [ 30, 50, 100 ] ],
Line 529 ⟶ 407:
};
 
var format;
if ( formats[currency] ) {
var format = formats[currency][language] || formats[currency]['default'] || formats[currency] || '\t';
} else {
format = '\t';
}
 
// Radio button amounts
Line 640 ⟶ 523:
'PT' : 'vmaj',
'SK' : 'vmaj',
'GR' : 'vma',
// Others
'CZ' : 'vmad',
'DK' : 'vma',
'HU' : 'vma',
'IL' : 'vmad', // Adyen
'JP' : 'vmjvmaj',
'MY' : 'vmaj',
'NO' : 'vma',
Line 651 ⟶ 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 685 ⟶ 572:
 
var params = {};
 
params.currency = donationForm.currency;
params.country = donationForm.country;
 
// Overrides for specific cc gateways
Line 690 ⟶ 580:
params.payment_method = 'cc';
params.gateway = 'adyen';
params.ffname = 'adyen';
} else if ( paymentMethod === 'cc-dlocal' ) {
params.payment_method = 'cc';
Line 696 ⟶ 585:
} else {
params.payment_method = paymentMethod;
}
 
if ( params.payment_method === 'cc' && params.country === 'ZA' ) {
params.gateway = 'astropay';
}
 
Line 709 ⟶ 602:
}
 
params.currency_code = donationForm.currency;
params.country = donationForm.country;
params.uselang = mw.config.get('wgPageContentLanguage'); // see T281285 for why not wgUserLanguage
 
Line 736 ⟶ 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 747 ⟶ 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' );
}
 
// Check for monthlyMonthly convert. TODO: make it possible to test JS variants
if ( mc ) { // check just in-case this wasn't loaded for some reason
if ( mw.util.getParamValue( 'monthlyconvert' ) ) {
mc.main( params, donationForm.finalStep );
} else {
Line 771 ⟶ 662:
donationForm.finalStep = function( params ) {
 
var uri = new mw.Uri('https://payments.wikimedia.org/index.php/Special:GatewayFormChooserGatewayChooser');
 
// 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');
}
 
Line 781 ⟶ 677:
 
// 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 801 ⟶ 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 830 ⟶ 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 865 ⟶ 762:
/* Return amount selected or input */
donationForm.getAmount = function() {
var form = document.forms['.donateForm'],
amount = null;
donationForm.extraData.otherAmt = 0;
Line 918 ⟶ 815:
 
var error = false;
var form = document.forms['.donateForm'];
 
// Reset all errors
Line 979 ⟶ 876:
minAmount = donationForm.minimums[ donationForm.currency ] || 1,
maxAmount = donationForm.maxUSD * minAmount,
feeText, locale;
 
locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country );
if ( feeAmount % 1 !== 0 ) { // Not a whole number
feeText = feeAmountdonationForm.toFixedformatAmount(2 feeAmount, locale );
} else {
feeText = feeAmount.toString();
}
 
$('.ptf label span').text( feeText );
Line 1,006 ⟶ 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,082 ⟶ 977:
/**
* Make language and country into a standard javascript Intl locale identifier
*
* Currently only used in monthlyconvert, but this could be useful
*
* @param {string} language
* @param {string} country
* @return {string} locale identifier e.g. locale identifieren-GB
*/
donationForm.getLocale = function( language, country ) {
Line 1,111 ⟶ 1,004:
*/
donationForm.shouldShowApplePay = function ( country ) {
// TODO: Add country logic when we get a list from payments
if ( location.search.match('forceApplePay') ) {
return true;
Line 1,123 ⟶ 1,015:
};
 
/**
* 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;
}
};
 
/* End form functions */
Line 1,130 ⟶ 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.currency = 'USD';
}
donationForm.country = mw.util.getParamValue('country').toUpperCase();
Line 1,170 ⟶ 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
Line 1,178 ⟶ 1,281:
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,196 ⟶ 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,209 ⟶ 1,322:
}
finally {
$('.frb-monthly-pitch, .frb-monthly-pitch-thanks').appendTo('.frequency-options');
$('.ptf').appendTo('.amount-options');
$('.optin-options').insertAfter('.amount-options');