MediaWiki:DonationForm.js: Difference between revisions
Content deleted Content added
re-add Amex in Japan Tag: Reverted |
m Reverted edit by PPenloglou-WMF (talk) to last revision by Pcoombe Tag: Rollback |
||
(95 intermediate revisions by 2 users not shown) | |||
Line 7:
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
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' :
'ADP' :
'AED' : 3.67,
'AFA' :
'AFN' :
'ALL' :
'AMD' :
'ANG' : 1.79,
'AOA' :
'AON' :
'ARS' :
'ATS' :
'AUD' : 1.
'AWG' : 1.79,
'AZM' : 8500,
'AZN' : 1.7,
'BAM' : 1.
'BBD' : 2,
'BDT' :
'BEF' :
'BGL' : 1.
'BGN' : 1.
'BHD' : 0.
'BIF' :
'BMD' : 1,
'BND' : 1.
'BOB' : 6.
'BRL' : 5.
'BSD' : 1,
'BTN' :
'BWP' :
'BYR' :
'BZD' : 1.
'CAD' : 1.
'CDF' :
'CHF' : 0.
'CLP' :
'CNY' :
'COP' :
'CRC' :
'CUC' : 1,
'CUP' : 25,
'CVE' :
'CYP' : 0.
'CZK' :
'DEM' : 1.
'DJF' : 178,
'DKK' : 6.
'DOP' :
'DZD' : 133,
'ECS' : 24094,
'EEK' :
'EGP' :
'ESP' :
'ETB' :
'EUR' : 0.
'FIM' :
'FJD' : 2.
'FKP' : 0.
'FRF' :
'GBP' : 0.
'GEL' :
'GHC' :
'GHS' :
'GIP' : 0.
'GMD' :
'GNF' :
'GRD' :
'GTQ' : 7.
'GYD' :
'HKD' : 7.
'HNL' : 24,
'HRK' : 6.
'HTG' :
'HUF' :
'IDR' :
'IEP' : 0.
'ILS' : 3.
'INR' :
'IQD' :
'IRR' :
'ISK' :
'ITL' :
'JMD' :
'JOD' : 0.70900000000001,
'JPY' :
'KES' :
'KGS' :
'KHR' :
'KMF' :
'KPW' : 135,
'KRW' :
'KWD' : 0.
'KYD' : 0.83333299999999,
'KZT' :
'LAK' :
'LBP' :
'LKR' :
'LRD' :
'LSL' :
'LTL' :
'LUF' :
'LVL' : 0.
'LYD' : 4.
'MAD' :
'MDL' : 17,
'MGA' :
'MGF' : 9150,
'MKD' :
'MMK' :
'MNT' : 2620,
'MOP' :
'MRO' :
'MTL' : 0.
'MUR' :
'MVR' : 15,
'MWK' :
'MXN' :
'MYR' : 4.
'MZM' :
'MZN' :
'NAD' :
'NGN' :
'NIO' :
'NLG' :
'NOK' :
'NPR' :
'NZD' : 1.
'OMR' : 0.
'PAB' : 1,
'PEN' : 3.
'PGK' : 3.
'PHP' :
'PKR' :
'PLN' : 3.
'PTE' :
'PYG' :
'QAR' : 3.
'ROL' :
'RON' : 4.
'RSD' :
'RUB' :
'RWF' :
'SAR' : 3.75,
'SBD' :
'SCR' :
'SDD' :
'SDG' :
'SDP' : 2261,
'SEK' :
'SGD' : 1.
'SHP' : 0.
'SIT' :
'SKK' :
'SLL' :
'SOS' :
'SRD' :
'SRG' :
'STD' :
'SVC' : 8.75,
'SYP' : 513,
'SZL' :
'THB' :
'TJS' : 11,
'TMM' :
'TMT' : 3.35,
'TND' :
'TOP' : 2.
'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' :
'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',
});
Line 243 ⟶ 309:
$('.lp-error-bigamount').text( function( index, oldText ) {
return oldText.replace( '$1',
.replace( '$2', currency )
.replace( '$3', 'benefactors@wikimedia.org' )
.replace( '$4', donationForm.formatAmount( donationForm.maxUSD ) );
});
};
Line 256 ⟶ 322:
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
var radioAmountsData = {
[ 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 ] ],
[
[
[
[
[
[
[
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
[ 0, [
[
[
[
[
[
[
[
[
[
[
[
[
[
[
],
[ 0, [
[
[
[
[
[
[
[
[
[
[
[
[
[
],
[ 0, [
[ 5, [ 2.75, 5, 10,
[ 10, [
[ 15, [ 10, 15, 20, 25, 35, 50,
[ 20, [ 15, 20, 25, 35, 50,
[ 25, [
[ 35, [
[ 75, [
[ 100, [ 75, 100, 150, 250, 500, 750, 1000
[ 150, [
[ 200, [ 150, 200, 300, 500, 750, 1000,
[ 500, [ 200, 300, 500, 750, 1000, 2500,
[ 1000, [
[ 3000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ]
],
"directmail" : [
[
],
[ 0, [
]
},
"EUR" : {
"default"
[
[
[
[
[
[
[
[
[ 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 ] ]
],
[ 0, [
[ 5, [ 5, 10, 15, 20, 35, 50,
[ 10, [ 10,
[ 15, [ 15, 20, 25, 35, 50, 75,
[ 20, [ 20,
[ 25, [ 25,
[ 35, [
[
[
[
[
[
[
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ],
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
[ 0, [
[ 5, [ 2.50, 5, 10, 20,
[ 10, [ 2.50, 10, 15, 20,
[ 15, [
[ 20, [ 3.50,
[ 25, [ 4.25,
[ 35, [ 6.25,
[
[
[
[
[
[ 1000, [ 250, 500,
[
],
[ 0, [ 2.50, 5, 10, 20
[ 5, [ 2.50,
[ 10, [
[ 15, [
[ 20, [
[ 25, [
[ 35, [ 25,
[ 75, [
[ 100, [
[ 150, [
[ 200, [
[ 500, [
[ 1000, [ 500,
[ 3000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ]
]
},
"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 ] ],
Line 453 ⟶ 565:
[ 10000, [ 10000, 25000, 50000, 75000, 100000, 150000, 200000 ] ]
],
[ 0, [
[
[ 200, [ 50, 100, 200, 300, 500, 750, 1000 ] ]
]
Line 462 ⟶ 573:
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 = {
[ 0, [ 5, 10, 20 ] ],
[ 10, [ 10, 20, 50 ] ],
Line 478 ⟶ 594:
[ 200, [ 100, 200, 300 ] ]
],
[ 0, [ 300, 500, 1000 ] ],
[ 3, [ 500, 1000, 1500 ] ],
Line 487 ⟶ 603:
[ 100, [ 5000, 10000, 15000 ] ]
],
[ 0, [ 20, 50, 100 ] ],
[ 3, [ 30, 50, 100 ] ],
Line 503 ⟶ 619:
appealAmountsData.NZD = appealAmountsData.USD;
appealAmountsData.EUR = appealAmountsData.USD;
// Radio button amounts
Line 538 ⟶ 628:
var $label = $("label[for='input_amount_" + j + "']");
$radio.val( radioAmounts[j] );
$label.text(
}
}
Line 545 ⟶ 635:
var appealAmounts = pickAmountArray( appealAmountsData, currency, hpc, hpcSet );
if ( appealAmounts.length ) {
var appealAmountString = appealAmounts.map( donationForm.formatCurrency ).join( ', ');
$('.consider-amounts').html(appealAmountString);
}
Line 600 ⟶ 684:
/* 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 639 ⟶ 723:
'PT' : 'vmaj',
'SK' : 'vmaj',
'GR' : 'vma',
// Others
'CZ' : 'vmad',
'DK' : 'vma',
'HU' : 'vma',
Line 650 ⟶ 736:
'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 684 ⟶ 772:
var params = {};
params.currency = donationForm.currency;
params.country = donationForm.country;
// Overrides for specific cc gateways
Line 689 ⟶ 780:
params.payment_method = 'cc';
params.gateway = 'adyen';
} else if ( paymentMethod === 'cc-dlocal' ) {
params.payment_method = 'cc';
Line 695 ⟶ 785:
} else {
params.payment_method = paymentMethod;
}
if ( params.payment_method === 'cc' && params.country === 'ZA' ) {
params.gateway = 'astropay';
}
Line 708 ⟶ 802:
}
params.uselang = mw.config.get('wgPageContentLanguage'); // see T281285 for why not wgUserLanguage
Line 735 ⟶ 827:
var opt_inValue = $('input[name="opt_in"]:checked').val();
params.opt_in = opt_inValue; // donationForm.validate() already checked it's 1 or 0
}
Line 746 ⟶ 832:
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' );
}
//
if ( mc ) { // check just in-case this wasn't loaded for some reason
mc.main( params, donationForm.finalStep );
} else {
Line 770 ⟶ 862:
donationForm.finalStep = function( params ) {
var uri = new mw.Uri('https://payments.wikimedia.org/index.php/Special:
// 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.
params.
params.
params.
if ( document.referrer ) { // TODO: do we need this?
// Strip protocol to stop firewall complaining
Line 795 ⟶ 897:
/**
* 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 824 ⟶ 927:
/* 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 859 ⟶ 962:
/* Return amount selected or input */
donationForm.getAmount = function() {
var form = document.forms
amount = null;
donationForm.extraData.otherAmt = 0;
Line 912 ⟶ 1,015:
var error = false;
var form = document.forms
// Reset all errors
Line 941 ⟶ 1,044:
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 971 ⟶ 1,073:
var selectedAmount = donationForm.getAmount(),
feeAmount = donationForm.calculateFee( selectedAmount ),
feeText;
$('.ptf label span').text( feeText );
if ( selectedAmount + feeAmount <=
$('.ptf').slideDown();
}
Line 1,000 ⟶ 1,096:
'HUF' : 100,
'ILS' : 1.2,
'INR' :
'JPY' : 35,
'MYR' : 1,
'NOK' : 3,
'PLN' : 1.35,
'CZK' : 7.5,
'RON' : 1.5,
'SEK' : 3,
'UAH' : 10,
'ZAR' : 5,
// Latin America // Updated 2024-08-22 to approx 0.35 USD equivalent
'BRL' :
'ARS' :
'CLP' :
'COP' :
'MXN' :
'PEN' : 1.
'UYU' :
};
Line 1,075 ⟶ 1,172:
/**
* 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 {
*/
donationForm.
if (
}
if (
if ( ApplePaySession.canMakePayments() ) {
return true;
}
return
};
/*
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,103 ⟶ 1,371:
mw.loader.using( ['mediawiki.util'] ).done( function() {
var form = document.forms
//
donationForm.
donationForm.
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,140 ⟶ 1,418:
$('.frequency-options, #cancel-monthly, #donate-recurring-smallprint').hide();
}
if ( donationForm.noRecurringPaypalCountries.indexOf( donationForm.country ) !== -1 ) {
$( '.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' ||
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,158 ⟶ 1,470:
// Allow preselecting monthly
if (
mw.util.getParamValue('monthly') && 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();
}
Line 1,171 ⟶ 1,488:
}
finally {
$('.frb-monthly-pitch, .frb-monthly-pitch-thanks').appendTo('.frequency-options');
$('.ptf').appendTo('.amount-options');
$('.optin-options').insertAfter('.amount-options');
|