r97341 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97340‎ | r97341 | r97342 >
Date:22:02, 16 September 2011
Author:khorn
Status:resolved (Comments)
Tags:fundraising 
Comment:
Adds a processor-type page for the iframe to come back from, and a way to handle error code translation in a gateway's transaction responses.
Modified paths:
  • /branches/fundraising/extensions/DonationInterface/donationinterface.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php (added) (history)
  • /branches/fundraising/extensions/DonationInterface/modules/iframe.liberator.js (added) (history)

Diff [purge]

Index: branches/fundraising/extensions/DonationInterface/donationinterface.php
@@ -89,17 +89,17 @@
9090 # Unit tests
9191 $wgHooks['UnitTestsList'][] = 'efDonationInterfaceUnitTests';
9292
93 -//
94 -//// Resource modules
95 -//$wgResourceTemplate = array(
96 -// 'localBasePath' => $donationinterface_dir . 'modules',
97 -// 'remoteExtPath' => 'DonationInterface/modules',
98 -//);
99 -//$wgResourceModules['jquery.donationInterface'] = array(
100 -// 'scripts' => 'jquery.donationInterface.js',
101 -// 'dependencies' => 'jquery.json',
102 -//) + $wgResourceTemplate;
10393
 94+// Resource modules
 95+$wgResourceTemplate = array(
 96+ 'localBasePath' => $donationinterface_dir . 'modules',
 97+ 'remoteExtPath' => 'DonationInterface/modules',
 98+);
 99+$wgResourceModules['iframe.liberator'] = array(
 100+ 'scripts' => 'iframe.liberator.js',
 101+ 'position' => 'top'
 102+) + $wgResourceTemplate;
 103+
104104 function efDonationInterfaceUnitTests( &$files ) {
105105 $files[] = dirname( __FILE__ ) . '/tests/GatewayAdapterTest.php';
106106 $files[] = dirname( __FILE__ ) . '/tests/DonationDataTest.php';
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php
@@ -0,0 +1,190 @@
 2+<?php
 3+
 4+class GlobalCollectGatewayResult extends UnlistedSpecialPage {
 5+
 6+ /**
 7+ * Defines the action to take on a PFP transaction.
 8+ *
 9+ * Possible values include 'process', 'challenge',
 10+ * 'review', 'reject'. These values can be set during
 11+ * data processing validation, for instance.
 12+ *
 13+ * Hooks are exposed to handle the different actions.
 14+ *
 15+ * Defaults to 'process'.
 16+ * @var string
 17+ */
 18+ public $action = 'process';
 19+
 20+ /**
 21+ * An array of form errors
 22+ * @var array
 23+ */
 24+ public $errors = array( );
 25+
 26+ /**
 27+ * Constructor - set up the new special page
 28+ */
 29+ public function __construct() {
 30+ parent::__construct( 'GlobalCollectGatewayResult' );
 31+ $this->errors = $this->getPossibleErrors();
 32+
 33+ $this->adapter = new GlobalCollectAdapter();
 34+ }
 35+
 36+ /**
 37+ * Show the special page
 38+ *
 39+ * @param $par Mixed: parameter passed to the page or null
 40+ */
 41+ public function execute( $par ) {
 42+ global $wgRequest, $wgOut, $wgExtensionAssetsPath,
 43+ $wgPayFlowProGatewayCSSVersion;
 44+
 45+ $wgOut->allowClickjacking();
 46+ $wgOut->addModules( 'iframe.liberator' );
 47+
 48+ $wgOut->addExtensionStyle(
 49+ $wgExtensionAssetsPath . '/DonationInterface/gateway_forms/css/gateway.css?284' .
 50+ $wgPayFlowProGatewayCSSVersion );
 51+
 52+ $this->setHeaders();
 53+
 54+
 55+ // dispatch forms/handling
 56+ if ( $this->adapter->checkTokens() ) {
 57+ // Display form for the first time
 58+ $oid = $wgRequest->getText( 'order_id' );
 59+ if ( $oid && !empty( $oid ) ) {
 60+ $result = $this->adapter->do_transaction( 'GET_ORDERSTATUS' );
 61+ $this->displayResultsForDebug( $result );
 62+ }
 63+ $this->adapter->log( "Not posted, or not processed. Showing the form for the first time." );
 64+ } else {
 65+ if ( !$this->adapter->isCache() ) {
 66+ // if we're not caching, there's a token mismatch
 67+ $this->errors['general']['token-mismatch'] = wfMsg( 'payflowpro_gateway-token-mismatch' );
 68+ }
 69+ }
 70+ }
 71+
 72+ function displayResultsForDebug( $results ) {
 73+ global $wgOut;
 74+ $wgOut->addHTML( $results['message'] );
 75+
 76+ if ( !empty( $results['errors'] ) ) {
 77+ $wgOut->addHTML( "<ul>" );
 78+ foreach ( $results['errors'] as $code => $value ) {
 79+ $wgOut->addHTML( "<li>Error $code: $value" );
 80+ }
 81+ $wgOut->addHTML( "</ul>" );
 82+ }
 83+
 84+ if ( !empty( $results['data'] ) ) {
 85+ $wgOut->addHTML( "<ul>" );
 86+ foreach ( $results['data'] as $key => $value ) {
 87+ if ( is_array( $value ) ) {
 88+ $wgOut->addHTML( "<li>$key:<ul>" );
 89+ foreach ( $value as $key2 => $val2 ) {
 90+ $wgOut->addHTML( "<li>$key2: $val2" );
 91+ }
 92+ $wgOut->addHTML( "</ul>" );
 93+ } else {
 94+ $wgOut->addHTML( "<li>$key: $value" );
 95+ }
 96+ }
 97+ $wgOut->addHTML( "</ul>" );
 98+ } else {
 99+ $wgOut->addHTML( "Empty Results" );
 100+ }
 101+ }
 102+
 103+ /**
 104+ * Prepares the transactional message to be sent via Stomp to queueing service
 105+ *
 106+ * @param array $data
 107+ * @param array $resposneArray
 108+ * @param array $responseMsg
 109+ * @return array
 110+ */
 111+ public function prepareStompTransaction( $data, $responseArray, $responseMsg ) {
 112+ $countries = $this->getCountries();
 113+
 114+ $transaction = array( );
 115+
 116+ // include response message
 117+ $transaction['response'] = $responseMsg;
 118+
 119+ // include date
 120+ $transaction['date'] = time();
 121+
 122+ // put all data into one array
 123+ $optout = $this->determineOptOut( $data );
 124+ $data['anonymous'] = $optout['anonymous'];
 125+ $data['optout'] = $optout['optout'];
 126+
 127+ $transaction += array_merge( $data, $responseArray );
 128+
 129+ return $transaction;
 130+ }
 131+
 132+ public function getPossibleErrors() {
 133+ return array(
 134+ 'general' => '',
 135+ 'retryMsg' => '',
 136+ 'invalidamount' => '',
 137+ 'card_num' => '',
 138+ 'card_type' => '',
 139+ 'cvv' => '',
 140+ 'fname' => '',
 141+ 'lname' => '',
 142+ 'city' => '',
 143+ 'country' => '',
 144+ 'street' => '',
 145+ 'state' => '',
 146+ 'zip' => '',
 147+ 'emailAdd' => '',
 148+ );
 149+ }
 150+
 151+ /**
 152+ * Handle redirection of form content to PayPal
 153+ *
 154+ * @fixme If we can update contrib tracking table in ContributionTracking
 155+ * extension, we can probably get rid of this method and just submit the form
 156+ * directly to the paypal URL, and have all processing handled by ContributionTracking
 157+ * This would make this a lot less hack-ish
 158+ */
 159+ public function paypalRedirect( &$data ) {
 160+ global $wgPayflowProGatewayPaypalURL, $wgOut;
 161+
 162+ // if we don't have a URL enabled throw a graceful error to the user
 163+ if ( !strlen( $wgPayflowProGatewayPaypalURL ) ) {
 164+ $this->errors['general']['nopaypal'] = wfMsg( 'payflow_gateway-error-msg-nopaypal' );
 165+ return;
 166+ }
 167+
 168+ // update the utm source to set the payment instrument to pp rather than cc
 169+ $utm_source_parts = explode( ".", $data['utm_source'] );
 170+ $utm_source_parts[2] = 'pp';
 171+ $data['utm_source'] = implode( ".", $utm_source_parts );
 172+ $data['gateway'] = 'paypal';
 173+ $data['currency_code'] = $data['currency'];
 174+ /**
 175+ * update contribution tracking
 176+ */
 177+ $this->updateContributionTracking( $data, true );
 178+
 179+ $wgPayflowProGatewayPaypalURL .= "/" . $data['language'] . "?gateway=paypal";
 180+
 181+ // submit the data to the paypal redirect URL
 182+ $wgOut->redirect( $wgPayflowProGatewayPaypalURL . '&' . http_build_query( $data ) );
 183+ }
 184+
 185+ public static function log( $msg, $log_level=LOG_INFO ) {
 186+ $this->adapter->log( $msg, $log_level );
 187+ }
 188+
 189+}
 190+
 191+// end class
Property changes on: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_resultswitcher.body.php
___________________________________________________________________
Added: svn:eol-style
1192 + native
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php
@@ -12,14 +12,14 @@
1313 */
1414 function stageData() {
1515 $this->postdata['amount'] = $this->postdata['amount'] * 100;
16 -
 16+
1717 $card_type = '';
18 - if (array_key_exists('card_type', $this->postdata) && !empty($this->postdata['card_type'])){
 18+ if ( array_key_exists( 'card_type', $this->postdata ) && !empty( $this->postdata['card_type'] ) ) {
1919 $card_type = $this->postdata['card_type'];
2020 } else {
2121 $card_type = $this->postdatadefaults['card_type'];
2222 }
23 -
 23+
2424 switch ( $card_type ) {
2525 case 'visa':
2626 $this->postdata['card_type'] = 1;
@@ -34,19 +34,18 @@
3535 $this->postdata['card_type'] = 128;
3636 break;
3737 }
38 -
 38+
3939 $this->postdata['expiry'] = $this->postdata['expiration']; //. ($this->postdata['year'] % 100);
40 - $this->postdata['card_num'] = str_replace(' ', '', $this->postdata['card_num']);
41 -
 40+ $this->postdata['card_num'] = str_replace( ' ', '', $this->postdata['card_num'] );
 41+
4242 $returnto = '';
43 - if (array_key_exists('returnto', $this->postdata)){
 43+ if ( array_key_exists( 'returnto', $this->postdata ) ) {
4444 $returnto = $this->postdata['returnto'];
4545 } else {
4646 $returnto = $this->postdatadefaults['returnto'];
4747 }
48 -
 48+
4949 $this->postdata['returnto'] = $returnto . "?order_id=" . $this->postdata['order_id'];
50 -
5150 }
5251
5352 function defineAccountInfo() {
@@ -70,7 +69,7 @@
7170 'PAYMENTPRODUCTID' => 'card_type',
7271 'CVV' => 'cvv',
7372 'EXPIRYDATE' => 'expiry',
74 - 'CREDITCARDNUMBER' => 'card_num',
 73+ 'CREDITCARDNUMBER' => 'card_num',
7574 'FIRSTNAME' => 'fname',
7675 'SURNAME' => 'lname',
7776 'STREET' => 'street',
@@ -86,6 +85,19 @@
8786 'OK' => true,
8887 'NOK' => false,
8988 );
 89+ $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending', 0, 70 );
 90+ $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'failed', 100, 180 );
 91+ $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending', 200 );
 92+ $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'failed', 220, 280 );
 93+ $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending', 300 );
 94+ $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'failed', 310, 350 );
 95+ $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'revised', 400 );
 96+ $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending_poke', 525 );
 97+ $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending', 550, 850 );
 98+ $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending', 900 ); //There's two 900s in the doc. The heck?
 99+ $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'pending', 950, 975 );
 100+ $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'complete', 1000, 1050 );
 101+ $this->addCodeRange( 'GET_ORDERSTATUS', 'STATUSID', 'failed', 1100, 99999 );
90102 }
91103
92104 function defineTransactions() {
@@ -235,22 +247,23 @@
236248 */
237249 function getResponseData( $response ) {
238250 $data = array( );
239 -
 251+
240252 $transaction = $this->currentTransaction();
241253
242254 switch ( $transaction ) {
243255 case 'INSERT_ORDERWITHPAYMENT':
244 - $data = $this->xmlChildrenToArray($response, 'ROW');
245 - $data['ORDER'] = $this->xmlChildrenToArray($response, 'ORDER');
246 - $data['PAYMENT'] = $this->xmlChildrenToArray($response, 'PAYMENT');
 256+ $data = $this->xmlChildrenToArray( $response, 'ROW' );
 257+ $data['ORDER'] = $this->xmlChildrenToArray( $response, 'ORDER' );
 258+ $data['PAYMENT'] = $this->xmlChildrenToArray( $response, 'PAYMENT' );
247259 break;
248260 case 'GET_ORDERSTATUS':
249 - $data = $this->xmlChildrenToArray($response, 'STATUS');
250 - $data['ORDER'] = $this->xmlChildrenToArray($response, 'ORDER');
 261+ $data = $this->xmlChildrenToArray( $response, 'STATUS' );
 262+ $data['WMF_TRANSLATEDCODE'] = $this->findCodeAction( 'GET_ORDERSTATUS', 'STATUSID', $data['STATUSID'] );
 263+ $data['ORDER'] = $this->xmlChildrenToArray( $response, 'ORDER' );
251264 break;
252265 }
253 -
254 -
 266+
 267+
255268 self::log( "Returned Data: " . print_r( $data, true ) );
256269 return $data;
257270 }
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.php
@@ -23,12 +23,14 @@
2424 // Set up the new special page
2525 $dir = dirname( __FILE__ ) . '/';
2626 $wgAutoloadClasses['GlobalCollectGateway'] = $dir . 'globalcollect_gateway.body.php';
 27+$wgAutoloadClasses['GlobalCollectGatewayResult'] = $dir . 'globalcollect_resultswitcher.body.php';
2728 $wgAutoloadClasses['GlobalCollectAdapter'] = $dir . 'globalcollect.adapter.php';
2829 $wgExtensionMessagesFiles['GlobalCollectGateway'] = $dir . '../payflowpro_gateway/payflowpro_gateway.i18n.php';
2930 $wgExtensionMessagesFiles['GlobalCollectGatewayCountries'] = $dir . '../payflowpro_gateway/payflowpro_gateway.countries.i18n.php';
3031 $wgExtensionMessagesFiles['GlobalCollectGatewayUSStates'] = $dir . '../payflowpro_gateway/payflowpro_gateway.us-states.i18n.php';
3132 $wgExtensionAliasesFiles['GlobalCollectGateway'] = $dir . '../payflowpro_gateway/payflowpro_gateway.alias.php';
3233 $wgSpecialPages['GlobalCollectGateway'] = 'GlobalCollectGateway';
 34+$wgSpecialPages['GlobalCollectGatewayResult'] = 'GlobalCollectGatewayResult';
3335 //$wgAjaxExportList[] = "fnGlobalCollectofofWork";
3436 // set defaults, these should be assigned in LocalSettings.php
3537 $wgGlobalCollectGatewayURL = 'https://ps.gcsip.nl/wdl/wdl';
Index: branches/fundraising/extensions/DonationInterface/modules/iframe.liberator.js
@@ -0,0 +1,4 @@
 2+
 3+if (top.frames.length!=0){
 4+ top.location=self.document.location;
 5+}
\ No newline at end of file
Property changes on: branches/fundraising/extensions/DonationInterface/modules/iframe.liberator.js
___________________________________________________________________
Added: svn:eol-style
16 + native
Index: branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -124,8 +124,8 @@
125125 * Override this in children if you want different defaults.
126126 */
127127 function setPostDefaults() {
128 - $returnTitle = Title::newFromText( 'Donate-thanks/en' );
129 -// $returnTitle = Title::newFromText( 'Special:GlobalCollectGateway' );
 128+// $returnTitle = Title::newFromText( 'Donate-thanks/en' );
 129+ $returnTitle = Title::newFromText( 'Special:GlobalCollectGatewayResult' );
130130 $returnto = $returnTitle->getFullURL();
131131
132132 $this->postdatadefaults = array(
@@ -192,7 +192,7 @@
193193
194194 //If there's a value in the post data (name-translated by the var_map), use that.
195195 if ( array_key_exists( $gateway_field_name, $this->var_map ) ) {
196 - if ($token === true){ //we just want the field name to use, so short-circuit all that mess.
 196+ if ( $token === true ) { //we just want the field name to use, so short-circuit all that mess.
197197 return '@' . $this->var_map[$gateway_field_name];
198198 }
199199 if ( array_key_exists( $this->var_map[$gateway_field_name], $this->postdata ) &&
@@ -249,9 +249,9 @@
250250 $node->appendChild( $temp );
251251 }
252252 }
253 -
 253+
254254 //TODO: You can actually take this out if we never ever want to use ajax for a gateway.
255 - function buildTransactionFormat($transaction){
 255+ function buildTransactionFormat( $transaction ) {
256256 $this->currentTransaction( $transaction );
257257 $this->xmlDoc = new DomDocument( '1.0' );
258258 $node = $this->xmlDoc->createElement( 'XML' );
@@ -261,34 +261,34 @@
262262 $this->buildTransactionNodes( $structure, $node, true );
263263 $this->xmlDoc->appendChild( $node );
264264 $xml = $this->xmlDoc->saveXML();
265 - $xmlStart = strpos($xml, "<XML>");
266 - self::log("XML START" . $xmlStart);
 265+ $xmlStart = strpos( $xml, "<XML>" );
 266+ self::log( "XML START" . $xmlStart );
267267 $xml = substr( $xml, $xmlStart );
268 - self::log("XML stubby thing..." . $xml);
269 -
 268+ self::log( "XML stubby thing..." . $xml );
 269+
270270 return $xml;
271271 }
272 -
 272+
273273 function do_transaction( $transaction ) {
274274 $this->currentTransaction( $transaction );
275275 //update the contribution tracking data
276276 $this->dataObj->updateContributionTracking( defined( 'OWA' ) );
277277 if ( $this->getCommunicationType() === 'xml' ) {
278 - $this->getStopwatch(__FUNCTION__);
 278+ $this->getStopwatch( "buildRequestXML" );
279279 $xml = $this->buildRequestXML();
280 - $this->saveCommunicationStats(__FUNCTION__, "Building Request XML", "Transaction = $transaction");
 280+ $this->saveCommunicationStats( "buildRequestXML", $transaction );
281281 $returned = $this->curl_transaction( $xml );
282282 //put the response in a universal form, and return it.
283283 }
284284
285285 if ( $this->getCommunicationType() === 'namevalue' ) {
286286 $namevalue = $this->postdata;
287 - $this->getStopwatch(__FUNCTION__);
 287+ $this->getStopwatch( __FUNCTION__ );
288288 $returned = $this->curl_transaction( $namevalue );
289289 $this->saveCommunicationStats();
290290 //put the response in a universal form, and return it.
291291 }
292 -
 292+
293293 self::log( "RETURNED FROM CURL:" . print_r( $returned, true ) );
294294 if ( $returned['result'] === false ) { //couldn't make contact. Bail.
295295 return $returned;
@@ -376,8 +376,8 @@
377377 */
378378 protected function curl_transaction( $data ) {
379379 // assign header data necessary for the curl_setopt() function
380 - $this->getStopwatch(__FUNCTION__, true);
381 -
 380+ $this->getStopwatch( __FUNCTION__, true );
 381+
382382 $ch = curl_init();
383383
384384 $headers = $this->getCurlBaseHeaders();
@@ -413,8 +413,8 @@
414414 }
415415 }
416416
417 - $this->saveCommunicationStats(__FUNCTION__, $this->currentTransaction(), "Request:" . print_r($data, true) . "\nResponse" . print_r($return, true));
418 -
 417+ $this->saveCommunicationStats( __FUNCTION__, $this->currentTransaction(), "Request:" . print_r( $data, true ) . "\nResponse" . print_r( $return, true ) );
 418+
419419 if ( $return['headers']['http_code'] != 200 ) {
420420 $return['result'] = false;
421421 //TODO: i18n here!
@@ -516,19 +516,19 @@
517517 $c = get_called_class();
518518 return $c::IDENTIFIER;
519519 }
520 -
521 - public function getStopwatch($string, $reset = false){
 520+
 521+ public function getStopwatch( $string, $reset = false ) {
522522 static $start = null;
523 - $now = microtime(true);
 523+ $now = microtime( true );
524524
525 - if ($start == null || $reset === true){
 525+ if ( $start == null || $reset === true ) {
526526 $start = $now;
527527 }
528 - $clock = round($now - $start, 4);
529 - self::log("\nClock at $string: $clock ($now)");
 528+ $clock = round( $now - $start, 4 );
 529+ self::log( "\nClock at $string: $clock ($now)" );
530530 return $clock;
531531 }
532 -
 532+
533533 /**
534534 *
535535 * @param type $function
@@ -536,12 +536,12 @@
537537 * @param type $vars
538538 */
539539 function saveCommunicationStats( $function = '', $additional = '', $vars = '' ) { //easier than looking at logs...
540 - $params = array();
541 - if (self::getGlobal('SaveCommStats')){ //TODO: I should do this for real at some point.
 540+ $params = array( );
 541+ if ( self::getGlobal( 'SaveCommStats' ) ) { //TODO: I should do this for real at some point.
542542 $db = ContributionTrackingProcessor::contributionTrackingConnection();
543543 $params['contribution_id'] = $this->dataObj->getVal( 'contribution_tracking_id' );
544544 $params['ts'] = $db->timestamp();
545 - $params['duration'] = $this->getStopwatch(__FUNCTION__);
 545+ $params['duration'] = $this->getStopwatch( __FUNCTION__ );
546546 $params['gateway'] = self::getGatewayName();
547547 $params['function'] = $function;
548548 $params['vars'] = $vars;
@@ -551,11 +551,10 @@
552552
553553 $db->insert( 'communication_stats', $params );
554554 }
 555+ }
555556
556 - }
557 -
558 - function xmlChildrenToArray($xml, $nodename){
559 - $data = array();
 557+ function xmlChildrenToArray( $xml, $nodename ) {
 558+ $data = array( );
560559 foreach ( $xml->getElementsByTagName( $nodename ) as $node ) {
561560 foreach ( $node->childNodes as $childnode ) {
562561 if ( trim( $childnode->nodeValue ) != '' ) {
@@ -566,4 +565,59 @@
567566 return $data;
568567 }
569568
 569+ /**
 570+ * DO NOT DEFINE OVERLAPPING RANGES!
 571+ * TODO: Make sure it won't let you add overlapping ranges. That would probably necessitate the sort moving to here, too.
 572+ * @param type $transaction
 573+ * @param type $key
 574+ * @param type $action
 575+ * @param type $lower
 576+ * @param type $upper
 577+ */
 578+ function addCodeRange( $transaction, $key, $action, $lower, $upper = null ) {
 579+ if ( $upper === null ) {
 580+ $this->return_value_map[$transaction][$key][$lower] = $action;
 581+ } else {
 582+ $this->return_value_map[$transaction][$key][$upper] = array( 'action' => $action, 'lower' => $lower );
 583+ }
 584+ }
 585+
 586+ function findCodeAction( $transaction, $key, $code ) {
 587+ $this->getStopwatch( __FUNCTION__, true );
 588+ if ( !array_key_exists( $transaction, $this->return_value_map ) || !array_key_exists( $key, $this->return_value_map[$transaction] ) ) {
 589+ return null;
 590+ }
 591+ if ( !is_array( $this->return_value_map[$transaction][$key] ) ) {
 592+ return null;
 593+ }
 594+ //sort the array so we can do this quickly.
 595+ ksort( $this->return_value_map[$transaction][$key], SORT_NUMERIC );
 596+
 597+ $ranges = $this->return_value_map[$transaction][$key];
 598+ //so, you have a code, which is a number. You also have a numerically sorted array.
 599+ //loop through until you find an upper >= your code.
 600+ //make sure it's in the range, and return the action.
 601+ foreach ( $ranges as $upper => $val ) {
 602+ if ( $upper >= $code ) { //you've arrived. It's either here or it's nowhere.
 603+ if ( is_array( $val ) ) {
 604+ if ( $val['lower'] <= $code ) {
 605+ $this->saveCommunicationStats( __FUNCTION__, $transaction, "code = $code" );
 606+ return $val['action'];
 607+ } else {
 608+ return null;
 609+ }
 610+ } else {
 611+ if ( $upper === $code ) {
 612+ $this->saveCommunicationStats( __FUNCTION__, $transaction, "code = $code" );
 613+ return $val;
 614+ } else {
 615+ return null;
 616+ }
 617+ }
 618+ }
 619+ }
 620+ //if we walk straight off the end...
 621+ return null;
 622+ }
 623+
570624 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r102047Establishes constraints on settable fields that should contain the over-archi...khorn21:09, 4 November 2011

Comments

#Comment by Khorn (WMF) (talk | contribs)   18:41, 23 September 2011

Please note that this branch is in the middle of a serious refactoring, and is by no means ready to be merged back into trunk. (Latest DonationInterface branch rev at the time of this comment is r97833.)

#Comment by Awjrichards (talk | contribs)   20:02, 29 September 2011

In donationinterface.php:

$wgResourceModules['iframe.liberator'] = array(
	'scripts' => 'iframe.liberator.js',
	'position' => 'top'
	) + $wgResourceTemplate;

Wouldn't it make more sense to keep this with the GlobalCollect adapter? We won't need this for other payment providers.

#Comment by Khorn (WMF) (talk | contribs)   23:53, 7 October 2011

Hah... pretty sure I put it in there because I didn't know what else you guys were going to do to me in the future. ::grin:: I can move it if you'd like. Currently it's available to everything, but it's only being used by the globalcollect resultswitcher.

#Comment by Awjrichards (talk | contribs)   20:48, 21 October 2011

Meh it is minor and not really a big deal. Marking ok.

Status & tagging log