MediaWiki:DonationFormSandbox.js: Difference between revisions
Content deleted Content added
No edit summary |
base64 decode recipient_id if needed |
||
(34 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';
}
// MediaWiki allows some language codes like en-gb, en-ca, pt-br
// We don't want these for a javascript locale, so drop anything after '-'
language = language.split('-')[0];
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.
// 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' : 70,
'AFN' : 70,
'ALL' : 90,
'AMD' : 368,
'ANG' : 1.79,
'AOA' : 844,
'AON' : 844,
'ARS' : 887,
'ATS' : 13,
'AUD' : 1.5,
'AWG' : 1.79,
'AZM' : 8500,
'AZN' : 1.7,
'BAM' : 1.8,
'BBD' : 2,
'BDT' : 116,
'BEF' : 37,
'BGL' : 1.8,
'BGN' : 1.8,
'BHD' : 0.37355757356689,
'BIF' : 2842,
'BMD' : 1,
'BND' : 1.35,
'BOB' : 6.71,
'BRL' : 5.1,
'BSD' : 1,
'BTN' : 83,
'BWP' : 13,
'BYR' : 32642,
'BZD' : 1.98,
'CAD' : 1.36,
'CDF' : 2786,
'CHF' : 0.9094629289448,
'CLP' : 890,
'CNY' : 7.23,
'COP' : 3803,
'CRC' : 498,
'CUC' : 1,
'CUP' : 25,
'CVE' : 101,
'CYP' : 0.53848627984321,
'CZK' : 23,
'DEM' : 1.8,
'DJF' : 178,
'DKK' : 6.86,
'DOP' : 58,
'DZD' : 133,
'ECS' : 24094,
'EEK' : 14,
'EGP' : 47,
'ESP' : 153,
'ETB' : 57,
'EUR' : 0.92005843390143,
'FIM' : 5.47,
'FJD' : 2.23,
'FKP' : 0.78703952551207,
'FRF' : 6.04,
'GBP' : 0.78703952551207,
'GEL' : 2.71,
'GHC' : 143125,
'GHS' : 14,
'GIP' : 0.78703952551207,
'GMD' : 68,
'GNF' : 8493,
'GRD' : 314,
'GTQ' : 7.57,
'GYD' : 200,
'HKD' : 7.8,
'HNL' : 24,
'HRK' : 6.93,
'HTG' : 132,
'HUF' : 355,
'IDR' : 15986,
'IEP' : 0.72460490043714,
'ILS' : 3.69,
'INR' : 83,
'IQD' : 1290,
'IRR' : 42009,
'ISK' : 138,
'ITL' : 1781,
'JMD' : 154,
'JOD' : 0.70900000000001,
'JPY' : 156,
'KES' : 130,
'KGS' : 88,
'KHR' : 3993,
'KMF' : 453,
'KPW' : 135,
'KRW' : 1358,
'KWD' : 0.30629670764681,
'KYD' : 0.83333299999999,
'KZT' : 442,
'LAK' : 21103,
'LBP' : 89393,
'LKR' : 298,
'LRD' : 193,
'LSL' : 18,
'LTL' : 3.18,
'LUF' : 37,
'LVL' : 0.64662074757963,
'LYD' : 4.8,
'MAD' : 9.79,
'MDL' : 17,
'MGA' : 4379,
'MGF' : 9150,
'MKD' : 56,
'MMK' : 2075,
'MNT' : 2620,
'MOP' : 8.03,
'MRO' : 391,
'MTL' : 0.39498108567387,
'MUR' : 45,
'MVR' : 15,
'MWK' : 1720,
'MXN' : 17,
'MYR' : 4.68,
'MZM' : 63200,
'MZN' : 63,
'NAD' : 18,
'NGN' : 1505,
'NIO' : 36,
'NLG' : 2.03,
'NOK' : 11,
'NPR' : 131,
'NZD' : 1.63,
'OMR' : 0.38377594841305,
'PAB' : 1,
'PEN' : 3.67,
'PGK' : 3.76,
'PHP' : 58,
'PKR' : 277,
'PLN' : 3.91,
'PTE' : 184,
'PYG' : 7355,
'QAR' : 3.56,
'ROL' : 45713,
'RON' : 4.57,
'RSD' : 108,
'RUB' : 91,
'RWF' : 1277,
'SAR' : 3.75,
'SBD' : 8.37,
'SCR' : 13,
'SDD' : 59800,
'SDG' : 598,
'SDP' : 2261,
'SEK' : 11,
'SGD' : 1.35,
'SHP' : 0.78703952551207,
'SIT' : 220,
'SKK' : 28,
'SLL' : 19750,
'SOS' : 549,
'SRD' : 33,
'SRG' : 33320,
'STD' : 22477,
'SVC' : 8.75,
'SYP' : 513,
'SZL' : 18,
'THB' : 36,
'TJS' : 11,
'TMM' : 16750,
'TMT' : 3.35,
'TND' : 3.11,
'TOP' : 2.32,
'TRL' : 32168418,
'TRY' : 32,
'TTD' : 6.64,
'TWD' : 32,
'TZS' : 2587,
'UAH' : 39,
'UGX' : 3760,
'USD' : 1,
'UYU' : 38,
'UZS' : 12662,
'VEB' : 3651907631,
'VEF' : 3651908,
'VND' : 25451,
'VUV' : 112,
'WST' : 2.67,
'XAF' : 604,
'XAG' : 0.031347411860134,
'XAU' : 0.00041128929241299,
'XCD' : 2.7,
'XEU' : 0.92005843390143,
'XOF' : 604,
'XPD' : 0.00098009826645798,
'XPF' : 110,
'XPT' : 0.00093444018680404,
'YER' : 249,
'YUN' : 108,
'ZAR' : 18,
'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() {
$('.lp-error-smallamount').text( function( index, oldText ) {
return oldText.replace( '$1', donationForm.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', donationForm.formatAmount( donationForm.maxLocal ) )
.replace( '$2', currency )
.replace( '$4', donationForm.formatAmount( donationForm.maxUSD ) );
};
function adjustHPC() {
var hpcSet = mw.util.getParamValue('hpcSet');
// 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) ) {
if ( hpcSet ) {
// Allow using hpcSet even without hpc, for MG appeals
hpc = 0;
} else {
return;
}
}
}
var currency = donationForm.currency;
// If changing, please update https://docs.google.com/spreadsheets/d/1e02TsZ_bKDAS1BMVBCdyo9D7RGln_wCGnkg7IF5kU5s/edit
var radioAmountsData = {
"USD" : { // also used for CAD,
"default" : [
[ 0, [ 2.75, 5,
[ 5, [ 5,
[ 10, [ 10, 15,
[ 15, [ 15, 20,
[ 20, [ 20, 25,
[ 25, [ 25, 30,
[ 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,
[ 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_USD" : [ // Upgrade recurring +1 for lowest ask
[ 0, [ 3.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 ] ],
[ 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_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 ] ]
],
// Direct Mail - fixed amounts
"directmail" : [
[ 0, [ 25, 35, 50, 100, 150, 250, 300 ] ]
],
"directmail250" : [
[ 0, [ 250, 300, 500, 750, 1000, 2500, 5000 ] ]
]
},
"EUR" : {
"default" : [
[ 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 ] ],
[ 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 ] ]
],
"SEK" : [
[ 0, [ 30, 100, 150, 200, 500, 750, 1000 ] ],
[ 50, [ 50, 100, 150, 200, 300, 750, 1000 ] ],
[ 200, [ 50, 100, 200, 300, 500, 750, 1000 ] ]
]
};
radioAmountsData.AUD = radioAmountsData.USD;
radioAmountsData.CAD = radioAmountsData.USD;
radioAmountsData.NZD = 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,
[ 20, [ 20, 30, 50 ] ],
[ 35, [ 20, 30, 50 ] ],
[ 50, [ 20, 50, 100 ] ],
[ 75, [ 50, 75, 100 ] ],
[ 100, [ 75, 100, 150 ] ],
[ 150, [ 75, 100, 200 ]
[ 200, [ 100, 200, 300 ] ]
],
"JPY" : [
[ 0, [ 300, 500, 1000 ] ],
[ 3, [ 500, 1000, 1500 ] ],
[ 5, [ 1000, 1500, 2000 ] ],
[ 10, [ 1500, 2000, 5000 ] ],
[ 20, [ 2000, 3000, 5000 ] ],
[ 50, [ 2000, 5000, 10000 ] ],
[ 100, [ 5000, 10000, 15000 ] ]
],
"SEK" : [
[ 0, [ 20, 50, 100 ] ],
[ 3, [ 30, 50, 100 ] ],
[ 5, [ 50, 100, 150 ] ],
[ 15, [ 100, 150, 200 ] ],
[ 23, [ 100, 200, 300 ] ],
[ 38, [ 100, 200, 500 ] ],
[ 75, [ 100, 500, 750 ] ],
[ 112, [ 100, 500, 1000 ] ]
]
};
appealAmountsData.AUD = appealAmountsData.USD;
appealAmountsData.CAD = appealAmountsData.USD;
appealAmountsData.GBP = appealAmountsData.USD;
appealAmountsData.NZD = appealAmountsData.USD;
appealAmountsData.EUR = appealAmountsData.USD;
// Change buttons
for (var j = 0; j < radioAmounts.length; j++) {
var $radio = $("#input_amount_" + j);
var $label = $("label[for='input_amount_" + j + "']");
$radio.val( radioAmounts[j] );
$label.text( donationForm.formatCurrency( radioAmounts[j] ) );
}
}
// Appeal amounts
var appealAmounts = pickAmountArray( appealAmountsData, currency, hpc, hpcSet );
if ( appealAmounts.length ) {
var appealAmountString = appealAmounts.map( donationForm.formatCurrency ).join( ', ');
$('.consider-amounts').html(appealAmountString);
}
}
function pickAmountArray( data, currency, hpc, hpcSet ) {
}
}
}
}
}
}
function preSelect() {
}
}
}
function addCardTypesClass(country) {
}
}
/* Form functions */
function clearOther(box) {
}
function selectOther() {
}
function selectAmount() {
}
Line 654 ⟶ 769:
donationForm.redirectPayment = function( paymentMethod, paymentSubMethod, skipAmountValidation ) {
}
}
}
params.frequency_unit = 'month';
} else if ( frequency === 'annual' ) {
params.recurring = '1';
params.frequency_unit = 'year';
}
}
}
}
}
}
}
// TODO: refactor this to a list of parameters to pass unchanged
// or just pass everything by default?
if ( mw.util.getParamValue( 'pym_appeal' ) ) {
params.appeal = mw.util.getParamValue( 'pym_appeal' );
}
// https://phabricator.wikimedia.org/T381405
if ( mw.util.getParamValue( 'contact_id' ) ) {
params.contact_id = mw.util.getParamValue( 'contact_id' );
}
if ( mw.util.getParamValue( 'contact_hash' ) ) {
params.contact_hash = mw.util.getParamValue( 'contact_hash' );
}
// SMS
var recipient_id = mw.util.getParamValue( 'recipient_id' );
if ( recipient_id ) {
if ( isNaN( parseFloat( recipient_id ) ) ) {
// Lop off last 2 characters and decode base64
params.recipient_id = atob( recipient_id.slice(0, -2) );
} else {
params.recipient_id = recipient_id;
}
}
}
}
};
Line 747 ⟶ 883:
donationForm.finalStep = function( params ) {
}
}
}
for ( var key
url.searchParams.set( key, params[key] );
}
}
};
Line 791 ⟶ 929:
donationForm.buildTrackingSource = function( params ) {
}
}
}
};
Line 831 ⟶ 969:
*/
donationForm.buildTrackingKey = function(data) {
}
}
}
};
/* Return amount selected or input */
donationForm.getAmount = function() {
}
}
}
}
};
Line 879 ⟶ 1,017:
*/
donationForm.parseOtherAmount = function( value ) {
}
};
Line 899 ⟶ 1,037:
donationForm.validate = function( skipAmountValidation ) {
}
}
}
};
Line 928 ⟶ 1,066:
donationForm.validateAmount = function() {
}
};
donationForm.
return document.forms.donateForm.dataset.frequency || 'onetime';
};
donationForm.setFrequency = function( frequency ) {
// TODO: add some validation to reject invalid frequency values
let form = document.forms.donateForm;
form.frequency.value = frequency; // change input
form.dataset.frequency = frequency;
};
/* Wrapper for compatibility with old forms */
donationForm.toggleMonthly = function( monthly ) {
if ( monthly ) {
donationForm.setFrequency( 'monthly' );
} else {
donationForm.setFrequency( 'onetime' );
}
};
donationForm.updateFeeDisplay = function() {
feeText;
feeText = donationForm.formatCurrency( feeAmount );
}
};
Line 979 ⟶ 1,126:
donationForm.calculateFee = function( amount ) {
}
};
donationForm.initOptin = function() {
}
}
}
};
Line 1,044 ⟶ 1,191:
*/
donationForm.otherInputControl = function( inputElement ) {
}
}
};
}
};
Line 1,089 ⟶ 1,216:
*/
donationForm.shouldShowApplePay = function ( country ) {
}
}
}
};
Line 1,131 ⟶ 1,233:
donationForm.isVenmoSupported = function(options) {
var options = options || {
};
var ua = window.navigator.userAgent;
var merchantAllowsReturningToNewBrowserTab,
var isMobileDevice = isAndroid() || isIos();
var isAndroidChrome = isAndroid() && isChrome();
Line 1,149 ⟶ 1,251:
// NEXT_MAJOR_VERSION allowDesktop will default to true, but can be opted out
merchantAllowsDesktopBrowsers =
merchantAllowsReturningToNewBrowserTab = options.hasOwnProperty(
)
// NEXT_MAJOR_VERSION webviews are not supported, except for the case where
// the merchant themselves is presenting venmo in a webview using the deep
Line 1,162 ⟶ 1,264:
// merchant's app via a webview.
merchantAllowsWebviews = options.hasOwnProperty("allowWebviews")
if (isKnownUnsupportedMobileBrowser) {
}
if (
) {
}
if (!isMobileDevice) {
}
if (!merchantAllowsReturningToNewBrowserTab) {
}
Line 1,189 ⟶ 1,291:
function isAndroid() {
}
function isIos(checkIpadOS = true) {
}
function isIpadOS() {
}
function isEdge() {
}
function isSamsung() {
}
function isDuckDuckGo() {
}
function isOpera() {
}
function isSilk() {
}
function isChrome() {
}
function isIosFirefox() {
}
function isWebkit() {
}
function isIosChrome() {
}
function isFacebook() {
}
function isIosSafari() {
}
function isFacebookOwnedBrowserOnAndroid() {
}
function isSamsungBrowser() {
}
function isAndroidWebview() {
}
function isGoogleSearchApp() {
}
function isIosGoogleSearchApp() {
}
function isIosWebview() {
}
}
};
Line 1,303 ⟶ 1,405:
$(document).ready(function() {
// Minimum amount is usually about 1 USD
donationForm.minLocal = donationForm.currencyRates[ donationForm.currency ];
donationForm.minLocal = Math.ceil( donationForm.minLocal * 100 ) / 100; // Round it up
donationForm.maxUSD = 25000;
donationForm.maxLocal = Math.floor( donationForm.currencyRates[ donationForm.currency ] * donationForm.maxUSD );
// Overrides for India
if
donationForm.minLocal = 10;
// Until https://phabricator.wikimedia.org/T370583 fixed?
donationForm.maxUSD = 3000;
donationForm.maxLocal = 250000;
}
// Block typing symbols in Other field
donationForm.otherInputControl( document.getElementById('input_amount_other_box') );
// Clear errors and update fee when selected/entered
// Ideally we would validate the amount, but this causes issues with focus
$('.amount-options .lp-error').hide();
donationForm.updateFeeDisplay();
});
// Disable submitting form with Enter key
var code = ( e.keyCode ? e.keyCode : e.which );
if ( code == 13 ) {
e.preventDefault();
}
});
// But allow Enter on buttons
$('.payment-method-button').keyup(function(e) {
if (event.keyCode === 13) {
e.target.click();
}
});
if ( form ) {
// hide frequency options for some countries
if ( donationForm.noRecurringCountries.indexOf( donationForm.country ) !== -1 ) {
$('#frequency_onetime').prop('checked', true);
$('.frequency-options, #cancel-monthly, #donate-recurring-smallprint').hide();
}
if (
$( '.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 );
// Only show Amazon for links from Ways to give
if (
mw.util.getParamValue( 'wmf_source' ) === 'Waystogive' ||
Line 1,362 ⟶ 1,478:
}
}
}
}
}
// Dumb hack to remove ACH for Portal test against Fundraise Up
if ( mw.util.getParamValue( 'wmf_source' ) === 'portalBanner_en6C_2024_overlayBanner4WikiForm' ) {
$('.paymentmethod-ach').remove();
}
}
// Links open in new tab
// Disable logo link
$('#p-logo a').attr( { href: '#', 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 frequency if possible
if (
donationForm.noRecurringCountries.indexOf( donationForm.country ) === -1
&& mw.util.getParamValue( 'utm_medium' ) !== 'endowment'
&& mw.util.getParamValue( 'wmf_medium' ) !== 'endowment'
) {
if ( mw.util.getParamValue( 'frequency' ) ) {
donationForm.setFrequency( mw.util.getParamValue( 'frequency' ) );
} else if ( mw.util.getParamValue('monthly') && mw.util.getParamValue('monthly') !== '0' ) {
// old method with "monthly=" parameter
donationForm.setFrequency( 'monthly' );
} else {
donationForm.setFrequency( 'onetime' );
}
}
}
}
});
|