[MediaWiki-commits] [Gerrit] Account for gateway-specific min/max client-side - change (mediawiki...DonationInterface)

2016-04-20 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

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(-)

Approvals:
  Awight: Looks good to me, approved
  jenkins-bot: Verified



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 

[MediaWiki-commits] [Gerrit] Account for gateway-specific min/max client-side - change (mediawiki...DonationInterface)

2016-04-19 Thread Ejegg (Code Review)
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