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 paymentsURL = 'https://payments.wikimedia.org/index.php/Special:GatewayFormChooser';
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';
form.payment_method.value = 'cc';
params.payment_method = 'cc';
form.gateway.value = 'adyen';
params.gateway = 'adyen';
form.ffname.value = 'adyen';
params.ffname = 'adyen';
}
}


Line 704: Line 703:
if ( paymentMethod === 'cc-dlocal' ) {
if ( paymentMethod === 'cc-dlocal' ) {
paymentMethod = 'cc';
paymentMethod = 'cc';
form.payment_method.value = 'cc';
params.payment_method = 'cc';
form.gateway.value = 'astropay';
params.gateway = '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 ( mw.util.getParamValue('country') === 'IN' ) {
params.variant = 'panExplain';
}

var frequency = $('input[name="frequency"]:checked').val();
if ( frequency !== 'monthly' ) {
frequency = 'onetime';
frequency = 'onetime';
form.recurring.value = 'false';
params.recurring = 'false';
} else {
} else {
form.recurring.value = 'true';
params.recurring = 'true';
}
}


form.payment_method.value = paymentMethod;
params.payment_method = 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 ) {
if ( paymentSubMethod ) {
full_dotted_payment_method = form.payment_method.value + '.' + 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') ) {
var amount1 = donationForm.getAmount();
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 );


form.utm_medium.value = mw.util.getParamValue( 'utm_medium' );
params.utm_medium = mw.util.getParamValue( 'utm_medium' );
form.utm_campaign.value = mw.util.getParamValue( 'utm_campaign' );
params.utm_campaign = mw.util.getParamValue( 'utm_campaign' );
form.utm_source.value = donationForm.buildUtmSource() + '.' + full_dotted_payment_method;
params.utm_source = donationForm.buildUtmSource( params );
form.utm_key.value = donationForm.buildUtmKey( donationForm.extraData );
params.utm_key = donationForm.buildUtmKey( donationForm.extraData );

// Strip protocol to stop firewall complaining
// TODO: do we need this?
params.referrer = document.referrer.replace(/https?:\/\//i, "");


form.method = 'GET';
uri.extend( params );
form.submit();
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;
if ( params.recurring ) {
fullDottedPaymentMethod = 'r' + fullDottedPaymentMethod;
}
if ( params.payment_submethod ) {
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' );

// Strip protocol to stop firewall throwing fits
form.referrer.value = document.referrer.replace(/https?:\/\//i, "");


// 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();
}

// Default to variant = panExplain for India
// https://phabricator.wikimedia.org/T259146
if ( form.country.value === 'IN' ) {
form.variant.value = 'panExplain';
}
}