Awight has uploaded a new change for review.
https://gerrit.wikimedia.org/r/184010
Change subject: WIP DataValidator uses GatewayAdapter object
......................................................................
WIP DataValidator uses GatewayAdapter object
This makes it possible to change validation based on adapter logic such
as country controlling allowable currencies, etc.
Change-Id: Icb347e2a1a77d359ff604049481d8dca0693e91e
---
M gateway_common/DataValidator.php
1 file changed, 17 insertions(+), 63 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface
refs/changes/10/184010/1
diff --git a/gateway_common/DataValidator.php b/gateway_common/DataValidator.php
index 96f80b4..600d2a0 100644
--- a/gateway_common/DataValidator.php
+++ b/gateway_common/DataValidator.php
@@ -39,21 +39,7 @@
'order_id',
'numAttempt'
);
-
- /**
- * $gateway_classes
- * @var array A list of all possible gateway classes.
- * FIXME: get rid of this
- */
- protected static $gateway_classes = array(
- 'globalcollect' => 'GlobalCollectAdapter',
- 'payflowpro' => 'PayflowProAdapter',
- 'paypal' => 'PaypalAdapter',
- 'adyen' => 'AdyenAdapter',
- 'amazon' => 'AmazonAdapter',
- 'worldpay' => 'WorldPayAdapter'
- );
-
+
/**
* $card_types
* @var array A list of SOME card types we recognize
@@ -458,11 +444,11 @@
switch ( $function ){
case 'validate_amount':
if (
self::checkValidationPassed( array( 'currency_code', 'gateway' ), $instructions
) ){
- $result =
$self::$function( $data[$field], $data['currency_code'], $data['gateway'] );
+ $result =
$self::$function( $data[$field], $data['currency_code'], $gateway );
} //otherwise, just don't do
the validation. The other stuff will be complaining already.
break;
case 'validate_currency_code':
- $result = $self::$function(
$data[$field], $data['gateway'] );
+ $result = $self::$function(
$data[$field], $gateway );
break;
case 'validate_card_type':
//the contingent field in this
case isn't strictly required, so this is going to look funny.
@@ -578,7 +564,7 @@
* @param string $value The piece of data that is supposed to be an
amount.
* @param string $currency_code Valid amounts depend on there being a
* currency code also. This also needs to be passed in.
- * @param string $gateway The gateway needs to be provided so we can
+ * @param GatewayAdapter $gateway The gateway needs to be provided so
we can
* determine that gateway's current price floor and ceiling.
* @return boolean True if $value is a valid amount, otherwise false.
*/
@@ -586,15 +572,9 @@
if ( !$value || !$currency_code || !is_numeric( $value ) ) {
return false;
}
-
- // check amount
- $gateway_class = self::getGatewayClass($gateway);
- if ( !$gateway_class ){
- return false;
- }
-
- $priceFloor = $gateway_class::getGlobal( 'PriceFloor' );
- $priceCeiling = $gateway_class::getGlobal( 'PriceCeiling' );
+
+ $priceFloor = $gateway->getGlobal( 'PriceFloor' );
+ $priceCeiling = $gateway->getGlobal( 'PriceCeiling' );
if ( !preg_match( '/^\d+(\.(\d+)?)?$/', $value ) ||
( ( float ) self::convert_to_usd( $currency_code,
$value ) < ( float ) $priceFloor ||
( float ) self::convert_to_usd( $currency_code, $value
) > ( float ) $priceCeiling ) ) {
@@ -609,15 +589,7 @@
return false;
}
- $gateway_class = self::getGatewayClass($gateway);
- if ( !$gateway_class ){
- return false;
- }
-
- // FIXME: we should be checking currencies using the live
gateway
- // object, the result is often dependent on payment
method/submethod,
- // country, and so on.
- return in_array( $value, $gateway_class::getCurrencies() );
+ return in_array( $value, $gateway->getCurrencies() );
}
/**
@@ -706,6 +678,7 @@
* @return boolean True if $value is a valid gateway, otherwise false
*/
protected static function validate_gateway( $value ){
+ // FIXME
if ( self::getGatewayClass( $value ) ){
return true;
}
@@ -899,23 +872,7 @@
}
return( ( $sum % 10 ) == 0 );
}
-
- /**
- * getGatewayClass
- * This exists to enable things like logging to the correct gateway,
and
- * retrieving gateway-specific globals.
- * @param string $gateway The gateway identifier.
- * @return string The name of the gateway class associated with that
- * identifier, or false if none exists.
- */
- protected static function getGatewayClass( $gateway ) {
- if ( array_key_exists( $gateway, self::$gateway_classes ) &&
class_exists( self::$gateway_classes[$gateway] ) ){
- return self::$gateway_classes[$gateway];
- }
- return false;
- }
-
-
+
/**
* Convert an amount for a particular currency to an amount in USD
*
@@ -1015,13 +972,13 @@
* @param string $ip The IP addx we want to check
* @param string $list_name The global list, ostensibly full of IP
addresses,
* that we want to check against.
- * @param string $gateway The gateway we're concerned with. Only
matters if,
- * for instance, $wgDonationInterfaceIPBlacklist is different from
- * $wgGlobalcollectGatewayIPBlacklist for some silly reason.
+ * @param GatewayAdapter|null $gateway The gateway we're concerned with.
+ * Only matters if, for instance, $wgDonationInterfaceIPBlacklist is
+ * different from $wgGlobalcollectGatewayIPBlacklist for some silly
reason.
* @throws MWException
* @return bool
*/
- public static function ip_is_listed( $ip, $list_name, $gateway = '' ) {
+ public static function ip_is_listed( $ip, $list_name, $gateway = null )
{
//cache this mess
static $ip_list_cache = array();
$globalIPLists = array(
@@ -1032,12 +989,9 @@
if ( !in_array( $list_name, $globalIPLists ) ){
throw new MWException( __FUNCTION__ . " BAD PROGRAMMER.
No recognized global list of IPs called $list_name. Do better." );
}
-
- $class = self::getGatewayClass( $gateway );
- if ( !$class ){
- $class = 'GatewayAdapter';
- }
-
+
+ // FIXME: fall back to generic GatewayAdapter
+
if ( !array_key_exists( $class, $ip_list_cache ) ||
!array_key_exists( $list_name, $ip_list_cache[$class] ) ){
//go get it and expand the block entries
$list = $class::getGlobal( $list_name );
--
To view, visit https://gerrit.wikimedia.org/r/184010
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icb347e2a1a77d359ff604049481d8dca0693e91e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits