MediaWiki:DonationForm T201415.js: Difference between revisions

Content deleted Content added
clean trailing spaces
No edit summary
Line 685:
if ( donationForm.validate( skipAmountValidation ) ) {
 
var paymentsURLuri = new mw.Uri('https://payments.wikimedia.org/index.php/Special:GatewayFormChooser');
var params = {};
 
form.action = paymentsURL;
 
if (typeof paymentSubMethod == 'undefined') {
Line 696 ⟶ 695:
if ( paymentMethod === 'cc-adyen' ) {
paymentMethod = 'cc';
formparams.payment_method.value = 'cc';
formparams.gateway.value = 'adyen';
formparams.ffname.value = 'adyen';
}
 
Line 704 ⟶ 703:
if ( paymentMethod === 'cc-dlocal' ) {
paymentMethod = 'cc';
formparams.payment_method.value = 'cc';
formparams.gateway.value = 'astropay';
}
 
// Default to variant = panExplain for India
var frequency = $("input[name='frequency']:checked").val();
// TODO: make this default payments side - https://phabricator.wikimedia.org/T259146
if( frequency !== 'monthly' ){
if ( formmw.countryutil.valuegetParamValue('country') === 'IN' ) {
formparams.variant.value = 'panExplain';
}
 
var frequency = $("'input[name='"frequency'"]:checked"').val();
if ( frequency !== 'monthly' ) {
frequency = 'onetime';
formparams.recurring.value = 'false';
} else {
formparams.recurring.value = 'true';
}
 
formparams.payment_method.value = paymentMethod;
form.payment_submethod.value = paymentSubMethod;
 
var full_dotted_payment_method = paymentMethod;
if ( form.recurring.value == 'true' ) {
full_dotted_payment_method = 'r' + full_dotted_payment_method;
}
if ( paymentSubMethod ) {
full_dotted_payment_methodparams.payment_submethod = form.payment_method.value + '.' + paymentSubMethod;
}
 
var amount = donationForm.getAmount();
// PTF - TODO: clean up form so we only use 'amount' and not 'amountGiven'
if ( $('#ptf-checkbox').prop('checked') ) {
var amount1amount = amount + donationForm.getAmountcalculateFee( amount );
document.getElementById('input_amount_other').checked = true;
form.amountGiven.value = amount1 + donationForm.calculateFee( amount1 );
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 );
 
formparams.utm_medium.value = mw.util.getParamValue( 'utm_medium' );
formparams.utm_campaign.value = mw.util.getParamValue( 'utm_campaign' );
formparams.utm_source.value = donationForm.buildUtmSource() +params '.' + full_dotted_payment_method);
formparams.utm_key.value = donationForm.buildUtmKey( donationForm.extraData );
 
// Strip protocol to stop firewall throwing fitscomplaining
// TODO: do we need this?
formparams.referrer.value = document.referrer.replace(/https?:\/\//i, "");
 
formuri.methodextend( =params 'GET');
formdonationForm.submitgoToPayments( uri );
 
} else {
Line 750 ⟶ 758:
 
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 ⟶ 773:
* 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
*/
donationForm.buildUtmSource = function( params ) {
 
var utm_source = mw.util.getParamValue( 'utm_source' ) + '.';
 
var fullDottedPaymentMethod = params.payment_method;
if ( formparams.recurring.value == 'true' ) {
fullDottedPaymentMethod = 'r' + fullDottedPaymentMethod;
}
if ( formparams.payment_submethod.value =) paymentSubMethod;{
fullDottedPaymentMethod = fullDottedPaymentMethod + '.' + params.payment_submethod;
}
 
/* Get URL parameter, but remove parts using old format. Allow fallback to a default value */
Line 1,029 ⟶ 1,056:
 
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' );
 
// Strip protocol to stop firewall throwing fits
form.referrer.value = document.referrer.replace(/https?:\/\//i, "");
 
// hide frequency options for some countries
Line 1,063 ⟶ 1,084:
&& donationForm.noRecurringCountries.indexOf( form.country.value ) === -1 ) {
$('#frequency_monthly').click();
}
 
// Default to variant = panExplain for India
// https://phabricator.wikimedia.org/T259146
if ( form.country.value === 'IN' ) {
form.variant.value = 'panExplain';
}