MediaWiki:DonationFormSandbox.js: Difference between revisions
Content deleted Content added
cleaned up amounts layout, use "" in case we do manage to convert to JSON |
No edit summary |
||
Line 7:
donationForm.loadedTime = Date.now();
donationForm.extraData = {};
// Don't offer recurring at all in these countries
donationForm.noRecurringPaypalCountries = [ 'CL', 'CO', 'PE', 'UY', 'BR' ];
donationForm.maxUSD = 25000;
Line 23 ⟶ 18:
donationForm.minimums = {
// From https://github.com/wikimedia/wikimedia-fundraising-SmashPig/blob/master/PaymentData/ReferenceData/CurrencyRates.php
// Updated
'ADF' : 6.
'ADP' : 154,
'AED' : 3.67,
'AFA' :
'AFN' :
'ALL' :
'AMD' :
'ANG' : 1.79,
'AOA' :
'AON' :
'ARS' :
'ATS' : 13,
'AUD' : 1.
'AWG' : 1.79,
'AZM' : 8500,
Line 42 ⟶ 37:
'BAM' : 1.81,
'BBD' : 2,
'BDT' :
'BEF' : 37,
'BGL' : 1.81,
'BGN' : 1.81,
'BHD' : 0.
'BIF' :
'BMD' : 1,
'BND' : 1.
'BOB' : 6.73,
'BRL' :
'BSD' : 1,
'BTN' :
'BWP' :
'BYR' :
'BZD' : 1.97,
'CAD' : 1.
'CDF' :
'CHF' : 0.
'CLP' :
'CNY' :
'COP' :
'CRC' :
'CUC' : 1,
'CUP' : 25,
'CVE' : 102,
'CYP' : 0.
'CZK' :
'DEM' : 1.81,
'DJF' : 178,
'DKK' : 6.
'DOP' : 56,
'DZD' :
'ECS' : 24094,
'EEK' :
'EGP' :
'ESP' : 154,
'ETB' :
'EUR' : 0.
'FIM' : 5.
'FJD' : 2.
'FKP' : 0.
'FRF' : 6.
'GBP' : 0.
'GEL' : 2.
'GHC' :
'GHS' : 12,
'GIP' : 0.
'GMD' :
'GNF' :
'GRD' :
'GTQ' : 7.
'GYD' : 200,
'HKD' : 7.
'HNL' : 24,
'HRK' : 6.
'HTG' :
'HUF' :
'IDR' :
'IEP' : 0.
'ILS' : 3.
'INR' : 10,
'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' : 3.
'LUF' : 37,
'LVL' : 0.
'LYD' : 4.
'MAD' : 10,
'MDL' :
'MGA' :
'MGF' : 9150,
'MKD' : 57,
'MMK' :
'MNT' : 2620,
'MOP' : 8.
'MRO' :
'MTL' : 0.
'MUR' : 43,
'MVR' : 15,
'MWK' :
'MXN' :
'MYR' : 4.
'MZM' : 63200,
'MZN' : 63,
'NAD' :
'NGN' :
'NIO' : 36,
'NLG' : 2.04,
'NOK' :
'NPR' :
'NZD' : 1.
'OMR' : 0.
'PAB' : 1,
'PEN' : 3.
'PGK' : 3.
'PHP' :
'PKR' :
'PLN' : 4.
'PTE' :
'PYG' :
'QAR' : 3.
'ROL' :
'RON' : 4.
'RSD' : 108,
'RUB' :
'RWF' :
'SAR' : 3.75,
'SBD' : 8.
'SCR' : 13,
'SDD' :
'SDG' :
'SDP' : 2261,
'SEK' : 10,
'SGD' : 1.
'SHP' : 0.
'SIT' : 222,
'SKK' : 28,
'SLL' :
'SOS' :
'SRD' :
'SRG' :
'STD' :
'SVC' : 8.75,
'SYP' : 513,
'SZL' :
'THB' :
'TJS' :
'TMM' :
'TMT' : 3.
'TND' : 3.
'TOP' : 2.
'TRL' :
'TRY' :
'TTD' : 6.65,
'TWD' :
'TZS' :
'UAH' : 37,
'UGX' :
'USD' : 1,
'UYU' : 39,
'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' : 250,
'YUN' : 108,
'ZAR' :
'ZMK' : 5176,
'ZWD' : 373
Line 228 ⟶ 223:
minAmount = donationForm.minimums[ currency ],
locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country );
// Round up
minAmount = Math.ceil( minAmount * 100 ) / 100;
Line 274 ⟶ 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 ] ],
Line 283 ⟶ 278:
[ 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 ] ],
Line 291 ⟶ 287:
[ 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 426 ⟶ 352:
[ 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 ] ]
],
"
[ 0, [
[ 5, [
[ 10, [ 5, 10,
[ 15, [
[ 20, [ 15, 20,
[ 25, [
[
[
[ 1000, [ 500, 750, 1000, 2500, 5000, 7500, 10000 ] ],
[ 3000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ]
]
},
Line 456 ⟶ 419:
],
"SEK" : [
[ 0, [
[
[ 200, [ 50, 100, 200, 300, 500, 750, 1000 ] ]
]
Line 464 ⟶ 426:
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 530 ⟶ 492:
};
var format;
if ( formats[currency] ) {
} else {
}
Line 645 ⟶ 608:
'PT' : 'vmaj',
'SK' : 'vmaj',
'GR' : 'vma',
// Others
'CZ' : 'vmad',
Line 693 ⟶ 657:
var params = {};
params.currency = donationForm.currency;
params.country = donationForm.country;
Line 707 ⟶ 671:
params.payment_method = paymentMethod;
}
if ( params.payment_method === 'cc' && params.country === 'ZA' ) {
params.gateway = 'astropay';
Line 763 ⟶ 727:
}
//
if ( mc ) { // check just in-case this wasn't loaded for some reason
mc.main( params, donationForm.finalStep );
} else {
Line 788 ⟶ 752:
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 793 ⟶ 762:
// Tracking data
params.
params.
params.
params.
if ( document.referrer ) { // TODO: do we need this?
// Strip protocol to stop firewall complaining
Line 813 ⟶ 782:
/**
* 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 842 ⟶ 812:
/* 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 877 ⟶ 847:
/* Return amount selected or input */
donationForm.getAmount = function() {
var form = document.forms
amount = null;
donationForm.extraData.otherAmt = 0;
Line 930 ⟶ 900:
var error = false;
var form = document.forms
// Reset all errors
Line 1,025 ⟶ 995:
'UAH' : 10,
'ZAR' : 5,
// Latin America // Updated 2023-01-17 to approx 0.35 USD equivalent
'BRL' :
'ARS' : 32,
'CLP' :
'COP' :
'MXN' :
'PEN' : 1.3,
'UYU' :
};
Line 1,132 ⟶ 1,102:
/**
* 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
Line 1,153 ⟶ 1,123:
}
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,162 ⟶ 1,305:
mw.loader.using( ['mediawiki.util'] ).done( function() {
var form = document.forms
// These get used in quite a few places
Line 1,202 ⟶ 1,345:
$('#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,210 ⟶ 1,366:
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,228 ⟶ 1,391:
// Allow preselecting monthly
if (
mw.util.getParamValue('monthly') && mw.util.getParamValue('monthly') !== '0'
&& donationForm.noRecurringCountries.indexOf( donationForm.country ) === -1
) {
$('#frequency_monthly').click();
}
Line 1,241 ⟶ 1,407:
}
finally {
$('.frb-monthly-pitch, .frb-monthly-pitch-thanks').appendTo('.frequency-options');
$('.ptf').appendTo('.amount-options');
$('.optin-options').insertAfter('.amount-options');
|