r102030 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102029‎ | r102030 | r102031 >
Date:19:37, 4 November 2011
Author:khorn
Status:ok
Tags:fundraising 
Comment:
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 (modified) (history)
  • /trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/minfraud/minfraud.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/recaptcha/recaptcha.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_common/GatewayForm.php (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_common/donation.api.php (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_forms/Form.php (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/tests/Adapter/GatewayAdapterTestCase.php (modified) (history)
  • /trunk/extensions/DonationInterface/tests/DonationInterfaceTestCase.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/tests/Adapter/GatewayAdapterTestCase.php
@@ -112,6 +112,9 @@
113113
114114 $gateway = new $testAdapter( $options );
115115
 116+ //please define this function only inside the TESTS_ADAPTER_DEFAULT,
 117+ //which should be a test adapter object that descende from one of the
 118+ //production adapters.
116119 $this->assertInstanceOf( 'DonationData', $gateway->getDonationData() );
117120 }
118121 }
Index: trunk/extensions/DonationInterface/tests/DonationInterfaceTestCase.php
@@ -52,7 +52,6 @@
5353 * @covers GatewayAdapter::__construct
5454 * @covers GatewayAdapter::setCurrentTransaction
5555 * @covers GatewayAdapter::buildRequestXML
56 - * @covers GatewayAdapter::getData
5756 */
5857 public function buildRequestXmlForGlobalCollect( $optionsForTestData, $options ) {
5958
@@ -275,7 +274,7 @@
276275 */
277276 public function getExpectedXmlRequestForGlobalCollect( $optionsForTestData, $options = array() ) {
278277
279 - $orderId = $this->gatewayAdapter->getData( 'order_id' );
 278+ $orderId = $this->gatewayAdapter->getData_Raw( 'order_id' );
280279
281280 $expected = '<?xml version="1.0"?>' . "\n";
282281 $expected .= '<XML>';
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
@@ -90,32 +90,31 @@
9191 }
9292 }
9393
94 - $oid = $this->adapter->getData( 'order_id' );
95 - $i_oid = $this->adapter->getData( 'i_order_id' );
96 - $data = $this->adapter->getData();
 94+ $data = $this->adapter->getData_Raw();
 95+ $msgPrefix = $data['order_id'] . ' ' . $data['i_order_id'] . ' ';
9796
9897 // if approved, display results and send transaction to the queue
9998 if ( $errorCode == '1' ) {
100 - $this->log( $oid . " " . $i_oid . " Transaction approved.", LOG_DEBUG );
 99+ $this->log( $msgPrefix . "Transaction approved.", LOG_DEBUG );
101100 $this->fnPayflowDisplayApprovedResults( $data, $responseMsg );
102101 // give user a second chance to enter incorrect data
103102 } elseif ( ( $errorCode == '3' ) && ( $data['numAttempt'] < '5' ) ) {
104 - $this->log( $oid . " " . $i_oid . " Transaction unsuccessful (invalid info).", LOG_DEBUG );
 103+ $this->log( $msgPrefix . "Transaction unsuccessful (invalid info).", LOG_DEBUG );
105104 // pass responseMsg as an array key as required by displayForm
106105 $this->errors['retryMsg'] = $responseMsg;
107106 $this->displayForm( $this->errors );
108107 // if declined or if user has already made two attempts, decline
109108 } elseif ( ( $errorCode == '2' ) || ( $data['numAttempt'] >= '3' ) ) {
110 - $this->log( $oid . " " . $i_oid . " Transaction declined.", LOG_DEBUG );
 109+ $this->log( $msgPrefix . "Transaction declined.", LOG_DEBUG );
111110 $this->fnPayflowDisplayDeclinedResults( $responseMsg );
112111 } elseif ( ( $errorCode == '4' ) ) {
113 - $this->log( $oid . " " . $i_oid . " Transaction unsuccessful.", LOG_DEBUG );
 112+ $this->log( $msgPrefix . "Transaction unsuccessful.", LOG_DEBUG );
114113 $this->fnPayflowDisplayOtherResults( $responseMsg );
115114 } elseif ( ( $errorCode == '5' ) ) {
116 - $this->log( $oid . " " . $i_oid . " Transaction pending.", LOG_DEBUG );
 115+ $this->log( $msgPrefix . "Transaction pending.", LOG_DEBUG );
117116 $this->fnPayflowDisplayPending( $data, $responseMsg );
118117 } elseif ( ( $errorCode == '1000000' ) ) { //TODO: This is temporary until we can decide on the actual error codes WE control.
119 - $this->log( $oid . " " . $i_oid . " Transaction unsuccessful (communication failure).", LOG_DEBUG );
 118+ $this->log( $msgPrefix . "Transaction unsuccessful (communication failure).", LOG_DEBUG );
120119 $this->fnPayflowDisplayOtherResults( $responseMsg );
121120 $this->errors['retryMsg'] = $responseMsg;
122121 $this->displayForm( $this->errors );
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro.adapter.php
@@ -251,15 +251,15 @@
252252
253253 protected function stage_card_num( $type = 'request' ) {
254254 //I realize that the $type isn't used. Voodoo.
255 - $this->postdata['card_num'] = str_replace( ' ', '', $this->postdata['card_num'] );
 255+ $this->staged_data['card_num'] = str_replace( ' ', '', $this->staged_data['card_num'] );
256256 }
257257
258258 //TODO: Something much fancier here.
259259 protected function stage_user_ip( $type = 'request' ) {
260 - if ( $this->postdata['user_ip'] === '127.0.0.1' ) {
261 - global $wgDonationInterfaceIPAddress;
262 - if ( !empty( $wgDonationInterfaceIPAddress ) ) {
263 - $this->postdata['user_ip'] = $wgDonationInterfaceIPAddress;
 260+ if ( $this->staged_data['user_ip'] === '127.0.0.1' ) {
 261+ $ipAddress = $this->getGlobal( 'IPAddress' );
 262+ if ( !empty( $ipAddress ) ) {
 263+ $this->staged_data['user_ip'] = $ipAddress;
264264 }
265265 }
266266 }
Index: trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php
@@ -60,7 +60,7 @@
6161 $this->gateway_adapter->setValidationAction( $localAction );
6262
6363 $log_msg = '"' . $localAction . "\"\t\"" . $this->risk_score . "\"";
64 - $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Filtered', $log_msg );
 64+ $this->log( $this->gateway_adapter->getData_Raw( 'contribution_tracking_id' ), 'Filtered', $log_msg );
6565 return TRUE;
6666 }
6767
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php
@@ -21,7 +21,7 @@
2222
2323 public function filter() {
2424 // pull out the source from the filter object
25 - $source = $this->gateway_adapter->getData( 'utm_source' );
 25+ $source = $this->gateway_adapter->getData_Raw( 'utm_source' );
2626
2727 // a very complex filtering algorithm for sources
2828 $srcRules = $this->gateway_adapter->getGlobal( 'CustomFiltersSrcRules' );
@@ -38,7 +38,7 @@
3939 $log_msg .= "\t\"" . addslashes( $regex ) . "\"";
4040 $log_msg .= "\t\"" . $this->cfo->risk_score . "\"";
4141 $this->log(
42 - $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Filter: Source', $log_msg
 42+ $this->gateway_adapter->getData_Raw( 'contribution_tracking_id' ), 'Filter: Source', $log_msg
4343 );
4444 }
4545 }
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php
@@ -17,7 +17,7 @@
1818 return TRUE;
1919 }
2020
21 - $minfraud_query = $this->build_query( $this->gateway_adapter->getData() );
 21+ $minfraud_query = $this->build_query( $this->gateway_adapter->getData_Raw() );
2222 $this->query_minfraud( $minfraud_query );
2323
2424
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php
@@ -21,7 +21,7 @@
2222
2323 public function filter() {
2424 // pull out the referrer from the gateway_adapter
25 - $referrer = $this->gateway_adapter->getData( 'referrer' );
 25+ $referrer = $this->gateway_adapter->getData_Raw( 'referrer' );
2626
2727 // a very complex filtering algorithm for referrers
2828 $refRules = $this->gateway_adapter->getGlobal( 'CustomFiltersRefRules' );
@@ -38,7 +38,7 @@
3939 $log_msg .= "\t\"" . addslashes( $regex ) . "\"";
4040 $log_msg .= "\t\"" . $this->cfo->risk_score . "\"";
4141 $this->log(
42 - $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Filter: Referrer', $log_msg
 42+ $this->gateway_adapter->getData_Raw( 'contribution_tracking_id' ), 'Filter: Referrer', $log_msg
4343 );
4444 }
4545 }
Index: trunk/extensions/DonationInterface/extras/minfraud/minfraud.body.php
@@ -68,7 +68,7 @@
6969 return TRUE;
7070 }
7171
72 - $minfraud_query = $this->build_query( $this->gateway_adapter->getData() );
 72+ $minfraud_query = $this->build_query( $this->gateway_adapter->getData_Raw() );
7373 $this->query_minfraud( $minfraud_query );
7474 $localAction = $this->determine_action( $this->minfraud_response['riskScore'] );
7575 $this->gateway_adapter->setValidationAction( $localAction );
@@ -76,7 +76,7 @@
7777 // reset the data hash
7878 $this->gateway_adapter->unsetHash();
7979 $this->gateway_adapter->setActionHash( $this->generate_hash( $localAction ) );
80 - $this->gateway_adapter->setHash( $this->generate_hash( $this->gateway_adapter->getData() ) );
 80+ $this->gateway_adapter->setHash( $this->generate_hash( $this->gateway_adapter->getData_Raw() ) );
8181
8282 // Write the query/response to the log
8383 $this->log_query( $minfraud_query, $localAction );
@@ -88,13 +88,13 @@
8989 */
9090 public function log_query( $minfraud_query, $action ) {
9191 if ( $this->log_fh ) {
92 - $log_message = '"' . addslashes( $this->gateway_adapter->getData( 'comment' ) ) . '"';
93 - $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getData( 'amount' ) . ' ' . $this->gateway_adapter->getData( 'currency' ) ) . '"';
 92+ $log_message = '"' . addslashes( $this->gateway_adapter->getData_Raw( 'comment' ) ) . '"';
 93+ $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getData_Raw( 'amount' ) . ' ' . $this->gateway_adapter->getData_Raw( 'currency' ) ) . '"';
9494 $log_message .= "\t" . '"' . addslashes( json_encode( $minfraud_query ) ) . '"';
9595 $log_message .= "\t" . '"' . addslashes( json_encode( $this->minfraud_response ) ) . '"';
9696 $log_message .= "\t" . '"' . addslashes( $action ) . '"';
97 - $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getData( 'referrer' ) ) . '"';
98 - $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'minFraud query', $log_message );
 97+ $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getData_Raw( 'referrer' ) ) . '"';
 98+ $this->log( $this->gateway_adapter->getData_Raw( 'contribution_tracking_id' ), 'minFraud query', $log_message );
9999 }
100100 }
101101
@@ -111,7 +111,7 @@
112112 */
113113 public function can_bypass_minfraud() {
114114 // if the data bits data_hash and action are not set, we need to hit minFraud
115 - $localdata = $this->gateway_adapter->getData();
 115+ $localdata = $this->gateway_adapter->getData_Raw();
116116 if ( !strlen( $localdata['data_hash'] ) || !strlen( $localdata['action'] ) ) {
117117 return FALSE;
118118 }
@@ -123,7 +123,7 @@
124124 // compare the data hash to make sure it's legit
125125 if ( $this->compare_hash( $data_hash, serialize( $localdata ) ) ) {
126126
127 - $this->gateway_adapter->setHash( $this->generate_hash( $this->gateway_adapter->getData() ) ); // hash the data array
 127+ $this->gateway_adapter->setHash( $this->generate_hash( $this->gateway_adapter->getData_Raw() ) ); // hash the data array
128128 // check to see if we have a valid action set for us to bypass minfraud
129129 $actions = array( 'process', 'challenge', 'review', 'reject' );
130130 $action_hash = $localdata['action']; // a hash of the action to take passed in by the form submission
Index: trunk/extensions/DonationInterface/extras/conversion_log/conversion_log.body.php
@@ -11,7 +11,7 @@
1212 // if the trxn has been outright rejected, log it
1313 if ( $this->gateway_adapter->getValidationAction() == 'reject' ) {
1414 $this->log(
15 - $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Rejected'
 15+ $this->gateway_adapter->getData_Raw( 'contribution_tracking_id' ), 'Rejected'
1616 );
1717 return TRUE;
1818 }
@@ -21,7 +21,7 @@
2222 return FALSE;
2323
2424 $this->log(
25 - $this->gateway_adapter->getData( 'contribution_tracking_id' ), "Gateway response: " . addslashes( $this->gateway_adapter->getTransactionMessage() ), '"' . addslashes( json_encode( $this->gateway_adapter->getTransactionData() ) ) . '"'
 25+ $this->gateway_adapter->getData_Raw( 'contribution_tracking_id' ), "Gateway response: " . addslashes( $this->gateway_adapter->getTransactionMessage() ), '"' . addslashes( json_encode( $this->gateway_adapter->getTransactionData() ) ) . '"'
2626 );
2727 return TRUE;
2828 }
Index: trunk/extensions/DonationInterface/extras/recaptcha/recaptcha.body.php
@@ -42,12 +42,12 @@
4343 $captcha_resp = $this->check_captcha();
4444 if ( $captcha_resp->is_valid ) {
4545 // if validated, update the action and move on
46 - $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Captcha passed' );
 46+ $this->log( $this->gateway_adapter->getData_Raw( 'contribution_tracking_id' ), 'Captcha passed' );
4747 $this->gateway_adapter->setValidationAction( 'process' );
4848 return TRUE;
4949 } else {
5050 $this->recap_err = $captcha_resp->error;
51 - $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Captcha failed' );
 51+ $this->log( $this->gateway_adapter->getData_Raw( 'contribution_tracking_id' ), 'Captcha failed' );
5252 }
5353 }
5454 // display captcha
@@ -64,7 +64,7 @@
6565 $useSSL = $this->gateway_adapter->getGlobal( 'RecaptchaUseSSL' );
6666
6767 // log that a captcha's been triggered
68 - $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Captcha triggered' );
 68+ $this->log( $this->gateway_adapter->getData_Raw( 'contribution_tracking_id' ), 'Captcha triggered' );
6969
7070 // construct the HTML used to display the captcha
7171 $captcha_html = Xml::openElement( 'div', array( 'id' => 'mw-donate-captcha' ) );
@@ -76,7 +76,7 @@
7777
7878 //TODO: use setValidationErrors and getValidationErrors everywhere, and
7979 //refactor all the form constructors one more time. Eventually.
80 - $data = $this->gateway_adapter->getData();
 80+ $data = $this->gateway_adapter->getData_Raw();
8181 $errors = $this->gateway_adapter->getValidationErrors();
8282 $form_obj = new $form_class( $this->gateway_adapter, $errors );
8383
Index: trunk/extensions/DonationInterface/gateway_forms/Form.php
@@ -84,7 +84,7 @@
8585
8686 $this->gateway = & $gateway;
8787 $this->test = $this->gateway->getGlobal( "Test" );
88 - $this->form_data = $this->gateway->getDisplayData();
 88+ $this->form_data = $this->gateway->getData_Raw();
8989 $this->form_errors = & $error;
9090
9191 /**
Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php
@@ -62,7 +62,7 @@
6363 if ( $this->adapter->checkTokens() ) {
6464 // Display form for the first time
6565 $oid = $wgRequest->getText( 'order_id' );
66 - $adapter_oid = $this->adapter->getData();
 66+ $adapter_oid = $this->adapter->getData_Raw();
6767 $adapter_oid = $adapter_oid['order_id'];
6868 if ( $oid && !empty( $oid ) && $oid === $adapter_oid ) {
6969 if ( !array_key_exists( 'order_status', $_SESSION ) || !array_key_exists( $oid, $_SESSION['order_status'] ) ) {
@@ -106,7 +106,7 @@
107107 function getDeclinedResultPage() {
108108 global $wgOut;
109109
110 - $displayData = $this->adapter->getDisplayData();
 110+ $displayData = $this->adapter->getData_Raw();
111111 $failpage = $this->adapter->getGlobal( 'FailPage' );
112112
113113 if ( $failpage ) {
Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php
@@ -86,7 +86,7 @@
8787
8888 //TODO: Get rid of $data out here completely, by putting this logic inside the adapter somewhere.
8989 //All we seem to be doing with it now, is internal adapter logic outside of the adapter.
90 - $data = $this->adapter->getDisplayData();
 90+ $data = $this->adapter->getData_Raw();
9191
9292 if ( $this->adapter->posted ) {
9393
@@ -119,7 +119,7 @@
120120
121121 // Display an iframe for credit cards
122122 if ( $this->executeIframeForCreditCard() ) {
123 -
 123+ $this->displayResultsForDebug();
124124 // Nothing left to process
125125 return;
126126 }
Index: trunk/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
@@ -767,7 +767,7 @@
768768 $xmlString = $this->stripXMLResponseHeaders( $rawResponse );
769769 $displayXML = $this->formatXmlString( $xmlString );
770770 $realXML = new DomDocument( '1.0' );
771 - self::log( $this->getData( 'contribution_tracking_id' ) . ": Raw XML Response:\n" . $displayXML ); //I am apparently a huge fibber.
 771+ self::log( $this->getData_Raw( 'contribution_tracking_id' ) . ": Raw XML Response:\n" . $displayXML ); //I am apparently a huge fibber.
772772 $realXML->loadXML( trim( $xmlString ) );
773773 return $realXML;
774774 }
@@ -961,7 +961,7 @@
962962 //set the transaction result message
963963 $responseStatus = isset( $response['STATUSID'] ) ? $response['STATUSID'] : '';
964964 $this->setTransactionResult( "Response Status: " . $responseStatus, 'txn_message' ); //TODO: Translate for GC.
965 - $this->setTransactionResult( $this->getData( 'order_id' ), 'gateway_txn_id' );
 965+ $this->setTransactionResult( $this->getData_Raw( 'order_id' ), 'gateway_txn_id' );
966966 }
967967
968968 /**
@@ -995,10 +995,10 @@
996996 protected function stage_amount( $type = 'request' ) {
997997 switch ( $type ) {
998998 case 'request':
999 - $this->postdata['amount'] = $this->postdata['amount'] * 100;
 999+ $this->staged_data['amount'] = $this->staged_data['amount'] * 100;
10001000 break;
10011001 case 'response':
1002 - $this->postdata['amount'] = $this->postdata['amount'] / 100;
 1002+ $this->staged_data['amount'] = $this->staged_data['amount'] / 100;
10031003 break;
10041004 }
10051005 }
@@ -1010,8 +1010,8 @@
10111011 */
10121012 protected function stage_card_num( $type = 'request' ) {
10131013 //I realize that the $type isn't used. Voodoo.
1014 - if ( array_key_exists( 'card_num', $this->postdata ) ) {
1015 - $this->postdata['card_num'] = str_replace( ' ', '', $this->postdata['card_num'] );
 1014+ if ( array_key_exists( 'card_num', $this->staged_data ) ) {
 1015+ $this->staged_data['card_num'] = str_replace( ' ', '', $this->staged_data['card_num'] );
10161016 }
10171017 }
10181018
@@ -1041,10 +1041,11 @@
10421042 $types = array_flip( $types );
10431043 }
10441044
1045 - if ( ( array_key_exists( 'card_type', $this->postdata ) ) && array_key_exists( $this->postdata['card_type'], $types ) ) {
1046 - $this->postdata['card_type'] = $types[$this->postdata['card_type']];
 1045+ $card_type = $this->getData_Staged('card_type');
 1046+ if ( ( !is_null( $card_type ) ) && array_key_exists( $card_type, $types ) ) {
 1047+ $this->staged_data['card_type'] = $types[$card_type];
10471048 } else {
1048 - //$this->postdata['card_type'] = '';
 1049+ //$this->staged_data['card_type'] = '';
10491050 //iono: maybe nothing?
10501051 }
10511052 }
@@ -1061,15 +1062,15 @@
10621063 */
10631064 protected function stage_payment_method( $type = 'request' ) {
10641065
1065 - $payment_method = array_key_exists( 'payment_method', $this->postdata ) ? $this->postdata['payment_method']: false;
1066 - $payment_submethod = array_key_exists( 'payment_submethod', $this->postdata ) ? $this->postdata['payment_submethod']: false;
 1066+ $payment_method = array_key_exists( 'payment_method', $this->staged_data ) ? $this->staged_data['payment_method']: false;
 1067+ $payment_submethod = array_key_exists( 'payment_submethod', $this->staged_data ) ? $this->staged_data['payment_submethod']: false;
10671068
10681069 // These will be grouped and ordred by payment product id
10691070 switch ( $payment_submethod ) {
10701071
10711072 /* Bank transfer */
10721073 case 'bt':
1073 - $this->postdata['payment_product'] = $this->payment_submethods[ $payment_submethod ]['paymentproductid'];
 1074+ $this->staged_data['payment_product'] = $this->payment_submethods[ $payment_submethod ]['paymentproductid'];
10741075 $this->var_map['PAYMENTPRODUCTID'] = 'payment_product';
10751076 break;
10761077
@@ -1083,12 +1084,12 @@
10841085 case 'dd_ch':
10851086 case 'dd_it':
10861087 case 'dd_es':
1087 - $this->postdata['payment_product'] = $this->payment_submethods[ $payment_submethod ]['paymentproductid'];
 1088+ $this->staged_data['payment_product'] = $this->payment_submethods[ $payment_submethod ]['paymentproductid'];
10881089 $this->var_map['PAYMENTPRODUCTID'] = 'payment_product';
10891090 $this->var_map['COUNTRYCODEBANK'] = 'country';
10901091
10911092 // Currently, this is needed by the Netherlands
1092 - $this->postdata['transaction_type'] = '01';
 1093+ $this->staged_data['transaction_type'] = '01';
10931094
10941095 $this->transactions['INSERT_ORDERWITHPAYMENT']['request']['REQUEST']['PARAMS']['PAYMENT'][] = 'ACCOUNTNAME';
10951096 $this->transactions['INSERT_ORDERWITHPAYMENT']['request']['REQUEST']['PARAMS']['PAYMENT'][] = 'ACCOUNTNUMBER';
@@ -1109,13 +1110,13 @@
11101111 case 'rtbt_nordea_sweeden':
11111112 case 'rtbt_enets':
11121113 case 'rtbt_sofortuberweisung':
1113 - $this->postdata['payment_product'] = $this->payment_submethods[ $payment_submethod ]['paymentproductid'];
 1114+ $this->staged_data['payment_product'] = $this->payment_submethods[ $payment_submethod ]['paymentproductid'];
11141115 $this->var_map['PAYMENTPRODUCTID'] = 'payment_product';
11151116 break;
11161117
11171118 case 'rtbt_eps':
11181119 case 'rtbt_ideal':
1119 - $this->postdata['payment_product'] = $this->payment_submethods[ $payment_submethod ]['paymentproductid'];
 1120+ $this->staged_data['payment_product'] = $this->payment_submethods[ $payment_submethod ]['paymentproductid'];
11201121 $this->var_map['PAYMENTPRODUCTID'] = 'payment_product';
11211122
11221123 // Add the ISSUERID field if it does not exist
@@ -1126,7 +1127,7 @@
11271128
11281129 /* Default Case */
11291130 default:
1130 - //$this->postdata['payment_product'] = $this->payment_submethods[ $payment_submethod ]['paymentproductid'];
 1131+ //$this->staged_data['payment_product'] = $this->payment_submethods[ $payment_submethod ]['paymentproductid'];
11311132 //$this->var_map['PAYMENTPRODUCTID'] = 'payment_product';
11321133 break;
11331134 }
@@ -1143,21 +1144,22 @@
11441145 //TODO: This needs to be more robust (like actually pulling the
11451146 //qstring keys, resetting the values, and putting it all back)
11461147 //but for now it'll keep us alive.
1147 - if ( !strpos( $this->postdata['returnto'], 'order_id' ) ){
1148 - $queryArray = array( 'order_id' => $this->postdata['order_id'] );
1149 - $this->postdata['returnto'] = wfAppendQuery( $this->postdata['returnto'], $queryArray );
 1148+ $returnto = $this->getData_Staged( 'returnto' );
 1149+ if ( !is_null( $returnto ) && !strpos( $returnto, 'order_id' ) ){
 1150+ $queryArray = array( 'order_id' => $this->staged_data['order_id'] );
 1151+ $this->staged_data['returnto'] = wfAppendQuery( $returnto, $queryArray );
11501152 }
11511153 }
11521154 }
11531155
11541156 protected function pre_process_insert_orderwithpayment(){
1155 - if ( $this->getData( 'payment_method' ) === 'cc' ){
 1157+ if ( $this->getData_Raw( 'payment_method' ) === 'cc' ){
11561158 $this->addDonorDataToSession();
11571159 }
11581160 }
11591161
11601162 protected function pre_process_get_orderstatus(){
1161 - if ( $this->getData( 'payment_method' ) === 'cc' ){
 1163+ if ( $this->getData_Raw( 'payment_method' ) === 'cc' ){
11621164 $this->runPreProcessHooks();
11631165 }
11641166 }
@@ -1171,7 +1173,7 @@
11721174 * determine if we want to fail the transaction ourselves or not.
11731175 */
11741176 public function getCVVResult(){
1175 - if ( is_null( $this->getData( 'cvv_result' ) ) ){
 1177+ if ( is_null( $this->getData_Raw( 'cvv_result' ) ) ){
11761178 return null;
11771179 }
11781180
@@ -1185,7 +1187,7 @@
11861188 '0' => true, //No service available.
11871189 );
11881190
1189 - $result = $result_map[$this->getData( 'cvv_result' )];
 1191+ $result = $result_map[$this->getData_Raw( 'cvv_result' )];
11901192 return $result;
11911193
11921194 }
@@ -1195,7 +1197,7 @@
11961198 * determine if we want to fail the transaction ourselves or not.
11971199 */
11981200 public function getAVSResult(){
1199 - if ( is_null( $this->getData( 'avs_result' ) ) ){
 1201+ if ( is_null( $this->getData_Raw( 'avs_result' ) ) ){
12001202 return null;
12011203 }
12021204 //Best guess here:
@@ -1223,7 +1225,7 @@
12241226 '0' => 50, //No service available.
12251227 );
12261228
1227 - $result = $result_map[$this->getData( 'avs_result' )];
 1229+ $result = $result_map[$this->getData_Raw( 'avs_result' )];
12281230 return $result;
12291231 }
12301232
Index: trunk/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -151,7 +151,8 @@
152152 */
153153 protected $staged_vars = array();
154154 protected $return_value_map;
155 - protected $postdata;
 155+ protected $staged_data;
 156+ protected $raw_data;
156157 protected $postdatadefaults;
157158 protected $xmlDoc;
158159 protected $dataObj;
@@ -160,7 +161,7 @@
161162 protected $validation_errors;
162163 protected $current_transaction;
163164 protected $action;
164 - public $debugarray; //TODO: Take me out.
 165+ public $debugarray;
165166
166167 //ALL OF THESE need to be redefined in the children. Much voodoo depends on the accuracy of these constants.
167168 const GATEWAY_NAME = 'Donation Gateway';
@@ -206,8 +207,8 @@
207208
208209 $this->dataObj = new DonationData( get_called_class(), self::getGlobal( 'Test' ), $testData );
209210
210 - $this->postdata = $this->dataObj->getData();
211 - //TODO: Fix this a bit.
 211+ $this->raw_data = $this->dataObj->getData();
 212+ $this->staged_data = $this->raw_data;
212213
213214 $this->posted = ( $wgRequest->wasPosted() && ( !is_null( $wgRequest->getVal( 'numAttempt', null ) ) ) );
214215
@@ -218,7 +219,6 @@
219220 $this->defineAccountInfo();
220221 $this->defineReturnValueMap();
221222
222 - $this->displaydata = $this->postdata;
223223 $this->stageData();
224224 }
225225
@@ -292,19 +292,20 @@
293293 return $checkResult;
294294 }
295295 }
296 -
 296+
297297 /**
298 - * Returns staged data from the adapter object.
 298+ * Returns staged data from the adapter object, or null if a key was
 299+ * specified and no value exsits.
299300 * @param string $val An optional specific key you want returned.
300301 * @return mixed All the staged data held by the adapter, or if a key was
301302 * set, the staged value for that key.
302303 */
303 - function getData( $val = '' ) {
 304+ function getData_Staged( $val = '' ) {
304305 if ( $val === '' ) {
305 - return $this->postdata;
 306+ return $this->staged_data;
306307 } else {
307 - if ( array_key_exists( $val, $this->postdata ) ) {
308 - return $this->postdata[$val];
 308+ if ( array_key_exists( $val, $this->staged_data ) ) {
 309+ return $this->staged_data[$val];
309310 } else {
310311 return null;
311312 }
@@ -337,22 +338,22 @@
338339 }
339340
340341 /**
341 - * Returns the variable $this->dataObj which should be an instance of
342 - * DonationData
343 - *
344 - * @return DonationData
 342+ * This is the ONLY getData type function anything should be using
 343+ * outside the adapter.
 344+ * Please note that in this case, raw means it's been normalized and
 345+ * sanitized by DonationData. Mostly, we qualify it as "raw" because it's
 346+ * not been staged for this adapter.
 347+ * @param string $val The specific key you're looking for (if any)
 348+ * @return mixed An array of all the raw, unstaged (but normalized and
 349+ * sanitized) data sent to the adapter, or if $val was set, either the
 350+ * specific value held for $val, or null if none exists.
345351 */
346 - public function getDonationData() {
347 -
348 - return $this->dataObj;
349 - }
350 -
351 - function getDisplayData( $val = '' ) {
 352+ public function getData_Raw( $val = '' ) {
352353 if ( $val === '' ) {
353 - return $this->displaydata;
 354+ return $this->raw_data;
354355 } else {
355 - if ( array_key_exists( $val, $this->displaydata ) ) {
356 - return $this->displaydata[$val];
 356+ if ( array_key_exists( $val, $this->raw_data ) ) {
 357+ return $this->raw_data[$val];
357358 } else {
358359 return null;
359360 }
@@ -534,10 +535,10 @@
535536 if ( $token === true ) { //we just want the field name to use, so short-circuit all that mess.
536537 return '@' . $this->var_map[$gateway_field_name];
537538 }
538 - if ( array_key_exists( $this->var_map[$gateway_field_name], $this->postdata ) &&
539 - $this->postdata[$this->var_map[$gateway_field_name]] !== '' ) {
 539+ $staged = $this->getData_Staged( $this->var_map[$gateway_field_name] );
 540+ if ( !is_null( $staged ) ) {
540541 //if it was sent, use that.
541 - return $this->postdata[$this->var_map[$gateway_field_name]];
 542+ return $staged;
542543 } else {
543544 //return the default for that form value
544545
@@ -889,7 +890,7 @@
890891 }
891892
892893 // log that the transaction is essentially complete
893 - self::log( $this->getData( 'contribution_tracking_id' ) . " Transaction complete." );
 894+ self::log( $this->getData_Raw( 'contribution_tracking_id' ) . " Transaction complete." );
894895
895896 //getTransactionStatus works here like this, because it only returns
896897 //something other than false if it's the sort of a transaction that can
@@ -897,7 +898,7 @@
898899 // $wmfStatus = $this->getTransactionWMFStatus();
899900 // switch ( $wmfStatus ){
900901 // case 'failed' : //only kill their session if they've tried three (or somehow more) times.
901 -// if ( (int)$this->postdata['numAttempt'] < 3 ) {
 902+// if ( (int)$this->getData_Staged('numAttempt') < 3 ) {
902903 // break;
903904 // }
904905 // case 'complete' :
@@ -906,7 +907,7 @@
907908 // $this->unsetAllSessionData();
908909 // }
909910
910 - $this->debugarray[] = 'numAttempt = ' . $this->postdata['numAttempt'];
 911+ $this->debugarray[] = 'numAttempt = ' . $this->getData_Staged('numAttempt');
911912
912913 return $this->getTransactionAllResults();
913914
@@ -1072,15 +1073,15 @@
10731074 $results = array();
10741075
10751076 while ( $i++ <= 3 ) {
1076 - self::log( $this->getData( 'contribution_tracking_id' ) . ' Preparing to send transaction to ' . self::getGatewayName() );
 1077+ self::log( $this->getData_Raw( 'contribution_tracking_id' ) . ' Preparing to send transaction to ' . self::getGatewayName() );
10771078 $results['result'] = curl_exec( $ch );
10781079 $results['headers'] = curl_getinfo( $ch );
10791080
10801081 if ( $results['headers']['http_code'] != 200 && $results['headers']['http_code'] != 403 ) {
1081 - self::log( $this->getData( 'contribution_tracking_id' ) . ' Failed sending transaction to ' . self::getGatewayName() . ', retrying' );
 1082+ self::log( $this->getData_Raw( 'contribution_tracking_id' ) . ' Failed sending transaction to ' . self::getGatewayName() . ', retrying' );
10821083 sleep( 1 );
10831084 } elseif ( $results['headers']['http_code'] == 200 || $results['headers']['http_code'] == 403 ) {
1084 - self::log( $this->getData( 'contribution_tracking_id' ) . ' Finished sending transaction to ' . self::getGatewayName() );
 1085+ self::log( $this->getData_Raw( 'contribution_tracking_id' ) . ' Finished sending transaction to ' . self::getGatewayName() );
10851086 break;
10861087 }
10871088 }
@@ -1092,7 +1093,7 @@
10931094 //TODO: i18n here!
10941095 //TODO: But also, fire off some kind of "No response from the gateway" thing to somebody so we know right away.
10951096 $results['message'] = 'No response from ' . self::getGatewayName() . '. Please try again later!';
1096 - self::log( $this->getData( 'contribution_tracking_id' ) . ' No response from ' . self::getGatewayName() . ': ' . curl_error( $ch ) );
 1097+ self::log( $this->getData_Raw( 'contribution_tracking_id' ) . ' No response from ' . self::getGatewayName() . ': ' . curl_error( $ch ) );
10971098 curl_close( $ch );
10981099 return false;
10991100 }
@@ -1392,7 +1393,7 @@
13931394 'gateway_txn_id' => $this->getTransactionGatewayTxnID(),
13941395 //'language' => '',
13951396 );
1396 - $transaction += $this->getDisplayData();
 1397+ $transaction += $this->getData_Raw();
13971398
13981399 try {
13991400 wfRunHooks( $hook, array( $transaction ) );
@@ -1404,9 +1405,10 @@
14051406 function smooshVarsForStaging() {
14061407
14071408 foreach ( $this->staged_vars as $field ) {
1408 - if ( !array_key_exists( $field, $this->postdata ) || empty( $this->postdata[$field] ) ) {
 1409+ $val = $this->getData_Staged( $field );
 1410+ if ( is_null( $val ) or $val === '' ) {
14091411 if ( array_key_exists( $field, $this->postdatadefaults ) ) {
1410 - $this->postdata[$field] = $this->postdatadefaults[$field];
 1412+ $this->staged_data[$field] = $this->postdatadefaults[$field];
14111413 }
14121414 }
14131415 //what do we do in the event that we're still nothing? (just move on.)
@@ -1445,7 +1447,7 @@
14461448 }
14471449
14481450 function getPaypalRedirectURL() {
1449 - $currency = $this->getData( 'currency' );
 1451+ $currency = $this->getData_Raw( 'currency' );
14501452
14511453 // update the utm source to set the payment instrument to pp rather than cc
14521454 $data['payment_method'] = 'pp';
@@ -1457,7 +1459,7 @@
14581460 //update contribution tracking
14591461 $this->dataObj->updateContributionTracking( true );
14601462
1461 - $ret = self::getGlobal( "PaypalURL" ) . "/" . $this->postdata['language'] . "?gateway=paypal&" . http_build_query( $this->getPaypalData() );
 1463+ $ret = self::getGlobal( "PaypalURL" ) . "/" . $this->staged_data['language'] . "?gateway=paypal&" . http_build_query( $this->getPaypalData() );
14621464 self::log( $ret );
14631465 return $ret;
14641466 }
@@ -1495,9 +1497,9 @@
14961498 );
14971499 $ret = array();
14981500 foreach ( $paypalkeys as $key ){
1499 - $val = $this->getDisplayData( $key );
 1501+ $val = $this->getData_Raw( $key );
15001502 if (!is_null( $val )){
1501 - $ret[$key] = $this->getDisplayData( $key );
 1503+ $ret[$key] = $this->getData_Raw( $key );
15021504 }
15031505 }
15041506 return $ret;
@@ -1735,9 +1737,9 @@
17361738 */
17371739 function runPreProcessHooks() {
17381740 // allow any external validators to have their way with the data
1739 - self::log( $this->getData( 'contribution_tracking_id' ) . " Preparing to query MaxMind" );
 1741+ self::log( $this->getData_Raw( 'contribution_tracking_id' ) . " Preparing to query MaxMind" );
17401742 wfRunHooks( 'GatewayValidate', array( &$this ) );
1741 - self::log( $this->getData( 'contribution_tracking_id' ) . ' Finished querying Maxmind' );
 1743+ self::log( $this->getData_Raw( 'contribution_tracking_id' ) . ' Finished querying Maxmind' );
17421744
17431745 //DO NOT set some variable as getValidationAction() here, and keep
17441746 //checking that. getValidationAction could change with each one of these
@@ -1806,9 +1808,9 @@
18071809
18081810 /**
18091811 * Instead of pulling all the DonationData back through to update one local
1810 - * value, use this. It updates both postdata (which is intended to be
1811 - * staged for the gateway) and displaydata (which could potentially become
1812 - * staged for the user).
 1812+ * value, use this. It updates both staged_data (which is intended to be
 1813+ * staged and used _just_ by the gateway) and raw_data, which is actually
 1814+ * just normalized and sanitized form data as entered by the user.
18131815 *
18141816 * TODO: handle the cases where $val is listed in the gateway adapter's
18151817 * staged_vars.
@@ -1821,11 +1823,11 @@
18221824 function refreshGatewayValueFromSource( $val ) {
18231825 $refreshed = $this->dataObj->getVal( $val );
18241826 if ( !is_null($refreshed) ){
1825 - $this->postdata[$val] = $refreshed;
1826 - $this->displaydata[$val] = $refreshed;
 1827+ $this->staged_data[$val] = $refreshed;
 1828+ $this->raw_data[$val] = $refreshed;
18271829 } else {
1828 - unset( $this->postdata[$val] );
1829 - unset( $this->displaydata[$val] );
 1830+ unset( $this->staged_data[$val] );
 1831+ unset( $this->raw_data[$val] );
18301832 }
18311833 }
18321834
Index: trunk/extensions/DonationInterface/gateway_common/donation.api.php
@@ -44,7 +44,7 @@
4545 $this->dieUsage( "Invalid gateway <<<$gateway>>> passed to Donation API.", 'unknown_gateway' );
4646 }
4747
48 - //$normalizedData = $gatewayObj->getData();
 48+ //$normalizedData = $gatewayObj->getData_Raw();
4949 $outputResult = array();
5050 $outputResult['message'] = $result['message'];
5151 $outputResult['status'] = $result['status'];
Index: trunk/extensions/DonationInterface/gateway_common/GatewayForm.php
@@ -77,7 +77,7 @@
7878 */
7979 public function validateForm( &$error, $options = array() ) {
8080
81 - $data = $this->adapter->getDisplayData();
 81+ $data = $this->adapter->getData_Raw();
8282
8383 extract( $options );
8484

Follow-up revisions

RevisionCommit summaryAuthorDate
r102236MFT r90286, r100671, r100837, r100950, r101060, r101063, r101064, r101073, r1......khorn03:06, 7 November 2011
r102237MFT r90286, r100671, r100837, r100950, r101060, r101063, r101064, r101073, r1......khorn03:07, 7 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r101857follow-up to r100923 and r97115 - better method for constructing URLkaldari19:12, 3 November 2011

Status & tagging log