Ejegg has uploaded a new change for review. https://gerrit.wikimedia.org/r/323254
Change subject: Allow getRequiredFields before unstagedData is set ...................................................................... Allow getRequiredFields before unstagedData is set Useful for initial validation. Bug: T151411 Change-Id: Ifa9228a3aa922725771733999ca365cbe12b08d5 --- M adyen_gateway/adyen.adapter.php M astropay_gateway/astropay.adapter.php M gateway_common/gateway.adapter.php 3 files changed, 25 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/54/323254/1 diff --git a/adyen_gateway/adyen.adapter.php b/adyen_gateway/adyen.adapter.php index fadcc3f..8266a69 100644 --- a/adyen_gateway/adyen.adapter.php +++ b/adyen_gateway/adyen.adapter.php @@ -30,8 +30,8 @@ return 'namevalue'; } - public function getRequiredFields() { - $fields = parent::getRequiredFields(); + public function getRequiredFields( $knownData = null ) { + $fields = parent::getRequiredFields( $knownData ); $fields[] = 'payment_submethod'; return $fields; } diff --git a/astropay_gateway/astropay.adapter.php b/astropay_gateway/astropay.adapter.php index da6b8c8..5801875 100644 --- a/astropay_gateway/astropay.adapter.php +++ b/astropay_gateway/astropay.adapter.php @@ -220,8 +220,8 @@ * Overriding parent method to add fiscal number * @return array of required field names */ - public function getRequiredFields() { - $fields = parent::getRequiredFields(); + public function getRequiredFields( $knownData = null ) { + $fields = parent::getRequiredFields( $knownData ); $noFiscalRequired = array( 'MX', 'PE' ); $country = $this->getData_Unstaged_Escaped( 'country' ); if ( !in_array( $country, $noFiscalRequired ) ) { diff --git a/gateway_common/gateway.adapter.php b/gateway_common/gateway.adapter.php index 624684f..f07638d 100644 --- a/gateway_common/gateway.adapter.php +++ b/gateway_common/gateway.adapter.php @@ -2386,29 +2386,37 @@ * all the per-country / per-gateway cases can be expressed declaratively * in payment method / submethod metadata. If that's the case, move this * function (to DataValidator?) + * @param array|null $knownData if provided, used to determine fields that + * depend on country or payment method. Falls back to unstaged data. * @return array of field names (empty if no payment method set) */ - public function getRequiredFields() { + public function getRequiredFields( $knownData = null ) { + if ( $knownData === null ) { + $knownData = $this->getData_Unstaged_Escaped(); + } $required_fields = array(); $validation = array(); // Add any country-specific required fields - if ( isset( $this->config['country_fields'] ) ) { - $country = $this->getData_Unstaged_Escaped( 'country' ); - if ( $country && isset( $this->config['country_fields'][$country] ) ) { + if ( + isset( $this->config['country_fields'] ) && + !empty( $knownData['country'] ) + ) { + $country = $knownData['country']; + if ( isset( $this->config['country_fields'][$country] ) ) { $validation = $this->config['country_fields'][$country]; } } - if ( $this->getPaymentMethod() ) { - $methodMeta = $this->getPaymentMethodMeta(); + if ( !empty( $knownData['payment_method'] ) ) { + $methodMeta = $this->getPaymentMethodMeta( $knownData['payment_method'] ); if ( isset( $methodMeta['validation'] ) ) { $validation = $methodMeta['validation'] + $validation; } } - if ( $this->getPaymentSubmethod() ) { - $submethodMeta = $this->getPaymentSubmethodMeta(); + if ( !empty( $knownData['payment_submethod'] ) ) { + $submethodMeta = $this->getPaymentSubmethodMeta( $knownData['payment_submethod'] ); if ( isset( $submethodMeta['validation'] ) ) { // submethod validation can override method validation // TODO: child method anything should supersede parent method @@ -2432,9 +2440,11 @@ //however, that's not happening in this class in the code I'm replacing, so... //TODO: Something clever in the DataValidator with data groups like these. ); - $country = $this->getData_Unstaged_Escaped( 'country' ); - if ( $country && Subdivisions::getByCountry( $country ) ) { - $check_not_empty[] = 'state'; + if ( !empty( $knownData['country'] ) ) { + $country = $knownData['country']; + if ( $country && Subdivisions::getByCountry( $country ) ) { + $check_not_empty[] = 'state'; + } } break; case 'creditCard' : -- To view, visit https://gerrit.wikimedia.org/r/323254 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ifa9228a3aa922725771733999ca365cbe12b08d5 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: master Gerrit-Owner: Ejegg <eeggles...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits