Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php |
— | — | @@ -29,7 +29,7 @@ |
30 | 30 | $wgOut->addExtensionStyle( |
31 | 31 | $wgExtensionAssetsPath . '/DonationInterface/gateway_forms/css/gateway.css?284' . |
32 | 32 | $CSSVersion ); |
33 | | - |
| 33 | + |
34 | 34 | // Hide unneeded interface elements |
35 | 35 | $wgOut->addModules( 'donationInterface.skinOverride' ); |
36 | 36 | |
— | — | @@ -73,10 +73,7 @@ |
74 | 74 | * will be set as the default. |
75 | 75 | */ |
76 | 76 | $transactionType = false; |
77 | | - $transactionType = 'INSERT_ORDERWITHPAYMENT'; |
78 | | - $data['transaction_type'] = (isset( $data['transaction_type'] ) && !empty( $data['transaction_type'] ) ) ? $data['transaction_type'] : $transactionType; |
79 | | - $this->adapter->setTransactionType( $data['transaction_type'] ); |
80 | | - unset( $transactionType ); |
| 77 | + $transactionType = ( isset( $data['transaction_type'] ) && !empty( $data['transaction_type'] ) ) ? $data['transaction_type'] : 'INSERT_ORDERWITHPAYMENT'; |
81 | 78 | |
82 | 79 | $this->adapter->log( '$transactionType: Default is set to: INSERT_ORDERWITHPAYMENT, this is a temporary hack for backwards compatibility.' ); |
83 | 80 | $this->adapter->log( 'Setting transaction type: ' . ( string ) $data['transaction_type'] ); |
— | — | @@ -91,7 +88,7 @@ |
92 | 89 | // Check form for errors |
93 | 90 | |
94 | 91 | $options = array( ); |
95 | | - switch ( $this->adapter->getTransactionType() ) { |
| 92 | + switch ( $transactionType ) { |
96 | 93 | |
97 | 94 | case 'BANK_TRANSFER': |
98 | 95 | $options['creditCard'] = false; |
— | — | @@ -116,7 +113,7 @@ |
117 | 114 | } else { // The submitted form data is valid, so process it |
118 | 115 | // allow any external validators to have their way with the data |
119 | 116 | // Execute the proper transaction code: |
120 | | - switch ( $this->adapter->getTransactionType() ) { |
| 117 | + switch ( $transactionType ) { |
121 | 118 | |
122 | 119 | case 'BANK_TRANSFER': |
123 | 120 | $this->executeBankTransfer(); |
— | — | @@ -128,7 +125,7 @@ |
129 | 126 | |
130 | 127 | default: |
131 | 128 | |
132 | | - $message = 'The transaction type [ ' . $this->adapter->getTransactionType() . ' ] was not found.'; |
| 129 | + $message = 'The transaction type [ ' . $transactionType . ' ] was not found.'; |
133 | 130 | throw new Exception( $message ); |
134 | 131 | } |
135 | 132 | |
— | — | @@ -174,7 +171,7 @@ |
175 | 172 | public function executeInsertOrderWithPayment() { |
176 | 173 | |
177 | 174 | global $wgOut; |
178 | | - |
| 175 | + |
179 | 176 | $result = $this->adapter->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); |
180 | 177 | $this->adapter->addDonorDataToSession(); |
181 | 178 | //$result = $this->adapter->do_transaction( 'TEST_CONNECTION' ); |
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect.adapter.php |
— | — | @@ -316,21 +316,6 @@ |
317 | 317 | 'returnto', |
318 | 318 | 'order_id', //This may or may not oughta-be-here... |
319 | 319 | ); |
320 | | - |
321 | | - switch ( $this->getTransactionType() ) { |
322 | | - |
323 | | - case 'BANK_TRANSFER': |
324 | | - break; |
325 | | - |
326 | | - case 'INSERT_ORDERWITHPAYMENT': |
327 | | - $this->staged_vars[] = 'card_type'; |
328 | | - $this->staged_vars[] = 'card_num'; |
329 | | - break; |
330 | | - |
331 | | - default: |
332 | | - $this->staged_vars[] = 'card_type'; |
333 | | - $this->staged_vars[] = 'card_num'; |
334 | | - } |
335 | 320 | } |
336 | 321 | |
337 | 322 | protected function stage_amount( $type = 'request' ) { |
— | — | @@ -357,7 +342,7 @@ |
358 | 343 | $types = array_flip( $types ); |
359 | 344 | } |
360 | 345 | |
361 | | - if ( array_key_exists( $this->postdata['card_type'], $types ) ) { |
| 346 | + if ( ( array_key_exists( 'card_type', $this->postdata ) ) && array_key_exists( $this->postdata['card_type'], $types ) ) { |
362 | 347 | $this->postdata['card_type'] = $types[$this->postdata['card_type']]; |
363 | 348 | } else { |
364 | 349 | //$this->postdata['card_type'] = ''; |
— | — | @@ -367,7 +352,9 @@ |
368 | 353 | |
369 | 354 | protected function stage_card_num( $type = 'request' ) { |
370 | 355 | //I realize that the $type isn't used. Voodoo. |
371 | | - $this->postdata['card_num'] = str_replace( ' ', '', $this->postdata['card_num'] ); |
| 356 | + if ( array_key_exists( 'card_num', $this->postdata ) ) { |
| 357 | + $this->postdata['card_num'] = str_replace( ' ', '', $this->postdata['card_num'] ); |
| 358 | + } |
372 | 359 | } |
373 | 360 | |
374 | 361 | protected function stage_returnto( $type = 'request' ) { |
Index: branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php |
— | — | @@ -1,4 +1,5 @@ |
2 | 2 | <?php |
| 3 | + |
3 | 4 | /** |
4 | 5 | * Wikimedia Foundation |
5 | 6 | * |
— | — | @@ -121,8 +122,7 @@ |
122 | 123 | * |
123 | 124 | * @var array $staged_vars |
124 | 125 | */ |
125 | | - protected $staged_vars = array(); |
126 | | - |
| 126 | + protected $staged_vars = array( ); |
127 | 127 | protected $return_value_map; |
128 | 128 | protected $postdata; |
129 | 129 | protected $postdatadefaults; |
— | — | @@ -149,23 +149,18 @@ |
150 | 150 | * |
151 | 151 | * @see DonationData |
152 | 152 | */ |
153 | | - public function __construct( $options = array() ) { |
| 153 | + public function __construct( $options = array( ) ) { |
154 | 154 | global $wgRequest; |
155 | 155 | |
156 | 156 | // Extract the options |
157 | 157 | extract( $options ); |
158 | | - |
| 158 | + |
159 | 159 | $testData = isset( $testData ) ? $testData : false; |
160 | 160 | $postDefaults = isset( $postDefaults ) ? $postDefaults : false; |
161 | | - $transactionType = isset( $transactionType ) ? $transactionType : false; |
162 | | - |
163 | | - if ( $transactionType ) { |
164 | | - $this->setTransactionType( $transactionType ); |
165 | | - } |
166 | | - |
| 161 | + |
167 | 162 | if ( !self::getGlobal( 'Test' ) ) { |
168 | 163 | $this->url = self::getGlobal( 'URL' ); |
169 | | - |
| 164 | + |
170 | 165 | // Only submit test data if we are in test mode. |
171 | 166 | $testData = false; |
172 | 167 | } else { |
— | — | @@ -176,6 +171,7 @@ |
177 | 172 | |
178 | 173 | $this->postdata = $this->dataObj->getData(); |
179 | 174 | //TODO: Fix this a bit. |
| 175 | + |
180 | 176 | $this->posted = $wgRequest->wasPosted(); |
181 | 177 | |
182 | 178 | $this->setPostDefaults( $postDefaults ); |
— | — | @@ -184,6 +180,11 @@ |
185 | 181 | $this->defineAccountInfo(); |
186 | 182 | $this->defineReturnValueMap(); |
187 | 183 | |
| 184 | + //Don't bother setting the transaction type if it's not something. |
| 185 | + if ( $this->dataObj->isSomething( 'transaction_type' ) ) { |
| 186 | + $this->currentTransaction( $this->postdata['transaction_type'] ); |
| 187 | + } |
| 188 | + |
188 | 189 | $this->displaydata = $this->postdata; |
189 | 190 | $this->stageData(); |
190 | 191 | } |
— | — | @@ -191,15 +192,15 @@ |
192 | 193 | /** |
193 | 194 | * Override this in children if you want different defaults. |
194 | 195 | */ |
195 | | - function setPostDefaults( $options = array() ) { |
| 196 | + function setPostDefaults( $options = array( ) ) { |
196 | 197 | |
197 | 198 | // Extract the options |
198 | | - if ( is_array( $options )) { |
| 199 | + if ( is_array( $options ) ) { |
199 | 200 | extract( $options ); |
200 | 201 | } |
201 | 202 | |
202 | 203 | $returnTitle = isset( $returnTitle ) ? $returnTitle : Title::newFromText( 'Special:GlobalCollectGatewayResult' ); |
203 | | - $returnTo = isset( $returnTo ) ? $returnTo : $returnTitle->getFullURL(); |
| 204 | + $returnTo = isset( $returnTo ) ? $returnTo : $returnTitle->getFullURL(); |
204 | 205 | |
205 | 206 | $this->postdatadefaults = array( |
206 | 207 | 'order_id' => '112358' . rand(), |
— | — | @@ -279,19 +280,21 @@ |
280 | 281 | if ( !array_key_exists( $varname, $gotten ) ) { |
281 | 282 | $globalname = self::getGlobalPrefix() . $varname; |
282 | 283 | global $$globalname; |
283 | | - if ( !isset( $$globalname )) { |
| 284 | + if ( !isset( $$globalname ) ) { |
284 | 285 | $globalname = "wgDonationInterface" . $varname; |
285 | 286 | global $$globalname; //set or not. This is fine. |
286 | 287 | } |
287 | 288 | $gotten[$varname] = $$globalname; |
288 | 289 | } |
289 | | - return $gotten[$varname]; |
| 290 | + return $gotten[$varname]; |
290 | 291 | } |
291 | 292 | |
292 | 293 | function getValue( $gateway_field_name, $token = false ) { |
293 | 294 | if ( empty( $this->transactions ) ) { |
294 | 295 | //TODO: These dies should all throw exceptions or something less completely fatal. |
295 | | - die( 'Transactions structure is empty! Aborting.' ); |
| 296 | + $msg = self::getGatewayName() . ': Transactions structure is empty! No transaction can be constructed.'; |
| 297 | + self::log( $msg, LOG_CRIT ); |
| 298 | + throw new MWException( $msg ); |
296 | 299 | } |
297 | 300 | //How do we determine the value of a field asked for in a particular transaction? |
298 | 301 | $transaction = $this->currentTransaction(); |
— | — | @@ -329,8 +332,9 @@ |
330 | 333 | |
331 | 334 | //not in the map, or hard coded. What then? |
332 | 335 | //Complain furiously, for your code is faulty. |
333 | | - //TODO: Something that plays nice with others, instead of... |
334 | | - die( "getValue found NOTHING for $gateway_field_name, $transaction." ); |
| 336 | + $msg = self::getGatewayName() . ': Requested value ' . $gateway_field_name . ' cannot be found in the transactions structure.'; |
| 337 | + self::log( $msg, LOG_CRIT ); |
| 338 | + throw new MWException( $msg ); |
335 | 339 | } |
336 | 340 | |
337 | 341 | function buildRequestNameValueString() { |
— | — | @@ -418,52 +422,66 @@ |
419 | 423 | * that maps to a first-level key in the $transactions array. |
420 | 424 | */ |
421 | 425 | function do_transaction( $transaction ) { |
422 | | - $this->currentTransaction( $transaction ); |
423 | | - //update the contribution tracking data |
424 | | - $this->incrementNumAttempt(); |
| 426 | + try { |
| 427 | + $this->currentTransaction( $transaction ); |
| 428 | + //update the contribution tracking data |
| 429 | + $this->incrementNumAttempt(); |
425 | 430 | |
426 | | - //if we're supposed to add the donor data to the session, do that. |
427 | | - if ( $this->transaction_option( 'addDonorDataToSession' ) ) { |
428 | | - $this->addDonorDataToSession(); |
429 | | - } |
| 431 | + //if we're supposed to add the donor data to the session, do that. |
| 432 | + if ( $this->transaction_option( 'addDonorDataToSession' ) ) { |
| 433 | + $this->addDonorDataToSession(); |
| 434 | + } |
430 | 435 | |
431 | | - $this->runPreProcess(); //many hooks get fired here... |
432 | | - //TODO: Uhmmm... what if none of the validate hooks are enabled? |
433 | | - //Currently, I think that means the transaction stops here, and that's not quite right. |
434 | | - //...is it? |
435 | | - // if the transaction was NOT flagged for processing by something in runPreProcess()... |
436 | | - if ( $this->action != 'process' ) { |
437 | | - self::log( "Transaction failed pre-process checks." . print_r( $this->getData(), true ) ); |
| 436 | + $this->runPreProcess(); //many hooks get fired here... |
| 437 | + //TODO: Uhmmm... what if none of the validate hooks are enabled? |
| 438 | + //Currently, I think that means the transaction stops here, and that's not quite right. |
| 439 | + //...is it? |
| 440 | + // if the transaction was NOT flagged for processing by something in runPreProcess()... |
| 441 | + if ( $this->action != 'process' ) { |
| 442 | + self::log( "Transaction failed pre-process checks." . print_r( $this->getData(), true ) ); |
| 443 | + return array( |
| 444 | + 'status' => false, |
| 445 | + //TODO: appropriate messages. |
| 446 | + 'message' => "$transaction : Failed failed pre-process checks. Somebody PLEASE override me!", |
| 447 | + 'errors' => array( |
| 448 | + '1000000' => 'pre-process failed you.' //...stupid code. |
| 449 | + ), |
| 450 | + 'action' => $this->action, |
| 451 | + ); |
| 452 | + } |
| 453 | + |
| 454 | + // expose a hook for external handling of trxns ready for processing |
| 455 | + if ( $this->transaction_option( 'do_processhooks' ) ) { |
| 456 | + wfRunHooks( 'GatewayProcess', array( &$this ) ); //don't think anybody is using this yet, but you could! |
| 457 | + } |
| 458 | + |
| 459 | + $this->dataObj->updateContributionTracking( defined( 'OWA' ) ); |
| 460 | + |
| 461 | + if ( $this->getCommunicationType() === 'xml' ) { |
| 462 | + $this->getStopwatch( "buildRequestXML" ); |
| 463 | + $curlme = $this->buildRequestXML(); |
| 464 | + $this->saveCommunicationStats( "buildRequestXML", $transaction ); |
| 465 | + } |
| 466 | + |
| 467 | + if ( $this->getCommunicationType() === 'namevalue' ) { |
| 468 | + //buildRequestNameValueString() |
| 469 | + $this->getStopwatch( "buildRequestNameValueString" ); |
| 470 | + $curlme = $this->buildRequestNameValueString(); |
| 471 | + $this->saveCommunicationStats( "buildRequestNameValueString", $transaction ); |
| 472 | + } |
| 473 | + } catch ( MWException $e ) { |
| 474 | + self::log( "Malformed gateway definition. Cannot continue: Aborting.", LOG_CRIT ); |
438 | 475 | return array( |
439 | 476 | 'status' => false, |
440 | 477 | //TODO: appropriate messages. |
441 | | - 'message' => "$transaction : Failed failed pre-process checks. Somebody PLEASE override me!", |
| 478 | + 'message' => "$transaction : Malformed gateway definition. Cannot continue: Aborting.", |
442 | 479 | 'errors' => array( |
443 | | - '1000000' => 'pre-process failed you.' //...stupid code. |
| 480 | + '1000000' => 'Faulty Code! Bad programmer. Bad!' //...please change this. |
444 | 481 | ), |
445 | 482 | 'action' => $this->action, |
446 | 483 | ); |
447 | 484 | } |
448 | 485 | |
449 | | - // expose a hook for external handling of trxns ready for processing |
450 | | - if ( $this->transaction_option( 'do_processhooks' ) ) { |
451 | | - wfRunHooks( 'GatewayProcess', array( &$this ) ); //don't think anybody is using this yet, but you could! |
452 | | - } |
453 | | - |
454 | | - $this->dataObj->updateContributionTracking( defined( 'OWA' ) ); |
455 | | - if ( $this->getCommunicationType() === 'xml' ) { |
456 | | - $this->getStopwatch( "buildRequestXML" ); |
457 | | - $curlme = $this->buildRequestXML(); |
458 | | - $this->saveCommunicationStats( "buildRequestXML", $transaction ); |
459 | | - } |
460 | | - |
461 | | - if ( $this->getCommunicationType() === 'namevalue' ) { |
462 | | - //buildRequestNameValueString() |
463 | | - $this->getStopwatch( "buildRequestNameValueString" ); |
464 | | - $curlme = $this->buildRequestNameValueString(); |
465 | | - $this->saveCommunicationStats( "buildRequestNameValueString", $transaction ); |
466 | | - } |
467 | | - |
468 | 486 | //start looping here, if we're the sort of transaction that needs to do that. |
469 | 487 | $stopflag = false; |
470 | 488 | $counter = 0; |
— | — | @@ -542,7 +560,7 @@ |
543 | 561 | |
544 | 562 | // log that the transaction is essentially complete |
545 | 563 | self::log( $this->getData( 'order_id' ) . " Transaction complete." ); |
546 | | - |
| 564 | + |
547 | 565 | //if we're not actively adding the donor data to the session, kill it. |
548 | 566 | if ( !$this->transaction_option( 'addDonorDataToSession' ) ) { |
549 | 567 | $this->unsetAllGatewaySessionData(); |
— | — | @@ -599,6 +617,11 @@ |
600 | 618 | if ( !isset( $current_transaction ) ) { |
601 | 619 | return false; |
602 | 620 | } |
| 621 | + if ( empty( $this->transactions ) || !is_array( $this->transactions ) || !array_key_exists( $current_transaction, $this->transactions ) ) { |
| 622 | + $msg = self::getGatewayName() . ': Transactions structure is malformed! ' . $current_transaction . ' transaction cannot be constructed.'; |
| 623 | + self::log( $msg, LOG_CRIT ); |
| 624 | + throw new MWException( $msg ); |
| 625 | + } |
603 | 626 | return $current_transaction; |
604 | 627 | } |
605 | 628 | |
— | — | @@ -793,15 +816,15 @@ |
794 | 817 | */ |
795 | 818 | function saveCommunicationStats( $function = '', $additional = '', $vars = '' ) { |
796 | 819 | $params = array( ); |
797 | | - if ( self::getGlobal( 'SaveCommStats' ) ) { |
| 820 | + if ( self::getGlobal( 'SaveCommStats' ) ) { |
798 | 821 | $db = ContributionTrackingProcessor::contributionTrackingConnection(); |
799 | | - |
| 822 | + |
800 | 823 | //TODO: Actually define this table somewhere in the code, once we |
801 | 824 | //are reasonably certain we know what we want to see in it. |
802 | | - if ( !( $db->tableExists( 'communication_stats' ) ) ){ |
| 825 | + if ( !( $db->tableExists( 'communication_stats' ) ) ) { |
803 | 826 | return; |
804 | 827 | } |
805 | | - |
| 828 | + |
806 | 829 | $params['contribution_id'] = $this->dataObj->getVal( 'contribution_tracking_id' ); |
807 | 830 | $params['ts'] = $db->timestamp(); |
808 | 831 | $params['duration'] = $this->getStopwatch( __FUNCTION__ ); |
— | — | @@ -990,32 +1013,6 @@ |
991 | 1014 | return $ret; |
992 | 1015 | } |
993 | 1016 | |
994 | | - /** |
995 | | - * Get the transaction type |
996 | | - * |
997 | | - * @return string|false |
998 | | - */ |
999 | | - public function getTransactionType() { |
1000 | | - |
1001 | | - return $this->transaction_type; |
1002 | | - } |
1003 | | - |
1004 | | - /** |
1005 | | - * Set the transaction type |
1006 | | - * |
1007 | | - * @see GatewayAdapter::currentTransaction() |
1008 | | - * |
1009 | | - * @param string|false $transaction_type |
1010 | | - */ |
1011 | | - public function setTransactionType( $transaction_type ) { |
1012 | | - |
1013 | | - $transaction_type = empty( $transaction_type ) ? false : $transaction_type; |
1014 | | - |
1015 | | - $this->transaction_type = $transaction_type; |
1016 | | - |
1017 | | - $this->currentTransaction( $this->transaction_type ); |
1018 | | - } |
1019 | | - |
1020 | 1017 | public function getTransactionAllResults() { |
1021 | 1018 | if ( !empty( $this->transaction_results ) && is_array( $this->transaction_results ) ) { |
1022 | 1019 | return $this->transaction_results; |