Awight has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/281461

Change subject: Rename $unstaged variable
......................................................................

Rename $unstaged variable

It's clearer to call this input data $normalized.

Note that I'm not making the same change to the unstaging function, because
the variable name is correct there--we have only unstaged that data and not
normalized it, yet.

Change-Id: I02be19fdcb1afaea49a4f1b8bed9874bdd5fce04
---
M astropay_gateway/AstroPayFinancialNumbers.php
M gateway_common/AmountInCents.php
M gateway_common/ContributionTrackingPlusUnique.php
M gateway_common/DonorEmail.php
M gateway_common/DonorFullName.php
M gateway_common/DonorLanguage.php
M gateway_common/FiscalNumber.php
M gateway_common/StagingHelper.php
M gateway_common/StreetAddress.php
M globalcollect_gateway/IngenicoFinancialNumber.php
M globalcollect_gateway/IngenicoMethodCodec.php
M globalcollect_gateway/IngenicoReturntoHelper.php
M paypal_gateway/CleanupRecurringLength.php
M paypal_gateway/PayPalLocale.php
M worldpay_gateway/WorldpayCurrency.php
M worldpay_gateway/WorldpayEmail.php
M worldpay_gateway/WorldpayNarrativeStatement.php
M worldpay_gateway/WorldpayReturnto.php
18 files changed, 76 insertions(+), 68 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/61/281461/1

diff --git a/astropay_gateway/AstroPayFinancialNumbers.php 
b/astropay_gateway/AstroPayFinancialNumbers.php
index 35ffb1e..9d5fdf1 100644
--- a/astropay_gateway/AstroPayFinancialNumbers.php
+++ b/astropay_gateway/AstroPayFinancialNumbers.php
@@ -1,23 +1,23 @@
 <?php
 
 class AstroPayFinancialNumbers implements StagingHelper {
-       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
-               $this->stage_donor_id( $adapter, $unstagedData, $stagedData );
-               $this->stage_bank_code( $adapter, $unstagedData, $stagedData );
+       public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
+               $this->stage_donor_id( $adapter, $normalized, $stagedData );
+               $this->stage_bank_code( $adapter, $normalized, $stagedData );
        }
 
        /**
         * They need a 20 char string for a customer ID - give them the first 20
         * characters of the email address for easy lookup
         */
-       protected function stage_donor_id( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
+       protected function stage_donor_id( GatewayType $adapter, $normalized, 
&$stagedData ) {
                // We use these to look up donations by email, so strip out the 
trailing
                // spam-tracking sub-address to get the email we'd see 
complaints from.
                $email = preg_replace( '/\+[^@]*/', '', $stagedData['email'] );
                $stagedData['donor_id'] = substr( $email, 0, 20 );
        }
 
-       protected function stage_bank_code( GatewayType $adapter, 
$unstagedData, &$stagedData ) {
+       protected function stage_bank_code( GatewayType $adapter, $normalized, 
&$stagedData ) {
                $submethod = $adapter->getPaymentSubmethod();
                if ( $submethod ) {
                        $meta = $adapter->getPaymentSubmethodMeta( $submethod );
diff --git a/gateway_common/AmountInCents.php b/gateway_common/AmountInCents.php
index f04bb1c..8222dd6 100644
--- a/gateway_common/AmountInCents.php
+++ b/gateway_common/AmountInCents.php
@@ -10,15 +10,15 @@
  * For example: JPY 1000.05 would be changed to 100005, but should be 100000.
  */
 class AmountInCents implements StagingHelper, UnstagingHelper {
-       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
-               if ( empty( $unstagedData['amount'] ) || empty( 
$unstagedData['currency_code'] ) ) {
+       public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
+               if ( empty( $normalized['amount'] ) || empty( 
$normalized['currency_code'] ) ) {
                        //can't do anything with amounts at all. Just go home.
                        unset( $stagedData['amount'] );
                        return;
                }
 
-               $amount = $unstagedData['amount'];
-               if ( !DataValidator::is_fractional_currency( 
$unstagedData['currency_code'] ) ) {
+               $amount = $normalized['amount'];
+               if ( !DataValidator::is_fractional_currency( 
$normalized['currency_code'] ) ) {
                        $amount = floor( $amount );
                }
 
diff --git a/gateway_common/ContributionTrackingPlusUnique.php 
b/gateway_common/ContributionTrackingPlusUnique.php
index ce55166..a445e86 100644
--- a/gateway_common/ContributionTrackingPlusUnique.php
+++ b/gateway_common/ContributionTrackingPlusUnique.php
@@ -5,8 +5,8 @@
  * pseudorandom value to the contribution_tracking ID.
  */
 class ContributionTrackingPlusUnique implements StagingHelper, UnstagingHelper 
{
-       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
-               $ctid = $unstagedData['contribution_tracking_id'];
+       public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
+               $ctid = $normalized['contribution_tracking_id'];
                //append timestamp to ctid
                $ctid .= '.' . (( microtime( true ) * 1000 ) % 100000); //least 
significant five
                $stagedData['contribution_tracking_id'] = $ctid;
diff --git a/gateway_common/DonorEmail.php b/gateway_common/DonorEmail.php
index 36b2144..d85aaa7 100644
--- a/gateway_common/DonorEmail.php
+++ b/gateway_common/DonorEmail.php
@@ -1,7 +1,7 @@
 <?php
 
 class DonorEmail implements StagingHelper {
-       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
+       public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
                if ( empty( $stagedData['email'] ) ) {
                        $stagedData['email'] = $adapter->getGlobal( 
'DefaultEmail' );
                }
diff --git a/gateway_common/DonorFullName.php b/gateway_common/DonorFullName.php
index 19232b0..ed982f7 100644
--- a/gateway_common/DonorFullName.php
+++ b/gateway_common/DonorFullName.php
@@ -5,13 +5,13 @@
         * Seems more sane to do it this way than provide a single input box
         * and try to parse out fname and lname.
         */
-       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
+       public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
                $name_parts = array();
-               if ( isset( $unstagedData['fname'] ) ) {
-                       $name_parts[] = $unstagedData['fname'];
+               if ( isset( $normalized['fname'] ) ) {
+                       $name_parts[] = $normalized['fname'];
                }
-               if ( isset( $unstagedData['lname'] ) ) {
-                       $name_parts[] = $unstagedData['lname'];
+               if ( isset( $normalized['lname'] ) ) {
+                       $name_parts[] = $normalized['lname'];
                }
                $stagedData['full_name'] = implode( ' ', $name_parts );
        }
diff --git a/gateway_common/DonorLanguage.php b/gateway_common/DonorLanguage.php
index c654c0c..4efd116 100644
--- a/gateway_common/DonorLanguage.php
+++ b/gateway_common/DonorLanguage.php
@@ -1,8 +1,8 @@
 <?php
 
 class DonorLanguage implements StagingHelper {
-       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
-               $language = strtolower( $unstagedData['language'] );
+       public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
+               $language = strtolower( $normalized['language'] );
                $adapterLanguages = $adapter->getAvailableLanguages();
                if ( !in_array( $language, $adapterLanguages ) ) {
                        $fallbacks = Language::getFallbacksFor( $language );
diff --git a/gateway_common/FiscalNumber.php b/gateway_common/FiscalNumber.php
index 3fe8cec..b904292 100644
--- a/gateway_common/FiscalNumber.php
+++ b/gateway_common/FiscalNumber.php
@@ -4,10 +4,10 @@
  * Strip any punctuation from fiscal number before submitting
  */
 class FiscalNumber implements StagingHelper {
-       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
-               if ( empty( $unstagedData['fiscal_number'] ) ) {
-                       if ( isset($unstagedData['country']) &&
-                               $unstagedData['country'] === 'MX' &&
+       public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
+               if ( empty( $normalized['fiscal_number'] ) ) {
+                       if ( isset($normalized['country']) &&
+                               $normalized['country'] === 'MX' &&
                                $adapter->getIdentifier() === 'astropay'
                        ) {
                                // Not validated, but currently required by the 
AstroPay API
@@ -15,7 +15,7 @@
                                $stagedData['fiscal_number'] = 
'111122223333444455';
                        }
                } else {
-                       $stagedData['fiscal_number'] = preg_replace( 
'/[^a-zA-Z0-9]/', '', $unstagedData['fiscal_number'] );
+                       $stagedData['fiscal_number'] = preg_replace( 
'/[^a-zA-Z0-9]/', '', $normalized['fiscal_number'] );
                }
        }
 }
diff --git a/gateway_common/StagingHelper.php b/gateway_common/StagingHelper.php
index 2e48a96..65ebf14 100644
--- a/gateway_common/StagingHelper.php
+++ b/gateway_common/StagingHelper.php
@@ -5,5 +5,13 @@
  * data into the form expected by a payment processing gateway API endpoint.
  */
 interface StagingHelper {
-       function stage( GatewayType $adapter, $unstagedData, &$stagedData );
+       /**
+        * Transform a subset of normalized data into the "staged" data 
expected by
+        * a payment processor.
+        *
+        * @param GatewayType $adapter
+        * @param array $normalized Donation data in normalized form.
+        * @param array $stagedData Reference to output data.
+        */
+       function stage( GatewayType $adapter, $normalized, &$stagedData );
 }
diff --git a/gateway_common/StreetAddress.php b/gateway_common/StreetAddress.php
index 01850e2..39a00cc 100644
--- a/gateway_common/StreetAddress.php
+++ b/gateway_common/StreetAddress.php
@@ -1,9 +1,9 @@
 <?php
 
 class StreetAddress implements StagingHelper {
-       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
-               $stagedData['street'] = $this->stage_street( $unstagedData );
-               $stagedData['zip'] = $this->stage_zip( $unstagedData );
+       public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
+               $stagedData['street'] = $this->stage_street( $normalized );
+               $stagedData['zip'] = $this->stage_zip( $normalized );
        }
 
        /**
@@ -15,10 +15,10 @@
         * The zero is intentional: Allegedly, Some banks won't perform the 
check
         * if the address line contains no numerical data.
         */
-       protected function stage_street( $unstagedData ) {
+       protected function stage_street( $normalized ) {
                $street = '';
-               if ( isset( $unstagedData['street'] ) ) {
-                       $street = trim( $unstagedData['street'] );
+               if ( isset( $normalized['street'] ) ) {
+                       $street = trim( $normalized['street'] );
                }
 
                if ( !$street
@@ -35,10 +35,10 @@
         * In the event that there isn't anything in there, we need to send
         * something along so that AVS checks get triggered at all.
         */
-       protected function stage_zip( $unstagedData ) {
+       protected function stage_zip( $normalized ) {
                $zip = '';
-               if ( isset( $unstagedData['zip'] ) ) {
-                       $zip = trim( $unstagedData['zip'] );
+               if ( isset( $normalized['zip'] ) ) {
+                       $zip = trim( $normalized['zip'] );
                }
                if ( strlen( $zip ) === 0 ) {
                        //it would be nice to check for more here, but the 
world has some
@@ -47,8 +47,8 @@
                }
 
                //country-based zip grooming to make AVS (marginally) happy
-               if ( !empty( $unstagedData['country'] ) ) {
-                       switch ( $unstagedData['country'] ) {
+               if ( !empty( $normalized['country'] ) ) {
+                       switch ( $normalized['country'] ) {
                        case 'CA':
                                //Canada goes "A0A 0A0"
                                $this->staged_data['zip'] = strtoupper( $zip );
diff --git a/globalcollect_gateway/IngenicoFinancialNumber.php 
b/globalcollect_gateway/IngenicoFinancialNumber.php
index 1ea7efe..f683a81 100644
--- a/globalcollect_gateway/IngenicoFinancialNumber.php
+++ b/globalcollect_gateway/IngenicoFinancialNumber.php
@@ -1,7 +1,7 @@
 <?php
 
 class IngenicoFinancialNumber implements StagingHelper {
-       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
+       public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
                // Pad some fields with zeros, to their maximum length.
                $fields = array(
                        'account_number',
@@ -10,10 +10,10 @@
                );
 
                foreach ( $fields as $field ) {
-                       if ( isset( $unstagedData[$field] ) ) {
+                       if ( isset( $normalized[$field] ) ) {
                                $constraints = $adapter->getDataConstraints( 
$field );
                                if ( isset( $constraints['length'] ) ) {
-                                       $newval = 
DataValidator::getZeroPaddedValue( $unstagedData[$field], 
$constraints['length'] );
+                                       $newval = 
DataValidator::getZeroPaddedValue( $normalized[$field], $constraints['length'] 
);
                                        if ( $newval !== false ) {
                                                $stagedData[$field] = $newval;
                                        } else {
diff --git a/globalcollect_gateway/IngenicoMethodCodec.php 
b/globalcollect_gateway/IngenicoMethodCodec.php
index 97c8b6a..f453931 100644
--- a/globalcollect_gateway/IngenicoMethodCodec.php
+++ b/globalcollect_gateway/IngenicoMethodCodec.php
@@ -9,23 +9,23 @@
         * Stages the payment product ID for GC.
         * Not what I had in mind to begin with, but this *completely* blew up.
         */
-       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
+       public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
                $logger = DonationLoggerFactory::getLogger( $adapter );
 
                // FIXME: too much variable management
-               if ( empty( $unstagedData['payment_method'] ) ) {
+               if ( empty( $normalized['payment_method'] ) ) {
                        $stagedData['payment_method'] = '';
                        $stagedData['payment_submethod'] = '';
                        return;
                }
-               $payment_method = $unstagedData['payment_method'];
-               $payment_submethod = $unstagedData['payment_submethod'];
+               $payment_method = $normalized['payment_method'];
+               $payment_submethod = $normalized['payment_submethod'];
 
                // We might support a variation of the submethod for this 
country.
                //TODO: Having to front-load the country in the payment 
submethod is pretty lame.
                //If we don't have one deliberately set...
                if ( !$payment_submethod ) {
-                       $trythis = $payment_method . '_' . strtolower( 
$unstagedData['country'] );
+                       $trythis = $payment_method . '_' . strtolower( 
$normalized['country'] );
                        if ( array_key_exists( $trythis, 
$adapter->getPaymentSubmethods() ) ){
                                $payment_submethod = $trythis;
                                $stagedData['payment_submethod'] = 
$payment_submethod;
diff --git a/globalcollect_gateway/IngenicoReturntoHelper.php 
b/globalcollect_gateway/IngenicoReturntoHelper.php
index da9e538..8caf60c 100644
--- a/globalcollect_gateway/IngenicoReturntoHelper.php
+++ b/globalcollect_gateway/IngenicoReturntoHelper.php
@@ -1,15 +1,15 @@
 <?php
 
 class IngenicoReturntoHelper implements StagingHelper {
-       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
-               if ( !empty( $unstagedData['returnto'] ) ) {
-                       $returnto = $unstagedData['returnto'];
+       public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
+               if ( !empty( $normalized['returnto'] ) ) {
+                       $returnto = $normalized['returnto'];
                } else {
                        $returnto = '';
                }
 
-               if ( isset( $unstagedData['payment_method'] )
-                       && $unstagedData['payment_method'] === 'cc'
+               if ( isset( $normalized['payment_method'] )
+                       && $normalized['payment_method'] === 'cc'
                ) {
                        // Add order ID to the returnto URL, only if it's not 
already there.
                        //TODO: This needs to be more robust (like actually 
pulling the
@@ -19,7 +19,7 @@
                                && !empty( $returnto )
                                && !strpos( $returnto, 'order_id' )
                        ) {
-                               $queryArray = array( 'order_id' => 
$unstagedData['order_id'] );
+                               $queryArray = array( 'order_id' => 
$normalized['order_id'] );
                                $stagedData['returnto'] = wfAppendQuery( 
$returnto, $queryArray );
                        }
                } else {
diff --git a/paypal_gateway/CleanupRecurringLength.php 
b/paypal_gateway/CleanupRecurringLength.php
index 646df0f..5fb8c9b 100644
--- a/paypal_gateway/CleanupRecurringLength.php
+++ b/paypal_gateway/CleanupRecurringLength.php
@@ -4,8 +4,8 @@
  * Silly helper to remove field when empty.
  */
 class CleanupRecurringLength implements StagingHelper {
-       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
-               if ( empty( $unstagedData['recurring_length'] ) ) {
+       public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
+               if ( empty( $normalized['recurring_length'] ) ) {
                        unset( $stagedData['recurring_length'] );
                }
        }
diff --git a/paypal_gateway/PayPalLocale.php b/paypal_gateway/PayPalLocale.php
index 3244de4..b359be2 100644
--- a/paypal_gateway/PayPalLocale.php
+++ b/paypal_gateway/PayPalLocale.php
@@ -1,7 +1,7 @@
 <?php
 
 class PayPalLocale implements StagingHelper {
-       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
+       public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
                // FIXME: Document the upstream source for this reference data.
                $supported_countries = array(
                        'AU',
@@ -38,14 +38,14 @@
                        'zh_TW',
                );
 
-               if ( in_array( $unstagedData['country'], $supported_countries ) 
) {
-                       $stagedData['locale'] = $unstagedData['country'];
+               if ( in_array( $normalized['country'], $supported_countries ) ) 
{
+                       $stagedData['locale'] = $normalized['country'];
                }
 
-               $fallbacks = Language::getFallbacksFor( strtolower( 
$unstagedData['language'] ) );
-               array_unshift( $fallbacks, strtolower( 
$unstagedData['language'] ) );
+               $fallbacks = Language::getFallbacksFor( strtolower( 
$normalized['language'] ) );
+               array_unshift( $fallbacks, strtolower( $normalized['language'] 
) );
                foreach ( $fallbacks as $lang ) {
-                       $locale = "{$lang}_{$unstagedData['country']}";
+                       $locale = "{$lang}_{$normalized['country']}";
                        if ( in_array( $locale, $supported_full_locales ) ) {
                                $stagedData['locale'] = $locale;
                                return;
diff --git a/worldpay_gateway/WorldpayCurrency.php 
b/worldpay_gateway/WorldpayCurrency.php
index 86612f5..bd27c42 100644
--- a/worldpay_gateway/WorldpayCurrency.php
+++ b/worldpay_gateway/WorldpayCurrency.php
@@ -1,8 +1,8 @@
 <?php
 
 class WorldpayCurrency implements StagingHelper {
-       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
-               $currency = $unstagedData['currency_code'];
+       public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
+               $currency = $normalized['currency_code'];
                $codes = $adapter->getConfig( 'currencies' );
                if ( array_key_exists( $currency, $codes ) ) {
                        $stagedData['iso_currency_id'] = $codes[$currency];
diff --git a/worldpay_gateway/WorldpayEmail.php 
b/worldpay_gateway/WorldpayEmail.php
index f235284..f959278 100644
--- a/worldpay_gateway/WorldpayEmail.php
+++ b/worldpay_gateway/WorldpayEmail.php
@@ -4,7 +4,7 @@
        /**
         * Provide email search in the Worldpay console by hiding garishly 
mangled email in a bizarre field
         */
-       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
+       public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
                $alphanumeric = preg_replace('/[^0-9a-zA-Z]/', ' ', 
$stagedData['email']);
                $stagedData['merchant_reference_2'] = $alphanumeric;
        }
diff --git a/worldpay_gateway/WorldpayNarrativeStatement.php 
b/worldpay_gateway/WorldpayNarrativeStatement.php
index 90d7a5d..82e94a8 100644
--- a/worldpay_gateway/WorldpayNarrativeStatement.php
+++ b/worldpay_gateway/WorldpayNarrativeStatement.php
@@ -1,10 +1,10 @@
 <?php
 
 class WorldpayNarrativeStatement implements StagingHelper {
-       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
+       public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
                $stagedData['narrative_statement_1'] = 
WmfFramework::formatMessage(
                        'donate_interface-statement',
-                       $unstagedData['contribution_tracking_id']
+                       $normalized['contribution_tracking_id']
                );
        }
 }
diff --git a/worldpay_gateway/WorldpayReturnto.php 
b/worldpay_gateway/WorldpayReturnto.php
index 5a7821b..e2b0cba 100644
--- a/worldpay_gateway/WorldpayReturnto.php
+++ b/worldpay_gateway/WorldpayReturnto.php
@@ -1,7 +1,7 @@
 <?php
 
 class WorldpayReturnto implements StagingHelper {
-       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
+       public function stage( GatewayType $adapter, $normalized, &$stagedData 
) {
                global $wgServer, $wgArticlePath;
 
                // Rebuild the url with the token param.
@@ -29,11 +29,11 @@
                // MessageCode 302 (which means 'unavailable') unless it is 
wrapped in
                // CDATA tags because godonlyknows
                $arr_query['token'] = rawurlencode( 
$adapter->token_getSaltedSessionToken() );
-               if ( !empty( $unstagedData['ffname'] ) ) {
-                       $arr_query['ffname'] = rawurlencode( 
$unstagedData['ffname'] );
+               if ( !empty( $normalized['ffname'] ) ) {
+                       $arr_query['ffname'] = rawurlencode( 
$normalized['ffname'] );
                }
-               if ( !empty( $unstagedData['amount'] ) ) {
-                       $arr_query['amount'] = rawurlencode( 
$unstagedData['amount'] );
+               if ( !empty( $normalized['amount'] ) ) {
+                       $arr_query['amount'] = rawurlencode( 
$normalized['amount'] );
                }
                foreach ( $arr_query as $key => $val ) {
                        $query .= ( $first ? '?' : '&' ) . $key . '=' . $val;

-- 
To view, visit https://gerrit.wikimedia.org/r/281461
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I02be19fdcb1afaea49a4f1b8bed9874bdd5fce04
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

Reply via email to