Ejegg has uploaded a new change for review.
https://gerrit.wikimedia.org/r/284366
Change subject: Account for gateway-specific min/max client-side
......................................................................
Account for gateway-specific min/max client-side
After letting this settle a bit, please remove the global
window.wgCurrencyMinimums and use the currency rates from config.
Bug: T132959
Change-Id: I2239d6d1abf2db21c968817412839bf9eea5a18d
---
M amazon_gateway/amazon.adapter.php
M amazon_gateway/amazon_gateway.body.php
M gateway_common/GatewayPage.php
M gateway_common/gateway.adapter.php
M modules/CurrencyRatesModule.php
M modules/validate_input.js
M worldpay_gateway/worldpay.adapter.php
M worldpay_gateway/worldpay_gateway.body.php
8 files changed, 29 insertions(+), 8 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface
refs/changes/66/284366/1
diff --git a/amazon_gateway/amazon.adapter.php
b/amazon_gateway/amazon.adapter.php
index 2a37854..349a080 100644
--- a/amazon_gateway/amazon.adapter.php
+++ b/amazon_gateway/amazon.adapter.php
@@ -423,6 +423,7 @@
* @param array $vars
*/
public function setClientVariables( &$vars ) {
+ parent::setClientVariables( $vars );
$vars['wgAmazonGatewayClientID'] =
$this->account_config['ClientID'];
$vars['wgAmazonGatewaySellerID'] =
$this->account_config['SellerID'];
$vars['wgAmazonGatewaySandbox'] = $this->getGlobal( 'TestMode'
) ? true : false;
diff --git a/amazon_gateway/amazon_gateway.body.php
b/amazon_gateway/amazon_gateway.body.php
index 75f60ed..c40a75c 100644
--- a/amazon_gateway/amazon_gateway.body.php
+++ b/amazon_gateway/amazon_gateway.body.php
@@ -24,7 +24,6 @@
* Show the special page
*/
protected function handleRequest() {
- Hooks::register( 'MakeGlobalVariablesScript', array(
$this->adapter, 'setClientVariables' ) );
$this->getOutput()->addModules(
'ext.donationinterface.amazon.styles' );
$this->getOutput()->addModules(
'ext.donationinterface.amazon.scripts' );
diff --git a/gateway_common/GatewayPage.php b/gateway_common/GatewayPage.php
index d49f143..8461312 100644
--- a/gateway_common/GatewayPage.php
+++ b/gateway_common/GatewayPage.php
@@ -90,6 +90,8 @@
public function execute( $par ) {
global $wgContributionTrackingFundraiserMaintenance,
$wgContributionTrackingFundraiserMaintenanceUnsched;
+ Hooks::register( 'MakeGlobalVariablesScript', array(
$this->adapter, 'setClientVariables' ) );
+
// FIXME: Deprecate "language" param.
$language = $this->getRequest()->getVal( 'language' );
if ( $language ) {
diff --git a/gateway_common/gateway.adapter.php
b/gateway_common/gateway.adapter.php
index a389f55..609d7ef 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -3662,4 +3662,13 @@
}
return $hookResult;
}
+
+ /**
+ * MakeGlobalVariablesScript handler, sends settings to Javascript
+ * @param array $vars
+ */
+ public function setClientVariables( &$vars ) {
+ $vars['wgDonationInterfacePriceFloor'] = $this->getGlobal(
'PriceFloor' );
+ $vars['wgDonationInterfacePriceCeiling'] = $this->getGlobal(
'PriceCeiling' );
+ }
}
diff --git a/modules/CurrencyRatesModule.php b/modules/CurrencyRatesModule.php
index e9648ec..b0afa22 100644
--- a/modules/CurrencyRatesModule.php
+++ b/modules/CurrencyRatesModule.php
@@ -9,8 +9,10 @@
* @see ResourceLoaderModule::getScript()
*/
public function getScript( ResourceLoaderContext $context ) {
+ // FIXME: get rid of global var
return 'window.wgCurrencyMinimums = ' .
- Xml::encodeJsVar( CurrencyRates::getCurrencyRates() ) .
';';
+ Xml::encodeJsVar( CurrencyRates::getCurrencyRates() ) .
';' .
+ 'mw.config.set( "wgDonationInterfaceCurrencyRates",
window.wgCurrencyMinimums );';
}
/**
diff --git a/modules/validate_input.js b/modules/validate_input.js
index 2aedfcd..ae282e6 100644
--- a/modules/validate_input.js
+++ b/modules/validate_input.js
@@ -38,11 +38,14 @@
/**
* Validate the donation amount to make sure it is formatted correctly and at
least a minimum amount.
+ * TODO: also validate ceiling
*/
window.validateAmount = function () {
var error = true,
amount = $( 'input[name="amount"]' ).val(), // get the amount
- currency_code = '';
+ currency_code = '',
+ rate,
+ minUsd = mw.config.get( 'wgDonationInterfacePriceFloor' );
// Normalize weird amount formats.
// Don't mess with these unless you know what you're doing.
@@ -64,11 +67,14 @@
if ( $( 'select[name="currency_code"]' ).length ) {
currency_code = $( 'select[name="currency_code"]' ).val();
}
+ // FIXME: replace with mw.config.get(
"wgDonationInterfaceCurrencyRates" )
if ( ( typeof wgCurrencyMinimums[ currency_code ] ) === 'undefined' ) {
- wgCurrencyMinimums[ currency_code ] = 1;
+ rate = 1;
+ } else {
+ rate = wgCurrencyMinimums[ currency_code ];
}
- if ( amount < wgCurrencyMinimums[ currency_code ] || error ) {
- alert( mediaWiki.msg( 'donate_interface-smallamount-error'
).replace( '$1', wgCurrencyMinimums[ currency_code ] + ' ' + currency_code ) );
+ if ( ( amount < minUsd * rate ) || error ) {
+ alert( mediaWiki.msg( 'donate_interface-smallamount-error'
).replace( '$1', minUsd * rate + ' ' + currency_code ) );
error = true;
// See if we're on a webitects accordian form
if ( $( '#step1wrapper' ).length ) {
diff --git a/worldpay_gateway/worldpay.adapter.php
b/worldpay_gateway/worldpay.adapter.php
index 849728f..6bdcfa3 100644
--- a/worldpay_gateway/worldpay.adapter.php
+++ b/worldpay_gateway/worldpay.adapter.php
@@ -689,7 +689,10 @@
}
public function setClientVariables( &$vars ) {
- $vars['wgWorldpayGatewayTokenTimeout'] = $this->getGlobal(
'TokenTimeout' );
+ parent::setClientVariables( $vars );
+ if ( $this->isESOP() ) {
+ $vars['wgWorldpayGatewayTokenTimeout'] =
$this->getGlobal( 'TokenTimeout' );
+ }
}
/**
diff --git a/worldpay_gateway/worldpay_gateway.body.php
b/worldpay_gateway/worldpay_gateway.body.php
index 1de552d..e508ef4 100644
--- a/worldpay_gateway/worldpay_gateway.body.php
+++ b/worldpay_gateway/worldpay_gateway.body.php
@@ -33,7 +33,6 @@
protected function handleRequest() {
if ( $this->adapter->isESOP() ) {
$this->getOutput()->addModules(
'ext.donationinterface.worldpay.esopjs' );
- Hooks::register( 'MakeGlobalVariablesScript', array(
$this->adapter, 'setClientVariables' ) );
} else {
$this->getOutput()->addModules(
'ext.donationinterface.worldpay.styles' ); //loads early
$this->getOutput()->addModules(
'ext.donationinterface.worldpay.code' ); //loads at normal time
--
To view, visit https://gerrit.wikimedia.org/r/284366
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2239d6d1abf2db21c968817412839bf9eea5a18d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits