https://www.mediawiki.org/wiki/Special:Code/MediaWiki/102030

Revision: 102030
Author:   khorn
Date:     2011-11-04 19:37:01 +0000 (Fri, 04 Nov 2011)
Log Message:
-----------
Locks down all staged gateway data, and (hopefully) makes the distinction 
between staged gateway-only data, and "raw" (but normalized and sanitized) data 
as entered by the user or our system. 
This fixes a default where staged data (amount was the one we noticed) was 
making it into minfraud queries, from globalcollect. 
Also took this as a bit of an excuse to do some other tiny bits of hygiene near 
the places I was fixing anyway. 

Modified Paths:
--------------
    
trunk/extensions/DonationInterface/extras/conversion_log/conversion_log.body.php
    
trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php
    
trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php
    
trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php
    
trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php
    trunk/extensions/DonationInterface/extras/minfraud/minfraud.body.php
    trunk/extensions/DonationInterface/extras/recaptcha/recaptcha.body.php
    trunk/extensions/DonationInterface/gateway_common/GatewayForm.php
    trunk/extensions/DonationInterface/gateway_common/donation.api.php
    trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
    trunk/extensions/DonationInterface/gateway_forms/Form.php
    
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
    
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php
    
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php
    trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php
    
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
    trunk/extensions/DonationInterface/tests/Adapter/GatewayAdapterTestCase.php
    trunk/extensions/DonationInterface/tests/DonationInterfaceTestCase.php

Modified: 
trunk/extensions/DonationInterface/extras/conversion_log/conversion_log.body.php
===================================================================
--- 
trunk/extensions/DonationInterface/extras/conversion_log/conversion_log.body.php
    2011-11-04 18:55:17 UTC (rev 102029)
+++ 
trunk/extensions/DonationInterface/extras/conversion_log/conversion_log.body.php
    2011-11-04 19:37:01 UTC (rev 102030)
@@ -11,7 +11,7 @@
                // if the trxn has been outright rejected, log it
                if ( $this->gateway_adapter->getValidationAction() == 'reject' 
) {
                        $this->log(
-                               $this->gateway_adapter->getData( 
'contribution_tracking_id' ), 'Rejected'
+                               $this->gateway_adapter->getData_Raw( 
'contribution_tracking_id' ), 'Rejected'
                        );
                        return TRUE;
                }
@@ -21,7 +21,7 @@
                        return FALSE;
 
                $this->log(
-                       $this->gateway_adapter->getData( 
'contribution_tracking_id' ), "Gateway response: " . addslashes( 
$this->gateway_adapter->getTransactionMessage() ), '"' . addslashes( 
json_encode( $this->gateway_adapter->getTransactionData() ) ) . '"'
+                       $this->gateway_adapter->getData_Raw( 
'contribution_tracking_id' ), "Gateway response: " . addslashes( 
$this->gateway_adapter->getTransactionMessage() ), '"' . addslashes( 
json_encode( $this->gateway_adapter->getTransactionData() ) ) . '"'
                );
                return TRUE;
        }

Modified: 
trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php
===================================================================
--- 
trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php
    2011-11-04 18:55:17 UTC (rev 102029)
+++ 
trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php
    2011-11-04 19:37:01 UTC (rev 102030)
@@ -60,7 +60,7 @@
                $this->gateway_adapter->setValidationAction( $localAction );
 
                $log_msg = '"' . $localAction . "\"\t\"" . $this->risk_score . 
"\"";
-               $this->log( $this->gateway_adapter->getData( 
'contribution_tracking_id' ), 'Filtered', $log_msg );
+               $this->log( $this->gateway_adapter->getData_Raw( 
'contribution_tracking_id' ), 'Filtered', $log_msg );
                return TRUE;
        }
 

Modified: 
trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php
===================================================================
--- 
trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php
 2011-11-04 18:55:17 UTC (rev 102029)
+++ 
trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php
 2011-11-04 19:37:01 UTC (rev 102030)
@@ -17,7 +17,7 @@
                        return TRUE;
                }
 
-               $minfraud_query = $this->build_query( 
$this->gateway_adapter->getData() );
+               $minfraud_query = $this->build_query( 
$this->gateway_adapter->getData_Raw() );
                $this->query_minfraud( $minfraud_query );
                
 

Modified: 
trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php
===================================================================
--- 
trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php
 2011-11-04 18:55:17 UTC (rev 102029)
+++ 
trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php
 2011-11-04 19:37:01 UTC (rev 102030)
@@ -21,7 +21,7 @@
 
        public function filter() {
                // pull out the referrer from the gateway_adapter
-               $referrer = $this->gateway_adapter->getData( 'referrer' );
+               $referrer = $this->gateway_adapter->getData_Raw( 'referrer' );
 
                // a very complex filtering algorithm for referrers
                $refRules = $this->gateway_adapter->getGlobal( 
'CustomFiltersRefRules' );
@@ -38,7 +38,7 @@
                                $log_msg .= "\t\"" . addslashes( $regex ) . 
"\"";
                                $log_msg .= "\t\"" . $this->cfo->risk_score . 
"\"";
                                $this->log(
-                                       $this->gateway_adapter->getData( 
'contribution_tracking_id' ), 'Filter: Referrer', $log_msg
+                                       $this->gateway_adapter->getData_Raw( 
'contribution_tracking_id' ), 'Filter: Referrer', $log_msg
                                );
                        }
                }

Modified: 
trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php
===================================================================
--- 
trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php
     2011-11-04 18:55:17 UTC (rev 102029)
+++ 
trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php
     2011-11-04 19:37:01 UTC (rev 102030)
@@ -21,7 +21,7 @@
 
        public function filter() {
                // pull out the source from the filter object
-               $source = $this->gateway_adapter->getData( 'utm_source' );
+               $source = $this->gateway_adapter->getData_Raw( 'utm_source' );
 
                // a very complex filtering algorithm for sources
                $srcRules = $this->gateway_adapter->getGlobal( 
'CustomFiltersSrcRules' );
@@ -38,7 +38,7 @@
                                $log_msg .= "\t\"" . addslashes( $regex ) . 
"\"";
                                $log_msg .= "\t\"" . $this->cfo->risk_score . 
"\"";
                                $this->log(
-                                       $this->gateway_adapter->getData( 
'contribution_tracking_id' ), 'Filter: Source', $log_msg
+                                       $this->gateway_adapter->getData_Raw( 
'contribution_tracking_id' ), 'Filter: Source', $log_msg
                                );
                        }
                }

Modified: trunk/extensions/DonationInterface/extras/minfraud/minfraud.body.php
===================================================================
--- trunk/extensions/DonationInterface/extras/minfraud/minfraud.body.php        
2011-11-04 18:55:17 UTC (rev 102029)
+++ trunk/extensions/DonationInterface/extras/minfraud/minfraud.body.php        
2011-11-04 19:37:01 UTC (rev 102030)
@@ -68,7 +68,7 @@
                        return TRUE;
                }
 
-               $minfraud_query = $this->build_query( 
$this->gateway_adapter->getData() );
+               $minfraud_query = $this->build_query( 
$this->gateway_adapter->getData_Raw() );
                $this->query_minfraud( $minfraud_query );
                $localAction = $this->determine_action( 
$this->minfraud_response['riskScore'] );
                $this->gateway_adapter->setValidationAction( $localAction );
@@ -76,7 +76,7 @@
                // reset the data hash
                $this->gateway_adapter->unsetHash();
                $this->gateway_adapter->setActionHash( $this->generate_hash( 
$localAction ) );
-               $this->gateway_adapter->setHash( $this->generate_hash( 
$this->gateway_adapter->getData() ) );
+               $this->gateway_adapter->setHash( $this->generate_hash( 
$this->gateway_adapter->getData_Raw() ) );
 
                // Write the query/response to the log
                $this->log_query( $minfraud_query, $localAction );
@@ -88,13 +88,13 @@
         */
        public function log_query( $minfraud_query, $action ) {
                if ( $this->log_fh ) {
-                       $log_message = '"' . addslashes( 
$this->gateway_adapter->getData( 'comment' ) ) . '"';
-                       $log_message .= "\t" . '"' . addslashes( 
$this->gateway_adapter->getData( 'amount' ) . ' ' . 
$this->gateway_adapter->getData( 'currency' ) ) . '"';
+                       $log_message = '"' . addslashes( 
$this->gateway_adapter->getData_Raw( 'comment' ) ) . '"';
+                       $log_message .= "\t" . '"' . addslashes( 
$this->gateway_adapter->getData_Raw( 'amount' ) . ' ' . 
$this->gateway_adapter->getData_Raw( 'currency' ) ) . '"';
                        $log_message .= "\t" . '"' . addslashes( json_encode( 
$minfraud_query ) ) . '"';
                        $log_message .= "\t" . '"' . addslashes( json_encode( 
$this->minfraud_response ) ) . '"';
                        $log_message .= "\t" . '"' . addslashes( $action ) . 
'"';
-                       $log_message .= "\t" . '"' . addslashes( 
$this->gateway_adapter->getData( 'referrer' ) ) . '"';
-                       $this->log( $this->gateway_adapter->getData( 
'contribution_tracking_id' ), 'minFraud query', $log_message );
+                       $log_message .= "\t" . '"' . addslashes( 
$this->gateway_adapter->getData_Raw( 'referrer' ) ) . '"';
+                       $this->log( $this->gateway_adapter->getData_Raw( 
'contribution_tracking_id' ), 'minFraud query', $log_message );
                }
        }
 
@@ -111,7 +111,7 @@
         */
        public function can_bypass_minfraud() {
                // if the data bits data_hash and action are not set, we need 
to hit minFraud
-               $localdata = $this->gateway_adapter->getData();
+               $localdata = $this->gateway_adapter->getData_Raw();
                if ( !strlen( $localdata['data_hash'] ) || !strlen( 
$localdata['action'] ) ) {
                        return FALSE;
                }
@@ -123,7 +123,7 @@
                // compare the data hash to make sure it's legit
                if ( $this->compare_hash( $data_hash, serialize( $localdata ) ) 
) {
 
-                       $this->gateway_adapter->setHash( $this->generate_hash( 
$this->gateway_adapter->getData() ) ); // hash the data array
+                       $this->gateway_adapter->setHash( $this->generate_hash( 
$this->gateway_adapter->getData_Raw() ) ); // hash the data array
                        // check to see if we have a valid action set for us to 
bypass minfraud
                        $actions = array( 'process', 'challenge', 'review', 
'reject' );
                        $action_hash = $localdata['action']; // a hash of the 
action to take passed in by the form submission

Modified: trunk/extensions/DonationInterface/extras/recaptcha/recaptcha.body.php
===================================================================
--- trunk/extensions/DonationInterface/extras/recaptcha/recaptcha.body.php      
2011-11-04 18:55:17 UTC (rev 102029)
+++ trunk/extensions/DonationInterface/extras/recaptcha/recaptcha.body.php      
2011-11-04 19:37:01 UTC (rev 102030)
@@ -42,12 +42,12 @@
                        $captcha_resp = $this->check_captcha();
                        if ( $captcha_resp->is_valid ) {
                                // if validated, update the action and move on
-                               $this->log( $this->gateway_adapter->getData( 
'contribution_tracking_id' ), 'Captcha passed' );
+                               $this->log( 
$this->gateway_adapter->getData_Raw( 'contribution_tracking_id' ), 'Captcha 
passed' );
                                $this->gateway_adapter->setValidationAction( 
'process' );
                                return TRUE;
                        } else {
                                $this->recap_err = $captcha_resp->error;
-                               $this->log( $this->gateway_adapter->getData( 
'contribution_tracking_id' ), 'Captcha failed' );
+                               $this->log( 
$this->gateway_adapter->getData_Raw( 'contribution_tracking_id' ), 'Captcha 
failed' );
                        }
                }
                // display captcha
@@ -64,7 +64,7 @@
                $useSSL = $this->gateway_adapter->getGlobal( 'RecaptchaUseSSL' 
);
 
                // log that a captcha's been triggered
-               $this->log( $this->gateway_adapter->getData( 
'contribution_tracking_id' ), 'Captcha triggered' );
+               $this->log( $this->gateway_adapter->getData_Raw( 
'contribution_tracking_id' ), 'Captcha triggered' );
 
                // construct the HTML used to display the captcha
                $captcha_html = Xml::openElement( 'div', array( 'id' => 
'mw-donate-captcha' ) );
@@ -76,7 +76,7 @@
 
                //TODO: use setValidationErrors and getValidationErrors 
everywhere, and 
                //refactor all the form constructors one more time. Eventually. 
 
-               $data = $this->gateway_adapter->getData();
+               $data = $this->gateway_adapter->getData_Raw();
                $errors = $this->gateway_adapter->getValidationErrors();
                $form_obj = new $form_class( $this->gateway_adapter, $errors );
 

Modified: trunk/extensions/DonationInterface/gateway_common/GatewayForm.php
===================================================================
--- trunk/extensions/DonationInterface/gateway_common/GatewayForm.php   
2011-11-04 18:55:17 UTC (rev 102029)
+++ trunk/extensions/DonationInterface/gateway_common/GatewayForm.php   
2011-11-04 19:37:01 UTC (rev 102030)
@@ -77,7 +77,7 @@
         */
        public function validateForm( &$error, $options = array() ) {
                
-               $data = $this->adapter->getDisplayData();
+               $data = $this->adapter->getData_Raw();
                
                extract( $options );
 

Modified: trunk/extensions/DonationInterface/gateway_common/donation.api.php
===================================================================
--- trunk/extensions/DonationInterface/gateway_common/donation.api.php  
2011-11-04 18:55:17 UTC (rev 102029)
+++ trunk/extensions/DonationInterface/gateway_common/donation.api.php  
2011-11-04 19:37:01 UTC (rev 102030)
@@ -44,7 +44,7 @@
                        $this->dieUsage( "Invalid gateway <<<$gateway>>> passed 
to Donation API.", 'unknown_gateway' );
                }
 
-               //$normalizedData = $gatewayObj->getData();
+               //$normalizedData = $gatewayObj->getData_Raw();
                $outputResult = array();
                $outputResult['message'] = $result['message'];
                $outputResult['status'] = $result['status'];

Modified: trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
===================================================================
--- trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php       
2011-11-04 18:55:17 UTC (rev 102029)
+++ trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php       
2011-11-04 19:37:01 UTC (rev 102030)
@@ -151,7 +151,8 @@
         */
        protected $staged_vars = array();
        protected $return_value_map;
-       protected $postdata;
+       protected $staged_data;
+       protected $raw_data;
        protected $postdatadefaults;
        protected $xmlDoc;
        protected $dataObj;
@@ -160,7 +161,7 @@
        protected $validation_errors;
        protected $current_transaction;
        protected $action;
-       public $debugarray; //TODO: Take me out. 
+       public $debugarray; 
 
        //ALL OF THESE need to be redefined in the children. Much voodoo 
depends on the accuracy of these constants. 
        const GATEWAY_NAME = 'Donation Gateway';
@@ -206,8 +207,8 @@
 
                $this->dataObj = new DonationData( get_called_class(), 
self::getGlobal( 'Test' ), $testData );
 
-               $this->postdata = $this->dataObj->getData();
-               //TODO: Fix this a bit. 
+               $this->raw_data = $this->dataObj->getData();
+               $this->staged_data = $this->raw_data;
 
                $this->posted = ( $wgRequest->wasPosted() && ( !is_null( 
$wgRequest->getVal( 'numAttempt', null ) ) ) );
 
@@ -218,7 +219,6 @@
                $this->defineAccountInfo();
                $this->defineReturnValueMap();
 
-               $this->displaydata = $this->postdata;
                $this->stageData();
        }
 
@@ -292,19 +292,20 @@
                        return $checkResult;
                }
        }
-
+       
        /**
-        * Returns staged data from the adapter object. 
+        * Returns staged data from the adapter object, or null if a key was 
+        * specified and no value exsits. 
         * @param string $val An optional specific key you want returned. 
         * @return mixed All the staged data held by the adapter, or if a key 
was 
         * set, the staged value for that key. 
         */
-       function getData( $val = '' ) {
+       function getData_Staged( $val = '' ) {
                if ( $val === '' ) {
-                       return $this->postdata;
+                       return $this->staged_data;
                } else {
-                       if ( array_key_exists( $val, $this->postdata ) ) {
-                               return $this->postdata[$val];
+                       if ( array_key_exists( $val, $this->staged_data ) ) {
+                               return $this->staged_data[$val];
                        } else {
                                return null;
                        }
@@ -337,22 +338,22 @@
        }
 
        /**
-        * Returns the variable $this->dataObj which should be an instance of
-        * DonationData
-        *
-        * @return DonationData
+        * This is the ONLY getData type function anything should be using 
+        * outside the adapter. 
+        * Please note that in this case, raw means it's been normalized and 
+        * sanitized by DonationData. Mostly, we qualify it as "raw" because 
it's 
+        * not been staged for this adapter. 
+        * @param string $val The specific key you're looking for (if any)
+        * @return mixed An array of all the raw, unstaged (but normalized and 
+        * sanitized) data sent to the adapter, or if $val was set, either the 
+        * specific value held for $val, or null if none exists.  
         */
-       public function getDonationData() {
-
-               return $this->dataObj;
-       }
-
-       function getDisplayData( $val = '' ) {
+       public function getData_Raw( $val = '' ) {
                if ( $val === '' ) {
-                       return $this->displaydata;
+                       return $this->raw_data;
                } else {
-                       if ( array_key_exists( $val, $this->displaydata ) ) {
-                               return $this->displaydata[$val];
+                       if ( array_key_exists( $val, $this->raw_data ) ) {
+                               return $this->raw_data[$val];
                        } else {
                                return null;
                        }
@@ -534,10 +535,10 @@
                        if ( $token === true ) { //we just want the field name 
to use, so short-circuit all that mess. 
                                return '@' . 
$this->var_map[$gateway_field_name];
                        }
-                       if ( array_key_exists( 
$this->var_map[$gateway_field_name], $this->postdata ) &&
-                               
$this->postdata[$this->var_map[$gateway_field_name]] !== '' ) {
+                       $staged = $this->getData_Staged( 
$this->var_map[$gateway_field_name] );
+                       if ( !is_null( $staged ) ) {
                                //if it was sent, use that. 
-                               return 
$this->postdata[$this->var_map[$gateway_field_name]];
+                               return $staged;
                        } else {
                                //return the default for that form value
 
@@ -889,7 +890,7 @@
                }
 
                // log that the transaction is essentially complete
-               self::log( $this->getData( 'contribution_tracking_id' ) . " 
Transaction complete." );
+               self::log( $this->getData_Raw( 'contribution_tracking_id' ) . " 
Transaction complete." );
 
                //getTransactionStatus works here like this, because it only 
returns 
                //something other than false if it's the sort of a transaction 
that can 
@@ -897,7 +898,7 @@
 //             $wmfStatus = $this->getTransactionWMFStatus();
 //             switch ( $wmfStatus ){
 //                     case 'failed' : //only kill their session if they've 
tried three (or somehow more) times. 
-//                             if ( (int)$this->postdata['numAttempt'] < 3 ) {
+//                             if ( (int)$this->getData_Staged('numAttempt') < 
3 ) {
 //                                     break;
 //                             }
 //                     case 'complete' :
@@ -906,7 +907,7 @@
 //                             $this->unsetAllSessionData();
 //             }
 
-               $this->debugarray[] = 'numAttempt = ' . 
$this->postdata['numAttempt'];
+               $this->debugarray[] = 'numAttempt = ' . 
$this->getData_Staged('numAttempt');
 
                return $this->getTransactionAllResults();
 
@@ -1072,15 +1073,15 @@
                $results = array();
 
                while ( $i++ <= 3 ) {
-                       self::log( $this->getData( 'contribution_tracking_id' ) 
. ' Preparing to send transaction to ' . self::getGatewayName() );
+                       self::log( $this->getData_Raw( 
'contribution_tracking_id' ) . ' Preparing to send transaction to ' . 
self::getGatewayName() );
                        $results['result'] = curl_exec( $ch );
                        $results['headers'] = curl_getinfo( $ch );
 
                        if ( $results['headers']['http_code'] != 200 && 
$results['headers']['http_code'] != 403 ) {
-                               self::log( $this->getData( 
'contribution_tracking_id' ) . ' Failed sending transaction to ' . 
self::getGatewayName() . ', retrying' );
+                               self::log( $this->getData_Raw( 
'contribution_tracking_id' ) . ' Failed sending transaction to ' . 
self::getGatewayName() . ', retrying' );
                                sleep( 1 );
                        } elseif ( $results['headers']['http_code'] == 200 || 
$results['headers']['http_code'] == 403 ) {
-                               self::log( $this->getData( 
'contribution_tracking_id' ) . ' Finished sending transaction to ' . 
self::getGatewayName() );
+                               self::log( $this->getData_Raw( 
'contribution_tracking_id' ) . ' Finished sending transaction to ' . 
self::getGatewayName() );
                                break;
                        }
                }
@@ -1092,7 +1093,7 @@
                        //TODO: i18n here! 
                        //TODO: But also, fire off some kind of "No response 
from the gateway" thing to somebody so we know right away. 
                        $results['message'] = 'No response from ' . 
self::getGatewayName() . '.  Please try again later!';
-                       self::log( $this->getData( 'contribution_tracking_id' ) 
. ' No response from ' . self::getGatewayName() . ': ' . curl_error( $ch ) );
+                       self::log( $this->getData_Raw( 
'contribution_tracking_id' ) . ' No response from ' . self::getGatewayName() . 
': ' . curl_error( $ch ) );
                        curl_close( $ch );
                        return false;
                }
@@ -1392,7 +1393,7 @@
                        'gateway_txn_id' => $this->getTransactionGatewayTxnID(),
                        //'language' => '',
                );
-               $transaction += $this->getDisplayData();
+               $transaction += $this->getData_Raw();
 
                try {
                        wfRunHooks( $hook, array( $transaction ) );
@@ -1404,9 +1405,10 @@
        function smooshVarsForStaging() {
 
                foreach ( $this->staged_vars as $field ) {
-                       if ( !array_key_exists( $field, $this->postdata ) || 
empty( $this->postdata[$field] ) ) {
+                       $val = $this->getData_Staged( $field );
+                       if ( is_null( $val ) or $val === '' ) {
                                if ( array_key_exists( $field, 
$this->postdatadefaults ) ) {
-                                       $this->postdata[$field] = 
$this->postdatadefaults[$field];
+                                       $this->staged_data[$field] = 
$this->postdatadefaults[$field];
                                }
                        }
                        //what do we do in the event that we're still nothing? 
(just move on.)
@@ -1445,7 +1447,7 @@
        }
 
        function getPaypalRedirectURL() {
-               $currency = $this->getData( 'currency' );
+               $currency = $this->getData_Raw( 'currency' );
 
                // update the utm source to set the payment instrument to pp 
rather than cc
                $data['payment_method'] = 'pp';
@@ -1457,7 +1459,7 @@
                //update contribution tracking
                $this->dataObj->updateContributionTracking( true );
 
-               $ret = self::getGlobal( "PaypalURL" ) . "/" . 
$this->postdata['language'] . "?gateway=paypal&" . http_build_query( 
$this->getPaypalData() );
+               $ret = self::getGlobal( "PaypalURL" ) . "/" . 
$this->staged_data['language'] . "?gateway=paypal&" . http_build_query( 
$this->getPaypalData() );
                self::log( $ret );
                return $ret;
        }
@@ -1495,9 +1497,9 @@
                );
                $ret = array();
                foreach ( $paypalkeys as $key ){
-                       $val = $this->getDisplayData( $key );
+                       $val = $this->getData_Raw( $key );
                        if (!is_null( $val )){
-                               $ret[$key] = $this->getDisplayData( $key );
+                               $ret[$key] = $this->getData_Raw( $key );
                        }
                }
                return $ret;
@@ -1735,9 +1737,9 @@
         */
        function runPreProcessHooks() {
                // allow any external validators to have their way with the data
-               self::log( $this->getData( 'contribution_tracking_id' ) . " 
Preparing to query MaxMind" );
+               self::log( $this->getData_Raw( 'contribution_tracking_id' ) . " 
Preparing to query MaxMind" );
                wfRunHooks( 'GatewayValidate', array( &$this ) );
-               self::log( $this->getData( 'contribution_tracking_id' ) . ' 
Finished querying Maxmind' );
+               self::log( $this->getData_Raw( 'contribution_tracking_id' ) . ' 
Finished querying Maxmind' );
 
                //DO NOT set some variable as getValidationAction() here, and 
keep 
                //checking that. getValidationAction could change with each one 
of these 
@@ -1806,9 +1808,9 @@
 
        /**
         * Instead of pulling all the DonationData back through to update one 
local 
-        * value, use this. It updates both postdata (which is intended to be 
-        * staged for the gateway) and displaydata (which could potentially 
become 
-        * staged for the user). 
+        * value, use this. It updates both staged_data (which is intended to 
be 
+        * staged and used _just_ by the gateway) and raw_data, which is 
actually 
+        * just normalized and sanitized form data as entered by the user. 
         * 
         * TODO: handle the cases where $val is listed in the gateway adapter's 
         * staged_vars. 
@@ -1821,11 +1823,11 @@
        function refreshGatewayValueFromSource( $val ) {
                $refreshed = $this->dataObj->getVal( $val );
                if ( !is_null($refreshed) ){
-                       $this->postdata[$val] = $refreshed;
-                       $this->displaydata[$val] = $refreshed;
+                       $this->staged_data[$val] = $refreshed;
+                       $this->raw_data[$val] = $refreshed;
                } else {
-                       unset( $this->postdata[$val] );
-                       unset( $this->displaydata[$val] );
+                       unset( $this->staged_data[$val] );
+                       unset( $this->raw_data[$val] );
                }
        }
 

Modified: trunk/extensions/DonationInterface/gateway_forms/Form.php
===================================================================
--- trunk/extensions/DonationInterface/gateway_forms/Form.php   2011-11-04 
18:55:17 UTC (rev 102029)
+++ trunk/extensions/DonationInterface/gateway_forms/Form.php   2011-11-04 
19:37:01 UTC (rev 102030)
@@ -84,7 +84,7 @@
 
                $this->gateway = & $gateway;
                $this->test = $this->gateway->getGlobal( "Test" );
-               $this->form_data = $this->gateway->getDisplayData();
+               $this->form_data = $this->gateway->getData_Raw();
                $this->form_errors = & $error;
 
                /**

Modified: 
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
===================================================================
--- 
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
  2011-11-04 18:55:17 UTC (rev 102029)
+++ 
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
  2011-11-04 19:37:01 UTC (rev 102030)
@@ -767,7 +767,7 @@
                $xmlString = $this->stripXMLResponseHeaders( $rawResponse );
                $displayXML = $this->formatXmlString( $xmlString );
                $realXML = new DomDocument( '1.0' );
-               self::log( $this->getData( 'contribution_tracking_id' ) . ": 
Raw XML Response:\n" . $displayXML ); //I am apparently a huge fibber.
+               self::log( $this->getData_Raw( 'contribution_tracking_id' ) . 
": Raw XML Response:\n" . $displayXML ); //I am apparently a huge fibber.
                $realXML->loadXML( trim( $xmlString ) );
                return $realXML;
        }
@@ -961,7 +961,7 @@
                //set the transaction result message
                $responseStatus = isset( $response['STATUSID'] ) ? 
$response['STATUSID'] : '';
                $this->setTransactionResult( "Response Status: " . 
$responseStatus, 'txn_message' ); //TODO: Translate for GC. 
-               $this->setTransactionResult( $this->getData( 'order_id' ), 
'gateway_txn_id' );
+               $this->setTransactionResult( $this->getData_Raw( 'order_id' ), 
'gateway_txn_id' );
        }
 
        /**
@@ -995,10 +995,10 @@
        protected function stage_amount( $type = 'request' ) {
                switch ( $type ) {
                        case 'request':
-                               $this->postdata['amount'] = 
$this->postdata['amount'] * 100;
+                               $this->staged_data['amount'] = 
$this->staged_data['amount'] * 100;
                                break;
                        case 'response':
-                               $this->postdata['amount'] = 
$this->postdata['amount'] / 100;
+                               $this->staged_data['amount'] = 
$this->staged_data['amount'] / 100;
                                break;
                }
        }
@@ -1010,8 +1010,8 @@
         */
        protected function stage_card_num( $type = 'request' ) {
                //I realize that the $type isn't used. Voodoo.
-               if ( array_key_exists( 'card_num', $this->postdata ) ) {
-                       $this->postdata['card_num'] = str_replace( ' ', '', 
$this->postdata['card_num'] );
+               if ( array_key_exists( 'card_num', $this->staged_data ) ) {
+                       $this->staged_data['card_num'] = str_replace( ' ', '', 
$this->staged_data['card_num'] );
                }
        }
 
@@ -1041,10 +1041,11 @@
                        $types = array_flip( $types );
                }
 
-               if ( ( array_key_exists( 'card_type', $this->postdata ) ) && 
array_key_exists( $this->postdata['card_type'], $types ) ) {
-                       $this->postdata['card_type'] = 
$types[$this->postdata['card_type']];
+               $card_type = $this->getData_Staged('card_type');
+               if ( ( !is_null( $card_type ) ) && array_key_exists( 
$card_type, $types ) ) {
+                       $this->staged_data['card_type'] = $types[$card_type];
                } else {
-                       //$this->postdata['card_type'] = '';
+                       //$this->staged_data['card_type'] = '';
                        //iono: maybe nothing? 
                }
        }
@@ -1061,15 +1062,15 @@
         */
        protected function stage_payment_method( $type = 'request' ) {
                
-               $payment_method = array_key_exists( 'payment_method', 
$this->postdata ) ? $this->postdata['payment_method']: false;
-               $payment_submethod = array_key_exists( 'payment_submethod', 
$this->postdata ) ? $this->postdata['payment_submethod']: false;
+               $payment_method = array_key_exists( 'payment_method', 
$this->staged_data ) ? $this->staged_data['payment_method']: false;
+               $payment_submethod = array_key_exists( 'payment_submethod', 
$this->staged_data ) ? $this->staged_data['payment_submethod']: false;
 
                // These will be grouped and ordred by payment product id
                switch ( $payment_submethod )  {
                        
                        /* Bank transfer */
                        case 'bt':
-                               $this->postdata['payment_product'] = 
$this->payment_submethods[ $payment_submethod ]['paymentproductid'];
+                               $this->staged_data['payment_product'] = 
$this->payment_submethods[ $payment_submethod ]['paymentproductid'];
                                $this->var_map['PAYMENTPRODUCTID'] = 
'payment_product';
                                break;
 
@@ -1083,12 +1084,12 @@
                        case 'dd_ch':
                        case 'dd_it':
                        case 'dd_es':
-                               $this->postdata['payment_product'] = 
$this->payment_submethods[ $payment_submethod ]['paymentproductid'];
+                               $this->staged_data['payment_product'] = 
$this->payment_submethods[ $payment_submethod ]['paymentproductid'];
                                $this->var_map['PAYMENTPRODUCTID'] = 
'payment_product';
                                $this->var_map['COUNTRYCODEBANK'] = 'country';
 
                                // Currently, this is needed by the Netherlands
-                               $this->postdata['transaction_type'] = '01';
+                               $this->staged_data['transaction_type'] = '01';
 
                                
$this->transactions['INSERT_ORDERWITHPAYMENT']['request']['REQUEST']['PARAMS']['PAYMENT'][]
 = 'ACCOUNTNAME';
                                
$this->transactions['INSERT_ORDERWITHPAYMENT']['request']['REQUEST']['PARAMS']['PAYMENT'][]
 = 'ACCOUNTNUMBER';
@@ -1109,13 +1110,13 @@
                        case 'rtbt_nordea_sweeden':
                        case 'rtbt_enets':
                        case 'rtbt_sofortuberweisung':
-                               $this->postdata['payment_product'] = 
$this->payment_submethods[ $payment_submethod ]['paymentproductid'];
+                               $this->staged_data['payment_product'] = 
$this->payment_submethods[ $payment_submethod ]['paymentproductid'];
                                $this->var_map['PAYMENTPRODUCTID'] = 
'payment_product';
                                break;
                        
                        case 'rtbt_eps':
                        case 'rtbt_ideal':
-                               $this->postdata['payment_product'] = 
$this->payment_submethods[ $payment_submethod ]['paymentproductid'];
+                               $this->staged_data['payment_product'] = 
$this->payment_submethods[ $payment_submethod ]['paymentproductid'];
                                $this->var_map['PAYMENTPRODUCTID'] = 
'payment_product';
                                
                                // Add the ISSUERID field if it does not exist
@@ -1126,7 +1127,7 @@
                                
                        /* Default Case */
                        default:
-                               //$this->postdata['payment_product'] = 
$this->payment_submethods[ $payment_submethod ]['paymentproductid'];
+                               //$this->staged_data['payment_product'] = 
$this->payment_submethods[ $payment_submethod ]['paymentproductid'];
                                //$this->var_map['PAYMENTPRODUCTID'] = 
'payment_product';
                                break;
                }
@@ -1143,21 +1144,22 @@
                        //TODO: This needs to be more robust (like actually 
pulling the 
                        //qstring keys, resetting the values, and putting it 
all back)
                        //but for now it'll keep us alive. 
-                       if ( !strpos( $this->postdata['returnto'], 'order_id' ) 
){
-                               $queryArray = array( 'order_id' => 
$this->postdata['order_id'] );
-                               $this->postdata['returnto'] = wfAppendQuery( 
$this->postdata['returnto'], $queryArray );
+                       $returnto = $this->getData_Staged( 'returnto' );
+                       if ( !is_null( $returnto ) && !strpos( $returnto, 
'order_id' ) ){
+                               $queryArray = array( 'order_id' => 
$this->staged_data['order_id'] );
+                               $this->staged_data['returnto'] = wfAppendQuery( 
$returnto, $queryArray );
                        }
                }
        }
        
        protected function pre_process_insert_orderwithpayment(){
-               if ( $this->getData( 'payment_method' ) === 'cc' ){
+               if ( $this->getData_Raw( 'payment_method' ) === 'cc' ){
                        $this->addDonorDataToSession();
                }
        }
        
        protected function pre_process_get_orderstatus(){
-               if  ( $this->getData( 'payment_method' ) === 'cc' ){
+               if  ( $this->getData_Raw( 'payment_method' ) === 'cc' ){
                        $this->runPreProcessHooks();
                }
        }
@@ -1171,7 +1173,7 @@
         * determine if we want to fail the transaction ourselves or not. 
         */
        public function getCVVResult(){
-               if ( is_null( $this->getData( 'cvv_result' ) ) ){
+               if ( is_null( $this->getData_Raw( 'cvv_result' ) ) ){
                        return null;
                }
                
@@ -1185,7 +1187,7 @@
                        '0' => true, //No service available.
                );
                
-               $result = $result_map[$this->getData( 'cvv_result' )];
+               $result = $result_map[$this->getData_Raw( 'cvv_result' )];
                return $result;
 
        }       
@@ -1195,7 +1197,7 @@
         * determine if we want to fail the transaction ourselves or not. 
         */
        public function getAVSResult(){
-               if ( is_null( $this->getData( 'avs_result' ) ) ){
+               if ( is_null( $this->getData_Raw( 'avs_result' ) ) ){
                        return null;
                }
                //Best guess here: 
@@ -1223,7 +1225,7 @@
                        '0' => 50, //No service available.
                );              
 
-               $result = $result_map[$this->getData( 'avs_result' )];
+               $result = $result_map[$this->getData_Raw( 'avs_result' )];
                return $result;
        }
 

Modified: 
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php
===================================================================
--- 
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php
     2011-11-04 18:55:17 UTC (rev 102029)
+++ 
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php
     2011-11-04 19:37:01 UTC (rev 102030)
@@ -86,7 +86,7 @@
 
                        //TODO: Get rid of $data out here completely, by 
putting this logic inside the adapter somewhere. 
                        //All we seem to be doing with it now, is internal 
adapter logic outside of the adapter. 
-                       $data = $this->adapter->getDisplayData();
+                       $data = $this->adapter->getData_Raw();
 
                        if ( $this->adapter->posted ) {
                                
@@ -119,7 +119,7 @@
                                                
                                                // Display an iframe for credit 
cards
                                                if ( 
$this->executeIframeForCreditCard() ) {
-                                                       
+                                                       
$this->displayResultsForDebug();
                                                        // Nothing left to 
process
                                                        return;
                                                }

Modified: 
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php
===================================================================
--- 
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php
      2011-11-04 18:55:17 UTC (rev 102029)
+++ 
trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php
      2011-11-04 19:37:01 UTC (rev 102030)
@@ -62,7 +62,7 @@
                if ( $this->adapter->checkTokens() ) {
                        // Display form for the first time
                        $oid = $wgRequest->getText( 'order_id' );
-                       $adapter_oid = $this->adapter->getData();
+                       $adapter_oid = $this->adapter->getData_Raw();
                        $adapter_oid = $adapter_oid['order_id'];
                        if ( $oid && !empty( $oid ) && $oid === $adapter_oid ) {
                                if ( !array_key_exists( 'order_status', 
$_SESSION ) || !array_key_exists( $oid, $_SESSION['order_status'] ) ) {
@@ -106,7 +106,7 @@
        function getDeclinedResultPage() {
                global $wgOut;
                
-               $displayData = $this->adapter->getDisplayData();
+               $displayData = $this->adapter->getData_Raw();
                $failpage = $this->adapter->getGlobal( 'FailPage' );
 
                if ( $failpage ) {

Modified: 
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php
===================================================================
--- 
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php    
    2011-11-04 18:55:17 UTC (rev 102029)
+++ 
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php    
    2011-11-04 19:37:01 UTC (rev 102030)
@@ -251,15 +251,15 @@
 
        protected function stage_card_num( $type = 'request' ) {
                //I realize that the $type isn't used. Voodoo.
-               $this->postdata['card_num'] = str_replace( ' ', '', 
$this->postdata['card_num'] );
+               $this->staged_data['card_num'] = str_replace( ' ', '', 
$this->staged_data['card_num'] );
        }
 
        //TODO: Something much fancier here. 
        protected function stage_user_ip( $type = 'request' ) {
-               if ( $this->postdata['user_ip'] === '127.0.0.1' ) {
-                       global $wgDonationInterfaceIPAddress;
-                       if ( !empty( $wgDonationInterfaceIPAddress ) ) {
-                               $this->postdata['user_ip'] = 
$wgDonationInterfaceIPAddress;
+               if ( $this->staged_data['user_ip'] === '127.0.0.1' ) {
+                       $ipAddress = $this->getGlobal( 'IPAddress' );
+                       if ( !empty( $ipAddress ) ) {
+                               $this->staged_data['user_ip'] = $ipAddress;
                        }
                }
        }

Modified: 
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
===================================================================
--- 
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
   2011-11-04 18:55:17 UTC (rev 102029)
+++ 
trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
   2011-11-04 19:37:01 UTC (rev 102030)
@@ -90,32 +90,31 @@
                        }
                }
 
-               $oid = $this->adapter->getData( 'order_id' );
-               $i_oid = $this->adapter->getData( 'i_order_id' );
-               $data = $this->adapter->getData();
+               $data = $this->adapter->getData_Raw();
+               $msgPrefix = $data['order_id'] . ' ' . $data['i_order_id'] . ' 
';
 
                // if approved, display results and send transaction to the 
queue
                if ( $errorCode == '1' ) {
-                       $this->log( $oid . " " . $i_oid . " Transaction 
approved.", LOG_DEBUG );
+                       $this->log( $msgPrefix . "Transaction approved.", 
LOG_DEBUG );
                        $this->fnPayflowDisplayApprovedResults( $data, 
$responseMsg );
                        // give user a second chance to enter incorrect data
                } elseif ( ( $errorCode == '3' ) && ( $data['numAttempt'] < '5' 
) ) {
-                       $this->log( $oid . " " . $i_oid . " Transaction 
unsuccessful (invalid info).", LOG_DEBUG );
+                       $this->log( $msgPrefix . "Transaction unsuccessful 
(invalid info).", LOG_DEBUG );
                        // pass responseMsg as an array key as required by 
displayForm
                        $this->errors['retryMsg'] = $responseMsg;
                        $this->displayForm( $this->errors );
                        // if declined or if user has already made two 
attempts, decline
                } elseif ( ( $errorCode == '2' ) || ( $data['numAttempt'] >= 
'3' ) ) {
-                       $this->log( $oid . " " . $i_oid . " Transaction 
declined.", LOG_DEBUG );
+                       $this->log( $msgPrefix . "Transaction declined.", 
LOG_DEBUG );
                        $this->fnPayflowDisplayDeclinedResults( $responseMsg );
                } elseif ( ( $errorCode == '4' ) ) {
-                       $this->log( $oid . " " . $i_oid . " Transaction 
unsuccessful.", LOG_DEBUG );
+                       $this->log( $msgPrefix . "Transaction unsuccessful.", 
LOG_DEBUG );
                        $this->fnPayflowDisplayOtherResults( $responseMsg );
                } elseif ( ( $errorCode == '5' ) ) {
-                       $this->log( $oid . " " . $i_oid . " Transaction 
pending.", LOG_DEBUG );
+                       $this->log( $msgPrefix . "Transaction pending.", 
LOG_DEBUG );
                        $this->fnPayflowDisplayPending( $data, $responseMsg );
                } elseif ( ( $errorCode == '1000000' ) ) { //TODO: This is 
temporary until we can decide on the actual error codes WE control.
-                       $this->log( $oid . " " . $i_oid . " Transaction 
unsuccessful (communication failure).", LOG_DEBUG );
+                       $this->log( $msgPrefix . "Transaction unsuccessful 
(communication failure).", LOG_DEBUG );
                        $this->fnPayflowDisplayOtherResults( $responseMsg );
                        $this->errors['retryMsg'] = $responseMsg;
                        $this->displayForm( $this->errors );

Modified: 
trunk/extensions/DonationInterface/tests/Adapter/GatewayAdapterTestCase.php
===================================================================
--- trunk/extensions/DonationInterface/tests/Adapter/GatewayAdapterTestCase.php 
2011-11-04 18:55:17 UTC (rev 102029)
+++ trunk/extensions/DonationInterface/tests/Adapter/GatewayAdapterTestCase.php 
2011-11-04 19:37:01 UTC (rev 102030)
@@ -112,6 +112,9 @@
                
                $gateway = new $testAdapter( $options );
 
+               //please define this function only inside the 
TESTS_ADAPTER_DEFAULT, 
+               //which should be a test adapter object that descende from one 
of the 
+               //production adapters. 
         $this->assertInstanceOf( 'DonationData', $gateway->getDonationData() );
        }
 }

Modified: trunk/extensions/DonationInterface/tests/DonationInterfaceTestCase.php
===================================================================
--- trunk/extensions/DonationInterface/tests/DonationInterfaceTestCase.php      
2011-11-04 18:55:17 UTC (rev 102029)
+++ trunk/extensions/DonationInterface/tests/DonationInterfaceTestCase.php      
2011-11-04 19:37:01 UTC (rev 102030)
@@ -52,7 +52,6 @@
         * @covers GatewayAdapter::__construct
         * @covers GatewayAdapter::setCurrentTransaction
         * @covers GatewayAdapter::buildRequestXML
-        * @covers GatewayAdapter::getData
         */
        public function buildRequestXmlForGlobalCollect( $optionsForTestData, 
$options ) {
 
@@ -275,7 +274,7 @@
         */
        public function getExpectedXmlRequestForGlobalCollect( 
$optionsForTestData, $options = array() ) {
 
-               $orderId = $this->gatewayAdapter->getData( 'order_id' );
+               $orderId = $this->gatewayAdapter->getData_Raw( 'order_id' );
 
                $expected  = '<?xml version="1.0"?>' . "\n";
                $expected .= '<XML>';


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to