Adamw has uploaded a new change for review. https://gerrit.wikimedia.org/r/64872
Change subject: GatewayAdapter::isSupported ...................................................................... GatewayAdapter::isSupported * Now it is possible to start a transaction with a given payment method but no gateway, then determine which gateways can complete the transaction. * Algorithms to eg determine whether a transaction currency is supported can vary at the gateway level, and may depend on the country of origin, etc. Change-Id: I73124f9f6b1160d339fcb2f7be5a2390f738a1dc --- M adyen_gateway/adyen.adapter.php M amazon_gateway/amazon.adapter.php M gateway_common/DataValidator.php M gateway_common/gateway.adapter.php M globalcollect_gateway/globalcollect.adapter.php M paypal_gateway/paypal.adapter.php 6 files changed, 39 insertions(+), 26 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/72/64872/1 diff --git a/adyen_gateway/adyen.adapter.php b/adyen_gateway/adyen.adapter.php index 0f7a4d0..92b44e5 100644 --- a/adyen_gateway/adyen.adapter.php +++ b/adyen_gateway/adyen.adapter.php @@ -223,7 +223,7 @@ function getResponseData( $response ) { } - static function getCurrencies() { + function getCurrencies() { // See http://www.adyen.com/platform/all-countries-all-currencies/ // This should be the list of all global "acceptance currencies". Not // finding that list, I've used everything for which we keep diff --git a/amazon_gateway/amazon.adapter.php b/amazon_gateway/amazon.adapter.php index 99ba1ce..e80c2f9 100644 --- a/amazon_gateway/amazon.adapter.php +++ b/amazon_gateway/amazon.adapter.php @@ -272,7 +272,7 @@ } } - static function getCurrencies() { + function getCurrencies() { // See https://payments.amazon.com/sdui/sdui/about?nodeId=73479#feat_countries return array( 'USD', diff --git a/gateway_common/DataValidator.php b/gateway_common/DataValidator.php index 178a7a7..5b313b3 100644 --- a/gateway_common/DataValidator.php +++ b/gateway_common/DataValidator.php @@ -375,9 +375,11 @@ $instructions['valid_type']['currency_code'] = 'validate_alphanumeric'; $instructions['non_empty']['gateway'] = 'validate_not_empty'; $instructions['valid_type']['gateway'] = self::getValidationFunction( 'gateway' ); + + $instructions['calculated']['currency_code'] = 'validate_supported_environment'; break; case 'validate_currency_code': - $check_type = 'calculated'; + $check_type = 'non_empty'; break; case 'validate_card_type': $check_type = 'calculated'; @@ -451,8 +453,8 @@ $result = $self::$function( $data[$field], $data['currency_code'], $data['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'] ); + case 'validate_supported_environment': + $result = $self::$function( $data['country'], $data['currency_code'], $data['recurring'], $data['payment_method'], $gateway ); break; case 'validate_card_type': //the contingent field in this case isn't strictly required, so this is going to look funny. @@ -529,8 +531,6 @@ case 'fname': case 'lname': return 'validate_name'; - case 'currency_code': - return 'validate_currency_code'; case 'city': case 'street': return 'validate_address'; @@ -599,22 +599,10 @@ return true; } - protected static function validate_currency_code( $value, $gateway ) { - if ( !$value ) { - 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() ); + protected static function validate_supported_environment( $country, $currency, $recurring, $method, $gateway ) { + return $gateway->isSupported( $country, $currency, $recurring, $method ); } - + /** * validate_card_type * Determines if the $value passed in is (possibly) a valid credit card type. diff --git a/gateway_common/gateway.adapter.php b/gateway_common/gateway.adapter.php index b501f77..4ac51d2 100644 --- a/gateway_common/gateway.adapter.php +++ b/gateway_common/gateway.adapter.php @@ -99,7 +99,11 @@ */ function defineReturnValueMap(); - static function getCurrencies(); + + /** + * Determine whether a specific payment environment can be supported by this gateway + */ + function isSupported( $country, $currency, $recurring, $method ); /** * Begin a payment, if possible @@ -2739,6 +2743,27 @@ return $score; } + public function isSupported( $country, $currency, $recurring, $method ) { + // FIXME: cheeze sauce + if ( is_callable( $this, 'getCountries' ) + and !in_array( $country, $this->getCountries() ) ) { + return false; + } + if ( is_callable( $this, 'getCurrencies' ) + and !in_array( $country, $this->getCurrencies() ) ) { + return false; + } + //TODO: this conditional is for back-compat: in the future we + // will not decide on a gateway until after the method is selected, + // so a blank method will return false; + if ( $method ) { + if ( !array_key_exists( $method, $this->getPaymentMethods() ) ) { + return false; + } + } + return true; + } + // Totally useless base implementation. public function initiatePayment() { if ( $this->checkTokens() ) { diff --git a/globalcollect_gateway/globalcollect.adapter.php b/globalcollect_gateway/globalcollect.adapter.php index f28fbb4..7ee3eca 100644 --- a/globalcollect_gateway/globalcollect.adapter.php +++ b/globalcollect_gateway/globalcollect.adapter.php @@ -611,7 +611,7 @@ * * The credit card group has a catchall for unspecified payment types. */ - protected function definePaymentMethods() { + function definePaymentMethods() { $this->payment_methods = array(); @@ -1635,7 +1635,7 @@ * Gets all the currency codes appropriate for this gateway * @return array of currency codes */ - static function getCurrencies() { + function getCurrencies() { // If you update this list, also update the list in the exchange_rates drupal module. $currencies = array( 'AED', // UAE dirham diff --git a/paypal_gateway/paypal.adapter.php b/paypal_gateway/paypal.adapter.php index 57386f7..b69dcd5 100644 --- a/paypal_gateway/paypal.adapter.php +++ b/paypal_gateway/paypal.adapter.php @@ -158,7 +158,7 @@ PaymentMethod::registerMethods( $this->payment_methods ); } - static function getCurrencies() { + function getCurrencies() { // see https://www.x.com/developers/paypal/documentation-tools/api/currency-codes return array( 'AUD', -- To view, visit https://gerrit.wikimedia.org/r/64872 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I73124f9f6b1160d339fcb2f7be5a2390f738a1dc Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: master Gerrit-Owner: Adamw <awi...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits