MediaWiki:DonationForm T201415.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
clean trailing spaces |
No edit summary |
||
Line 685: | Line 685: | ||
if ( donationForm.validate( skipAmountValidation ) ) { |
if ( donationForm.validate( skipAmountValidation ) ) { |
||
var |
var uri = new mw.Uri('https://payments.wikimedia.org/index.php/Special:GatewayFormChooser'); |
||
var params = {}; |
|||
form.action = paymentsURL; |
|||
if (typeof paymentSubMethod == 'undefined') { |
if (typeof paymentSubMethod == 'undefined') { |
||
Line 696: | Line 695: | ||
if ( paymentMethod === 'cc-adyen' ) { |
if ( paymentMethod === 'cc-adyen' ) { |
||
paymentMethod = 'cc'; |
paymentMethod = 'cc'; |
||
params.payment_method = 'cc'; |
|||
params.gateway = 'adyen'; |
|||
params.ffname = 'adyen'; |
|||
} |
} |
||
Line 704: | Line 703: | ||
if ( paymentMethod === 'cc-dlocal' ) { |
if ( paymentMethod === 'cc-dlocal' ) { |
||
paymentMethod = 'cc'; |
paymentMethod = 'cc'; |
||
params.payment_method = 'cc'; |
|||
params.gateway = 'astropay'; |
|||
} |
} |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
frequency = 'onetime'; |
frequency = 'onetime'; |
||
params.recurring = 'false'; |
|||
} else { |
} else { |
||
params.recurring = 'true'; |
|||
} |
} |
||
params.payment_method = paymentMethod; |
|||
⚫ | |||
var full_dotted_payment_method = paymentMethod; |
|||
⚫ | |||
full_dotted_payment_method = 'r' + full_dotted_payment_method; |
|||
⚫ | |||
if ( paymentSubMethod ) { |
if ( paymentSubMethod ) { |
||
params.payment_submethod = paymentSubMethod; |
|||
} |
} |
||
var amount = donationForm.getAmount(); |
|||
// PTF - TODO: clean up form so we only use 'amount' and not 'amountGiven' |
|||
if ( $('#ptf-checkbox').prop('checked') ) { |
if ( $('#ptf-checkbox').prop('checked') ) { |
||
amount = amount + donationForm.calculateFee( amount ); |
|||
document.getElementById('input_amount_other').checked = true; |
|||
form.amountGiven.value = amount1 + donationForm.calculateFee( amount1 ); |
|||
donationForm.extraData.ptf = 1; |
donationForm.extraData.ptf = 1; |
||
⚫ | |||
params.amount = amount; |
|||
/* Email optin */ |
|||
if ( $('input[name="opt_in"]').length > 0 ) { |
|||
var opt_inValue = $('input[name="opt_in"]:checked').val(); |
|||
params.opt_in = opt_inValue; // donationForm.validate() already checked it's 1 or 0 |
|||
} |
} |
||
donationForm.extraData.time = Math.round( (Date.now() - donationForm.loadedTime)/1000 ); |
donationForm.extraData.time = Math.round( (Date.now() - donationForm.loadedTime)/1000 ); |
||
params.utm_medium = mw.util.getParamValue( 'utm_medium' ); |
|||
params.utm_campaign = mw.util.getParamValue( 'utm_campaign' ); |
|||
params.utm_source = donationForm.buildUtmSource( params ); |
|||
params.utm_key = donationForm.buildUtmKey( donationForm.extraData ); |
|||
⚫ | |||
// TODO: do we need this? |
|||
⚫ | |||
uri.extend( params ); |
|||
donationForm.goToPayments( uri ); |
|||
} else { |
} else { |
||
Line 750: | Line 758: | ||
return false; // don't submit if called by a button |
return false; // don't submit if called by a button |
||
}; |
|||
donationForm.goToPayments = function( uri ) { |
|||
if ( window.top !== window.self ) { |
|||
// In a frame, open payments in a new tab |
|||
window.open( uri.toString() ); |
|||
} else { |
|||
window.location.href = uri.toString(); |
|||
} |
|||
}; |
}; |
||
Line 755: | Line 773: | ||
* Build a utm_source value, including the landing page info. |
* Build a utm_source value, including the landing page info. |
||
* |
* |
||
* Own function so it can be overriden for weird tests |
|||
* Note this doesn't include payment method, that's added in redirectPayment method |
|||
* |
* |
||
* @param {Object} params |
|||
* @return {string} utm_source |
* @return {string} utm_source |
||
*/ |
*/ |
||
donationForm.buildUtmSource = function() { |
donationForm.buildUtmSource = function( params ) { |
||
var utm_source = mw.util.getParamValue( 'utm_source' ) + '.'; |
var utm_source = mw.util.getParamValue( 'utm_source' ) + '.'; |
||
var fullDottedPaymentMethod = params.payment_method; |
|||
⚫ | |||
fullDottedPaymentMethod = 'r' + fullDottedPaymentMethod; |
|||
} |
|||
⚫ | |||
fullDottedPaymentMethod = fullDottedPaymentMethod + '.' + params.payment_submethod; |
|||
} |
|||
/* Get URL parameter, but remove parts using old format. Allow fallback to a default value */ |
/* Get URL parameter, but remove parts using old format. Allow fallback to a default value */ |
||
Line 1,029: | Line 1,056: | ||
if ( form ) { |
if ( form ) { |
||
form.utm_medium.value = mw.util.getParamValue( 'utm_medium' ); |
|||
form.utm_campaign.value = mw.util.getParamValue( 'utm_campaign' ); |
|||
form.utm_key.value = mw.util.getParamValue( 'utm_key' ); |
|||
⚫ | |||
⚫ | |||
// hide frequency options for some countries |
// hide frequency options for some countries |
||
Line 1,063: | Line 1,084: | ||
&& donationForm.noRecurringCountries.indexOf( form.country.value ) === -1 ) { |
&& donationForm.noRecurringCountries.indexOf( form.country.value ) === -1 ) { |
||
$('#frequency_monthly').click(); |
$('#frequency_monthly').click(); |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
} |
||