Adamw has uploaded a new change for review.
https://gerrit.wikimedia.org/r/63823
Change subject: Finish moving validation out of GatewayForm and into the
adapter.
......................................................................
Finish moving validation out of GatewayForm and into the adapter.
Change-Id: I723e48a296b854fac77e9122c587ebc11f10864c
---
M adyen_gateway/adyen_gateway.body.php
M gateway_common/GatewayForm.php
M gateway_common/gateway.adapter.php
M globalcollect_gateway/globalcollect.adapter.php
M globalcollect_gateway/globalcollect_gateway.body.php
M payflowpro_gateway/payflowpro_gateway.body.php
M paypal_gateway/paypal_gateway.body.php
7 files changed, 83 insertions(+), 78 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface
refs/changes/23/63823/1
diff --git a/adyen_gateway/adyen_gateway.body.php
b/adyen_gateway/adyen_gateway.body.php
index b2b631b..73a060d 100644
--- a/adyen_gateway/adyen_gateway.body.php
+++ b/adyen_gateway/adyen_gateway.body.php
@@ -49,10 +49,10 @@
if ( $this->adapter->posted ) {
// Check form for errors
- $form_errors = $this->validateForm();
+ $this->adapter->revalidate();
// If there were errors, redisplay form,
otherwise proceed to next step
- if ( $form_errors ) {
+ if ( !$this->adapter->validatedOK() ) {
$this->displayForm();
}
}
diff --git a/gateway_common/GatewayForm.php b/gateway_common/GatewayForm.php
index fa49b06..4a962ae 100644
--- a/gateway_common/GatewayForm.php
+++ b/gateway_common/GatewayForm.php
@@ -57,72 +57,6 @@
}
/**
- * Checks current dataset for validation errors
- * TODO: As with every other bit of gateway-related logic that should
- * definitely be available to every entry point, and functionally has
very
- * little to do with being contained within what in an ideal world
would be
- * a piece of mostly UI, this function needs to be moved inside the
gateway
- * adapter class.
- * @param array $options
- * OPTIONAL - In addition to all non-optional validation which
verifies
- * that all populated fields contain an appropriate data type, you
may
- * require certain field groups to be non-empty.
- * - address - Validation requires non-empty: street, city, state, zip
- * - amount - Validation requires non-empty: amount
- * - creditCard - Validation requires non-empty: card_num, cvv,
expiration and card_type
- * - email - Validation requires non-empty: email
- * - name - Validation requires non-empty: fname, lname
- *
- * @return boolean Returns true on an error-free validation, otherwise
false.
- */
- public function validateForm( $options = array() ) {
-
- $check_not_empty = array();
-
- foreach ( $options as $option ){
- $add_checks = array();
- switch( $option ){
- case 'address' :
- $add_checks = array(
- 'street',
- 'city',
- 'state',
- 'country',
- 'zip', //this should really be
added or removed, depending on the country and/or gateway requirements.
- //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.
- );
- break;
- case 'amount' :
- $add_checks[] = 'amount';
- break;
- case 'creditCard' :
- $add_checks = array(
- 'card_num',
- 'cvv',
- 'expiration',
- 'card_type'
- );
- break;
- case 'email' :
- $add_checks[] = 'email';
- break;
- case 'name' :
- $add_checks = array(
- 'fname',
- 'lname'
- );
- break;
- }
- $check_not_empty = array_merge( $check_not_empty,
$add_checks );
- }
-
- $validated_ok = $this->adapter->revalidate( $check_not_empty );
-
- return !$validated_ok;
- }
-
- /**
* Build and display form to user
*
* The message at the top of the form can be edited in the
payflow_gateway.i18n.php file
diff --git a/gateway_common/gateway.adapter.php
b/gateway_common/gateway.adapter.php
index bafe018..d9b2004 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -2444,9 +2444,75 @@
public function getOriginalValidationErrors( ){
return $this->dataObj->getValidationErrors();
}
-
+
+ /**
+ * Build field list from group name
+ *
+ * @param array $options
+ * OPTIONAL - In addition to all non-optional validation which
verifies
+ * that all populated fields contain an appropriate data type, you
may
+ * require certain field groups to be non-empty.
+ * - address - Validation requires non-empty: street, city, state, zip
+ * - amount - Validation requires non-empty: amount
+ * - creditCard - Validation requires non-empty: card_num, cvv,
expiration and card_type
+ * - email - Validation requires non-empty: email
+ * - name - Validation requires non-empty: fname, lname
+ *
+ * @return array of field names
+ */
+ protected function buildRequiredFields( $options = array() ) {
+ $check_not_empty = array();
+
+ foreach ( $options as $option ) {
+ $add_checks = array();
+ switch ( $option ) {
+ case 'address' :
+ $add_checks = array(
+ 'street',
+ 'city',
+ 'state',
+ 'country',
+ 'zip', //this should really be
added or removed, depending on the country and/or gateway requirements.
+ //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.
+ );
+ break;
+ case 'amount' :
+ $add_checks[] = 'amount';
+ break;
+ case 'creditCard' :
+ $add_checks = array(
+ 'card_num',
+ 'cvv',
+ 'expiration',
+ 'card_type'
+ );
+ break;
+ case 'email' :
+ $add_checks[] = 'email';
+ break;
+ case 'name' :
+ $add_checks = array(
+ 'fname',
+ 'lname'
+ );
+ break;
+ default:
+ self::log( "bad required group name:
{$option}", LOG_ERR );
+ break;
+ }
+ $check_not_empty = array_merge( $check_not_empty,
$add_checks );
+ }
+ return $check_not_empty;
+ }
+
+ protected function getExtraRequiredFields() {
+ return array();
+ }
+
//TODO: Maybe validate on $unstaged_data directly?
- public function revalidate( $check_not_empty = array() ){
+ public function revalidate() {
+ $check_not_empty = $this->getExtraRequiredFields();
$validation_errors = $this->dataObj->getValidationErrors( true,
$check_not_empty );
$this->setValidationErrors( $validation_errors );
return $this->validatedOK();
diff --git a/globalcollect_gateway/globalcollect.adapter.php
b/globalcollect_gateway/globalcollect.adapter.php
index ad158cb..158d1b8 100644
--- a/globalcollect_gateway/globalcollect.adapter.php
+++ b/globalcollect_gateway/globalcollect.adapter.php
@@ -689,7 +689,7 @@
* Default => Credit Card
*
* Every payment_method should have a payment_submethod.
- * This is just a catch to sure some validation happens.
+ * This is just a catch-all to ensure some validation happens.
*/
// None specified - This is a catchall to validate all options
for credit cards.
@@ -1108,7 +1108,11 @@
return $meta['validation'];
}
-
+
+ protected function getExtraRequiredFields() {
+ return $this->buildRequiredFields(
$this->getPaymentSubmethodFormValidation() );
+ }
+
/**
* Because GC has some processes that involve more than one
do_transaction
* chained together, we're catching those special ones in an overload
and
@@ -2372,5 +2376,4 @@
return false;
}
}
-
}
diff --git a/globalcollect_gateway/globalcollect_gateway.body.php
b/globalcollect_gateway/globalcollect_gateway.body.php
index 3c7106d..faf322c 100644
--- a/globalcollect_gateway/globalcollect_gateway.body.php
+++ b/globalcollect_gateway/globalcollect_gateway.body.php
@@ -70,10 +70,10 @@
}
// Check form for errors
- $form_errors = $this->validateForm(
$this->adapter->getPaymentSubmethodFormValidation() );
+ $this->adapter->revalidate();
// If there were errors, redisplay form,
otherwise proceed to next step
- if ( $form_errors ) {
+ if ( !$this->adapter->validatedOK() ) {
$this->displayForm();
} else { // The submitted form data is valid,
so process it
// allow any external validators to
have their way with the data
diff --git a/payflowpro_gateway/payflowpro_gateway.body.php
b/payflowpro_gateway/payflowpro_gateway.body.php
index abd66a9..7c4cde0 100644
--- a/payflowpro_gateway/payflowpro_gateway.body.php
+++ b/payflowpro_gateway/payflowpro_gateway.body.php
@@ -33,9 +33,9 @@
if ( $this->adapter->posted ) {
// The form was submitted and the payment
method has been set
// Check form for errors
- $form_errors = $this->validateForm();
+ $this->adapter->revalidate();
// If there were errors, redisplay form,
otherwise proceed to next step
- if ( $form_errors ) {
+ if ( !$this->adapter->validatedOK() ) {
$this->displayForm();
} else { // The submitted form data is valid,
so process it
$result =
$this->adapter->do_transaction( 'Card' );
diff --git a/paypal_gateway/paypal_gateway.body.php
b/paypal_gateway/paypal_gateway.body.php
index 125b428..0f1f1e6 100644
--- a/paypal_gateway/paypal_gateway.body.php
+++ b/paypal_gateway/paypal_gateway.body.php
@@ -34,7 +34,9 @@
$this->setHeaders();
- if ( $this->validateForm() ) {
+ $this->adapter->revalidate();
+
+ if ( !$this->adapter->validatedOK() ) {
$form_errors = $this->adapter->getValidationErrors();
if ( array_key_exists( 'currency_code', $form_errors )
) {
// If the currency is invalid, fallback to USD
--
To view, visit https://gerrit.wikimedia.org/r/63823
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I723e48a296b854fac77e9122c587ebc11f10864c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Adamw <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits