MediaWiki:DonationForm.js: Difference between revisions
Content deleted Content added
Edited hpcSet for FY2425 Email 1 T21 to adapt for EUR & GBP currencies. |
Adding directmail250 hpcSet for US |
||
(21 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' ];
donationForm.noRecurringPaypalCountries = [ 'CL', 'CO', 'PE', 'UY', 'BR' ];
donationForm.
// From https://github.com/wikimedia/wikimedia-fundraising-SmashPig/blob/master/PaymentData/ReferenceData/CurrencyRates.php
// Updated 2024-
'ADF' : 6.
'ADP' :
'AED' : 3.67,
'AFA' :
'AFN' :
'ALL' :
'AMD' :
'ANG' : 1.79,
'AOA' :
'AON' :
'ARS' :
'ATS' : 13,
'AUD' : 1.
'AWG' : 1.79,
'AZM' : 8500,
'AZN' : 1.7,
'BAM' : 1.
'BBD' : 2,
'BDT' :
'BEF' : 37,
'BGL' : 1.
'BGN' : 1.
'BHD' : 0.
'BIF' :
'BMD' : 1,
'BND' : 1.
'BOB' : 6.
'BRL' :
'BSD' : 1,
'BTN' : 83,
'BWP' :
'BYR' :
'BZD' : 1.
'CAD' : 1.36,
'CDF' :
'CHF' : 0.
'CLP' :
'CNY' : 7.
'COP' :
'CRC' :
'CUC' : 1,
'CUP' : 25,
'CVE' :
'CYP' : 0.
'CZK' : 23,
'DEM' : 1.
'DJF' : 178,
'DKK' : 6.
'DOP' :
'DZD' :
'ECS' : 24094,
'EEK' :
'EGP' :
'ESP' :
'ETB' :
'EUR' : 0.
'FIM' : 5.
'FJD' : 2.
'FKP' : 0.
'FRF' : 6.
'GBP' : 0.
'GEL' : 2.
'GHC' :
'GHS' :
'GIP' : 0.
'GMD' :
'GNF' :
'GRD' :
'GTQ' : 7.
'GYD' : 200,
'HKD' : 7.
'HNL' : 24,
'HRK' : 6.
'HTG' :
'HUF' : 355,
'IDR' :
'IEP' : 0.
'ILS' : 3.
'INR' :
'IQD' :
'IRR' :
'ISK' :
'ITL' :
'JMD' : 154,
'JOD' : 0.70900000000001,
'JPY' :
'KES' :
'KGS' :
'KHR' :
'KMF' :
'KPW' : 135,
'KRW' :
'KWD' : 0.
'KYD' : 0.83333299999999,
'KZT' :
'LAK' :
'LBP' :
'LKR' :
'LRD' :
'LSL' :
'LTL' : 3.
'LUF' : 37,
'LVL' : 0.
'LYD' : 4.8,
'MAD' :
'MDL' :
'MGA' :
'MGF' : 9150,
'MKD' :
'MMK' :
'MNT' : 2620,
'MOP' : 8.
'MRO' :
'MTL' : 0.
'MUR' :
'MVR' : 15,
'MWK' :
'MXN' : 17,
'MYR' : 4.68,
'MZM' : 63200,
'MZN' : 63,
'NAD' :
'NGN' :
'NIO' : 36,
'NLG' : 2.
'NOK' : 11,
'NPR' :
'NZD' : 1.63,
'OMR' : 0.
'PAB' : 1,
'PEN' : 3.
'PGK' : 3.
'PHP' :
'PKR' :
'PLN' :
'PTE' :
'PYG' :
'QAR' : 3.
'ROL' :
'RON' : 4.
'RSD' : 108,
'RUB' :
'RWF' :
'SAR' : 3.75,
'SBD' : 8.
'SCR' : 13,
'SDD' : 59800,
'SDG' : 598,
'SDP' : 2261,
'SEK' :
'SGD' : 1.
'SHP' : 0.
'SIT' :
'SKK' : 28,
'SLL' : 19750,
'SOS' :
'SRD' :
'SRG' :
'STD' :
'SVC' : 8.75,
'SYP' : 513,
'SZL' :
'THB' : 36,
'TJS' : 11,
Line 187 ⟶ 220:
'TND' : 3.11,
'TOP' : 2.32,
'TRL' :
'TRY' :
'TTD' : 6.
'TWD' :
'TZS' :
'UAH' :
'UGX' :
'USD' : 1,
'UYU' :
'UZS' :
'VEB' :
'VEF' :
'VND' :
'VUV' : 112,
'WST' : 2.
'XAF' :
'XAG' : 0.
'XAU' : 0.
'XCD' : 2.7,
'XEU' : 0.
'XOF' :
'XPD' : 0.
'XPF' :
'XPT' : 0.
'YER' :
'YUN' : 108,
'ZAR' :
'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
$('.lp-error-smallamount').text( function( index, oldText ) {
return oldText.replace( '$1', donationForm.formatAmount(
});
Line 240 ⟶ 314:
$('.lp-error-bigamount').text( function( index, oldText ) {
return oldText.replace( '$1', donationForm.formatAmount( donationForm.
.replace( '$2', currency )
.replace( '$3', 'benefactors@wikimedia.org' )
.replace( '$4', donationForm.formatAmount( donationForm.maxUSD
});
};
Line 253 ⟶ 327:
TODO: split data out? */
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) ) {
// 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
Line 287 ⟶ 365:
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
"
[ 0, [ 3.75, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 5, 10, 15, 20, 35, 50, 100 ] ],
Line 304 ⟶ 382:
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
"
[ 0, [ 2.75,
[ 5, [ 2.75,
[ 10, [ 2.75,
[ 15, [
[ 20, [ 3.75,
[ 25, [ 4.50,
[ 35, [ 6.75,
[ 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,
[ 500, [ 150,
[ 1000, [ 250,
[ 3000, [ 500,
],
"
[ 0, [ 2.75, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 2.75, 5, 10, 20, 25, 35, 50 ] ],
Line 328 ⟶ 406:
[ 25, [ 20, 25, 35, 50, 75, 100, 150 ] ],
[ 35, [ 25, 30, 40, 50, 75, 100, 150 ] ],
[
[ 100, [ 75, 100, 150, 250, 500, 750, 1000 ] ],
[ 150, [ 100, 150, 250, 500, 750, 1000, 2500 ] ],
Line 337 ⟶ 414:
[ 3000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ]
],
"directmail" : [
[
],
"directmail250" : [
[
]
},
"EUR" : {
"default" : [
[ 0, [
[ 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 ] ]
],
"
[ 15, [
[ 35, [
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
"
[ 0, [
[ 5, [
[ 15, [
[ 20, [
[ 25, [ 4.25,
[ 35, [
[
[
[
[
[
],
"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 428 ⟶ 580:
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 = {
Line 467 ⟶ 624:
appealAmountsData.NZD = appealAmountsData.USD;
appealAmountsData.EUR = appealAmountsData.USD;
// Radio button amounts
Line 507 ⟶ 633:
var $label = $("label[for='input_amount_" + j + "']");
$radio.val( radioAmounts[j] );
$label.text(
}
}
Line 514 ⟶ 640:
var appealAmounts = pickAmountArray( appealAmountsData, currency, hpc, hpcSet );
if ( appealAmounts.length ) {
var appealAmountString = appealAmounts.map( donationForm.formatCurrency ).join( ', ');
$('.consider-amounts').html(appealAmountString);
}
Line 929 ⟶ 1,049:
var amount = donationForm.getAmount();
if ( amount === null || isNaN(amount) || amount <= 0 || amount <
$('.amount-options').addClass('lp-haserror');
$('.lp-error-bigamount').hide();
$('.lp-error-smallamount').show();
return false;
} else if ( amount > donationForm.
$('.amount-options').addClass('lp-haserror');
$('.lp-error-bigamount').show();
Line 959 ⟶ 1,078:
var selectedAmount = donationForm.getAmount(),
feeAmount = donationForm.calculateFee( selectedAmount ),
feeText;
$('.ptf label span').text( feeText );
if ( selectedAmount + feeAmount <=
$('.ptf').slideDown();
}
Line 995 ⟶ 1,111:
'UAH' : 10,
'ZAR' : 5,
// Latin America // Updated
'BRL' : 1.75,
'ARS' :
'CLP' :
'COP' :
'MXN' : 6,
'PEN' : 1.
'UYU' :
};
Line 1,058 ⟶ 1,174:
};
}
};
Line 1,098 ⟶ 1,194:
}
return false;
};
Line 1,307 ⟶ 1,378:
var form = document.forms.donateForm;
//
donationForm.minLocal = donationForm.currencyRates[ donationForm.currency ];
donationForm.maxLocal = Math.floor( donationForm.currencyRates[ donationForm.currency
// Overrides for India
if ( donationForm.currency === 'INR' ) {
donationForm.minLocal = 10;
// Until https://phabricator.wikimedia.org/T370583 fixed?
donationForm.maxUSD = 3000;
donationForm.maxLocal = 250000;
}
// Block typing symbols in Other field
Line 1,350 ⟶ 1,427:
$( '.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,395 ⟶ 1,479:
&& mw.util.getParamValue('monthly') !== '0'
&& donationForm.noRecurringCountries.indexOf( donationForm.country ) === -1
&& mw.util.getParamValue('utm_medium') !== 'endowment'
&& mw.util.getParamValue('wmf_medium') !== 'endowment'
) {
$('#frequency_monthly').click();
|