MediaWiki:DonationForm.js: Difference between revisions
Content deleted Content added
update LatAm feeMinimums |
simplify locale code: just define donationForm.locale on load and use that as default for formatAmount |
||
(17 intermediate revisions by 2 users not shown) | |||
Line 7:
donationForm.loadedTime = Date.now();
donationForm.extraData = {};
// Don't offer recurring at all in these countries
donationForm.noRecurringCountries = [ 'AR'
donationForm.
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 192 ⟶ 185:
'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
Line 225 ⟶ 218:
/* 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 245 ⟶ 233:
$('.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 274 ⟶ 262:
// 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 ] ],
Line 292 ⟶ 280:
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
"
[ 0, [
[
[
[
[
[
[
[
[
[
[
[
[
[
[
],
"
[ 0, [
[
[
[
[
[
[
[
[
[
[
[
[
[
],
"
[ 0, [ 2.75, 5, 10, 20, 25, 35,
[ 5, [ 2.75, 5, 10,
[ 10, [
[ 15, [
[ 20, [ 15, 20, 25, 35, 50, 75, 100
[ 25, [
[ 35, [
[
[
[
[
[
[
[ 1000, [ 500, 750, 1000, 2500, 5000, 7500, 10000 ] ],
[ 3000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ]
],
"midtier2018" : [
Line 427 ⟶ 345:
[ 500, [ 750, 1000, 1500, 2500, 5000, 7500, 10000 ] ],
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ]
]
},
"EUR" : {
"default" : [ // 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 ] ]
],
"FY2425_E1_T14_GB" : [
[ 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, [ 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_GB" : [
[ 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 ] ],
[ 50, [ 35, 50, 75, 100, 200, 300, 500 ] ],
[ 75, [ 50, 75, 100, 200, 300, 500, 750 ] ],
[ 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 ] ]
]
},
Line 449 ⟶ 419:
radioAmountsData.AUD = radioAmountsData.USD;
radioAmountsData.CAD = radioAmountsData.USD;
radioAmountsData.NZD = radioAmountsData.USD;
radioAmountsData.GBP = radioAmountsData.EUR;
var appealAmountsData = {
"USD" : [ // also used for CAD, AUD, NZD, GBP, EUR
Line 680 ⟶ 650:
var params = {};
params.currency = donationForm.currency;
params.country = donationForm.country;
Line 694 ⟶ 664:
params.payment_method = paymentMethod;
}
if ( params.payment_method === 'cc' && params.country === 'ZA' ) {
params.gateway = 'astropay';
Line 776 ⟶ 746:
uri = new mw.Uri('https://payments.wikimedia.org/index.php/Special:AdyenCheckoutGateway');
}
// Skip form chooser for Venmo
if ( params.payment_method === 'venmo' ) {
Line 785 ⟶ 755:
// Tracking data
params.
params.
params.
params.
if ( document.referrer ) { // TODO: do we need this?
// Strip protocol to stop firewall complaining
Line 805 ⟶ 775:
/**
* Build a
*
* Own function so it can be overriden for weird tests
*
* @param {Object} params
* @return {string}
*/
donationForm.
var
wmf_source += '.';
var fullDottedPaymentMethod = params.payment_method;
Line 834 ⟶ 805:
/* The landing page info, separated by ~. This mostly exists for legacy reasons */
return
};
/**
* Build a string for
*
* @param {Object} data
* @return {string}
*/
donationForm.
var
dataArray = [];
if (
dataArray.push(
}
for (var key in data) {
Line 951 ⟶ 922:
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 981 ⟶ 951:
var selectedAmount = donationForm.getAmount(),
feeAmount = donationForm.calculateFee( selectedAmount ),
feeText;
$('.ptf label span').text( feeText );
if ( selectedAmount + feeAmount <=
$('.ptf').slideDown();
}
Line 1,123 ⟶ 1,090:
/**
* Format an amount for a given locale (default to donationForm.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=donationForm.locale] To determine correct separators
* @return {string}
*/
donationForm.formatAmount = function( amount, locale = donationForm.locale ) {
var formatterOptions, output;
if ( amount % 1 !== 0 ) { // Not a whole number
Line 1,336 ⟶ 1,303:
}
donationForm.country = mw.util.getParamValue('country').toUpperCase();
donationForm.locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country );
// 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.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,367 ⟶ 1,349:
$('#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' );
}
Line 1,372 ⟶ 1,358:
// Only show Amazon for links from Ways to give
// TODO: remove utm_source when Ways to give has been updated
if (
mw.util.getParamValue( '
mw.util.getParamValue( 'wmf_source' ) === 'Ways_to_Give'
) {
}
Line 1,385 ⟶ 1,372:
}
}
// Venmo browser check
if ( $('.paymentmethod-venmo').length > 0 ) {
Line 1,408 ⟶ 1,395:
// Allow preselecting monthly
if (
mw.util.getParamValue('monthly') && mw.util.getParamValue('monthly') !== '0'
&& donationForm.noRecurringCountries.indexOf( donationForm.country ) === -1
) {
$('#frequency_monthly').click();
}
Line 1,421 ⟶ 1,411:
}
finally {
$('.frb-monthly-pitch, .frb-monthly-pitch-thanks').appendTo('.frequency-options');
$('.ptf').appendTo('.amount-options');
$('.optin-options').insertAfter('.amount-options');
|