r71725 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71724‎ | r71725 | r71726 >
Date:18:48, 26 August 2010
Author:awjrichards
Status:deferred
Tags:
Comment:
Updated payflowpro gateway extra extensions (with the exception of recaptcha, which will be changing drastically shortly) to be more MW-friendly; removed erroneous & in function calls; all as per http://www.mediawiki.org/wiki/Special:Code/MediaWiki/70919#c8510
Modified paths:
  • /trunk/extensions/DonationInterface/payflowpro_gateway/extras/conversion_log/conversion_log.body.php (added) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/extras/conversion_log/conversion_log.php (replaced) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/extras/extras.body.php (added) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/extras/extras.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/extras/minfraud/minfraud.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/extras/minfraud/minfraud.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
@@ -147,24 +147,24 @@
148148 $this->fnPayflowDisplayForm( $data, $error );
149149 } else { // The submitted form data is valid, so process it
150150 // allow any external validators to have their way with the data
151 - wfRunHooks( 'PayflowGatewayValidate', array( &$this, &$data ));
 151+ wfRunHooks( 'PayflowGatewayValidate', array( $this, $data ));
152152
153153 // if the transaction was flagged for review
154154 if ( $this->action == 'review' ) {
155155 // expose a hook for external handling of trxns flagged for review
156 - wfRunHooks( 'PayflowGatewayReview', array( &$this, &$data ));
 156+ wfRunHooks( 'PayflowGatewayReview', array( $this, $data ));
157157 }
158158
159159 // if the transaction was flagged to be 'challenged'
160160 if ( $this->action == 'challenge' ) {
161161 // expose a hook for external handling of trxns flagged for challenge (eg captcha)
162 - wfRunHooks( 'PayflowGatewayChallenge', array( &$this, &$data ));
 162+ wfRunHooks( 'PayflowGatewayChallenge', array( $this, $data ));
163163 }
164164
165165 // if the transaction was flagged for rejection
166166 if ( $this->action == 'reject' ) {
167167 // expose a hook for external handling of trxns flagged for rejection
168 - wfRunHooks( 'PayflowGatewayReject', array( &$this, &$data ));
 168+ wfRunHooks( 'PayflowGatewayReject', array( $this, $data ));
169169
170170 $this->fnPayflowDisplayDeclinedResults( '' );
171171 $this->fnPayflowUnsetEditToken();
@@ -173,13 +173,13 @@
174174 // if the transaction was flagged for processing
175175 if ( $this->action == 'process' ) {
176176 // expose a hook for external handling of trxns ready for processing
177 - wfRunHooks( 'PayflowGatewayProcess', array( &$this, &$data ));
 177+ wfRunHooks( 'PayflowGatewayProcess', array( $this, $data ));
178178 $this->fnPayflowProcessTransaction( $data, $payflow_data );
179179 $this->fnPayflowUnsetEditToken();
180180 }
181181
182182 // expose a hook for any post processing
183 - wfRunHooks( 'PayflowGatewayPostProcess', array( &$this, &$data ));
 183+ wfRunHooks( 'PayflowGatewayPostProcess', array( $this, $data ));
184184 }
185185 } else {
186186 //Display form for the first time
@@ -466,8 +466,8 @@
467467 */
468468 public function fnPayflowDisplayForm( $data, &$error ) {
469469 global $wgOut;
470 - $form = $this->fnPayflowGenerateFormBody( &$data, &$error );
471 - $form .= $this->fnPayflowGenerateFormSubmit( &$data, &$error );
 470+ $form = $this->fnPayflowGenerateFormBody( $data, $error );
 471+ $form .= $this->fnPayflowGenerateFormSubmit( $data, $error );
472472 $wgOut->addHTML( $form );
473473 }
474474
@@ -819,7 +819,7 @@
820820 $transaction += array_merge( $data, $responseArray );
821821
822822 // hook to call stomp functions
823 - wfRunHooks( 'gwStomp', array( &$transaction ) );
 823+ wfRunHooks( 'gwStomp', array( $transaction ) );
824824
825825 if ( $wgExternalThankYouPage ) {
826826 $wgOut->redirect( $wgExternalThankYouPage . "/" . $data['language'] );
@@ -890,7 +890,7 @@
891891 $transaction += array_merge( $data, $responseArray );
892892
893893 // hook to call stomp functions
894 - wfRunHooks( 'gwPendingStomp', array( &$transaction ) );
 894+ wfRunHooks( 'gwPendingStomp', array( $transaction ) );
895895
896896 $thankyou = wfMsg( 'payflowpro_gateway-thankyou' );
897897
Index: trunk/extensions/DonationInterface/payflowpro_gateway/extras/minfraud/minfraud.body.php
@@ -35,7 +35,6 @@
3636 parent::__construct();
3737 $dir = dirname( __FILE__ ) .'/';
3838 require_once( $dir . "ccfd/CreditCardFraudDetection.php" );
39 - //require_once( $dir . "../../includes/countryCodes.inc" );
4039 global $wgMinFraudLicenseKey, $wgMinFraudActionRanges;
4140
4241 // set the minfraud license key, go no further if we don't have it
@@ -56,7 +55,7 @@
5756 */
5857 public function validate( &$pfp_gateway_object, &$data ) {
5958 // see if we can bypass minfraud
60 - if ( $this->can_bypass_minfraud( $pfp_gateway_object, &$data )) return TRUE;
 59+ if ( $this->can_bypass_minfraud( $pfp_gateway_object, $data )) return TRUE;
6160
6261 $minfraud_query = $this->build_query( $data );
6362 $this->query_minfraud( $minfraud_query );
Index: trunk/extensions/DonationInterface/payflowpro_gateway/extras/minfraud/minfraud.php
@@ -2,7 +2,7 @@
33 /**
44 * Validates a transaction against MaxMind's minFraud service
55 *
6 - * For more detailf on minFraud, go: http://www.maxmind.com/app/minfraud
 6+ * For more details on minFraud, go: http://www.maxmind.com/app/minfraud
77 *
88 * To install:
99 * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/minfraud/minfraud.php" );
@@ -21,17 +21,8 @@
2222 );
2323
2424 /**
25 - * Full path to file to use for logging for Payflowpro Gateway scripts
26 - *
27 - * Declare in LocalSettings.php
28 - */
29 -global $wgPayflowGatewayLog;
30 -$wgPayflowGatewayLog = '';
31 -
32 -/**
3325 * Your minFraud license key.
3426 */
35 -global $wgMinFraudLicenseKey;
3627 $wgMinFraudLicenseKey = '';
3728
3829 /**
@@ -50,7 +41,6 @@
5142 * These are evauluated on a >= or <= basis. Please refer to minFraud
5243 * documentation for a thorough explanation of the 'riskScore'.
5344 */
54 -global $wgMinFraudActionRanges;
5545 $wgMinFraudActionRanges = array(
5646 'process' => array( 0, 100 ),
5747 'review' => array( -1, -1 ),
@@ -60,7 +50,6 @@
6151
6252 $dir = dirname( __FILE__ ) . "/";
6353 require_once( $dir . "../../includes/countryCodes.inc" );
64 -$wgAutoloadClasses['PayflowProGateway_Extras'] = $dir . "../extras.php";
6554 $wgAutoloadClasses['PayflowProGateway_Extras_MinFraud'] = $dir . "minfraud.body.php";
6655
6756 /**
Index: trunk/extensions/DonationInterface/payflowpro_gateway/extras/conversion_log/conversion_log.body.php
@@ -0,0 +1,39 @@
 2+<?php
 3+class PayflowProGateway_Extras_ConversionLog extends PayflowProGateway_Extras {
 4+ static $instance;
 5+
 6+ /**
 7+ * Logs the response from a payflow transaction
 8+ */
 9+ public function post_process( &$pfp_gateway_object, &$data ) {
 10+ // if the trxn has been outright rejected, log it
 11+ if ( $pfp_gateway_object->action == 'reject' ) {
 12+ $this->log(
 13+ $data[ 'contribution_tracking_id' ],
 14+ 'Rejected'
 15+ );
 16+ return TRUE;
 17+ }
 18+
 19+ //make sure the payflow response property has been set (signifying a transaction has been made)
 20+ if ( !$pfp_gateway_object->payflow_response ) return FALSE;
 21+
 22+ $this->log(
 23+ $data[ 'contribution_tracking_id' ],
 24+ "Payflow response: " . addslashes( $pfp_gateway_object->payflow_response[ 'RESPMSG' ] ),
 25+ '"' . addslashes( json_encode( $pfp_gateway_object->payflow_response )) . '"'
 26+ );
 27+ return TRUE;
 28+ }
 29+
 30+ static function onPostProcess( &$pfp_gateway_object, &$data ) {
 31+ return self::singleton()->post_process( $pfp_gateway_object, $data );
 32+ }
 33+
 34+ static function singleton() {
 35+ if ( !self::$instance ) {
 36+ self::$instance = new self;
 37+ }
 38+ return self::$instance;
 39+ }
 40+}
Property changes on: trunk/extensions/DonationInterface/payflowpro_gateway/extras/conversion_log/conversion_log.body.php
___________________________________________________________________
Added: svn:eol-style
141 + native
Index: trunk/extensions/DonationInterface/payflowpro_gateway/extras/conversion_log/conversion_log.php
@@ -1,38 +0,0 @@
2 -<?php
3 -/**
4 - * Extra to log payflow response during post processing hook
5 - *
6 - * @fixme Class/file names should likely change to reflect change in purpose...
7 - *
8 - * To install:
9 - * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/conversion_log/conversion_log.php" )
10 - * In LocalSettings.php:
11 - * $wgHooks["PayflowGatewayPostProcess"][] = array( new PayflowProGateway_Extras_ConversionLog, 'post_process' ); // sets this script to log some information after a transaction has been processed by PayflowPro
12 - */
13 -require_once( dirname( __FILE__ ) . "/../extras.php" );
14 -class PayflowProGateway_Extras_ConversionLog extends PayflowProGateway_Extras {
15 -
16 - /**
17 - * Logs the response from a payflow transaction
18 - */
19 - public function post_process( &$pfp_gateway_object, &$data ) {
20 - // if the trxn has been outright rejected, log it
21 - if ( $pfp_gateway_object->action == 'reject' ) {
22 - $this->log(
23 - $data[ 'contribution_tracking_id' ],
24 - 'Rejected'
25 - );
26 - return TRUE;
27 - }
28 -
29 - //make sure the payflow response property has been set (signifying a transaction has been made)
30 - if ( !$pfp_gateway_object->payflow_response ) return FALSE;
31 -
32 - $this->log(
33 - $data[ 'contribution_tracking_id' ],
34 - "Payflow response: " . addslashes( $pfp_gateway_object->payflow_response[ 'RESPMSG' ] ),
35 - '"' . addslashes( json_encode( $pfp_gateway_object->payflow_response )) . '"'
36 - );
37 - return TRUE;
38 - }
39 -}
Index: trunk/extensions/DonationInterface/payflowpro_gateway/extras/conversion_log/conversion_log.php
@@ -0,0 +1,26 @@
 2+<?php
 3+/**
 4+ * Extra to log payflow response during post processing hook
 5+ *
 6+ * @fixme Class/file names should likely change to reflect change in purpose...
 7+ *
 8+ * To install:
 9+ * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/conversion_log/conversion_log.php"
 10+ */
 11+
 12+if ( !defined( 'MEDIAWIKI' ) ) {
 13+ die( "This file is part of the Conversion Log for PayflowPro Gateway extension. It is not a valid entry point.\n");
 14+}
 15+
 16+$wgExtensionCredits['validextensionclass'][] = array(
 17+ 'name' => 'conversion log',
 18+ 'author' =>'Arthur Richards',
 19+ 'url' => '',
 20+ 'description' => "This extension handles logging for Payflow Gateway extension 'extras'"
 21+);
 22+
 23+$dir = dirname( __FILE__ ) . "/";
 24+$wgAutoloadClasses['PayflowProGateway_Extras_ConversionLog'] = $dir . "conversion_log.body.php";
 25+
 26+// Sets the 'conversion log' as logger for post-processing
 27+$wgHooks["PayflowGatewayPostProcess"][] = array( "PayflowProGateway_Extras_ConversionLog::onPostProcess" );
Index: trunk/extensions/DonationInterface/payflowpro_gateway/extras/extras.body.php
@@ -0,0 +1,78 @@
 2+<?php
 3+/**
 4+ * An abstract class for payflowpro gateway 'extras'
 5+ */
 6+
 7+abstract class PayflowProGateway_Extras {
 8+ /**
 9+ * File handle for log file
 10+ * @var public
 11+ */
 12+ public $log_fh = NULL;
 13+
 14+ public function __construct() {
 15+ global $wgPayflowGatewayLog;
 16+ // prepare the log file if the user has specified one
 17+ if ( strlen( $wgPayflowGatewayLog) > 0 ) $this->prepare_log_file( $wgPayflowGatewayLog );
 18+ }
 19+
 20+ /**
 21+ * Prepare a log file
 22+ *
 23+ * @param string path to log file
 24+ * @return resource Pointer for the log file
 25+ */
 26+ protected function prepare_log_file( $log_file ){
 27+ $this->log_fh = fopen( $log_file, 'a+' );
 28+ }
 29+
 30+ /**
 31+ * Writes message to a log file
 32+ *
 33+ * If a log file does not exist and could not be created,
 34+ * do nothing.
 35+ * @fixme Perhaps lack of log file can be handled better?
 36+ * @param string The message to log
 37+ */
 38+ public function log( $id='', $status='', $data='' ) {
 39+ if ( !$this->log_fh ) {
 40+ return;
 41+ }
 42+ $msg = '"' . date( 'c' ) . '"';
 43+ $msg .= "\t" . '"' . $id . '"';
 44+ $msg .= "\t" . '"' . $status . '"';
 45+ $msg .= "\t" . $data . "\n";
 46+ fwrite( $this->log_fh, $msg );
 47+ }
 48+
 49+ /**
 50+ * Generate a hash of some data
 51+ * @param string the data to hash
 52+ * @return string The hash of the data
 53+ */
 54+ public function generate_hash( $data ) {
 55+ global $wgPayflowGatewaySalt;
 56+ return hash( "sha512", $wgPayflowGatewaySalt . $data );
 57+ }
 58+
 59+ /**
 60+ * Compare a hash to the hash of some given data
 61+ * @param string $hash A given hash
 62+ * @param string $data The data to hash and compare to $hash
 63+ * @return bool
 64+ */
 65+ public function compare_hash( $hash, $data ) {
 66+ if ( $hash == $this->generate_hash( $data )) {
 67+ return TRUE;
 68+ }
 69+
 70+ return FALSE;
 71+ }
 72+
 73+ /**
 74+ * Close the open log file handler if it's open
 75+ */
 76+ public function __destruct() {
 77+ if ( $this->log_fh ) fclose( $this->log_fh );
 78+ }
 79+}
Index: trunk/extensions/DonationInterface/payflowpro_gateway/extras/extras.php
@@ -1,78 +1,29 @@
22 <?php
33 /**
4 - * An abstract class for payflowpro gateway 'extras'
 4+ * An abstract class and set up for payflowpro gateway 'extras'
 5+ *
 6+ * To install:
 7+ * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/extras.php"
 8+ * Note: This should be specified in LocalSettings.php BEFORE requiring any of the other 'extras'
59 */
610
7 -abstract class PayflowProGateway_Extras {
8 - /**
9 - * File handle for log file
10 - * @var public
11 - */
12 - public $log_fh = NULL;
 11+if ( !defined( 'MEDIAWIKI' ) ) {
 12+ die( "This file is part of PayflowPro Gateway extension. It is not a valid entry point.\n");
 13+}
1314
14 - public function __construct() {
15 - global $wgPayflowGatewayLog;
16 - // prepare the log file if the user has specified one
17 - if ( strlen( $wgPayflowGatewayLog) > 0 ) $this->prepare_log_file( $wgPayflowGatewayLog );
18 - }
 15+$wgExtensionCredits['payflowprogateway_extras'][] = array(
 16+ 'name' => 'extras',
 17+ 'author' =>'Arthur Richards',
 18+ 'url' => '',
 19+ 'description' => "This extension handles some of the set up required for PayflowPro Gateway extras"
 20+);
1921
20 - /**
21 - * Prepare a log file
22 - *
23 - * @param string path to log file
24 - * @return resource Pointer for the log file
25 - */
26 - protected function prepare_log_file( $log_file ){
27 - $this->log_fh = fopen( $log_file, 'a+' );
28 - }
 22+/**
 23+ * Full path to file to use for logging for Payflowpro Gateway scripts
 24+ *
 25+ * Declare in LocalSettings.php
 26+ */
 27+$wgPayflowGatewayLog = '';
2928
30 - /**
31 - * Writes message to a log file
32 - *
33 - * If a log file does not exist and could not be created,
34 - * do nothing.
35 - * @fixme Perhaps lack of log file can be handled better?
36 - * @param string The message to log
37 - */
38 - public function log( $id='', $status='', $data='' ) {
39 - if ( !$this->log_fh ) {
40 - return;
41 - }
42 - $msg = '"' . date( 'c' ) . '"';
43 - $msg .= "\t" . '"' . $id . '"';
44 - $msg .= "\t" . '"' . $status . '"';
45 - $msg .= "\t" . $data . "\n";
46 - fwrite( $this->log_fh, $msg );
47 - }
48 -
49 - /**
50 - * Generate a hash of some data
51 - * @param string the data to hash
52 - * @return string The hash of the data
53 - */
54 - public function generate_hash( $data ) {
55 - global $wgPayflowGatewaySalt;
56 - return hash( "sha512", $wgPayflowGatewaySalt . $data );
57 - }
58 -
59 - /**
60 - * Compare a hash to the hash of some given data
61 - * @param string $hash A given hash
62 - * @param string $data The data to hash and compare to $hash
63 - * @return bool
64 - */
65 - public function compare_hash( $hash, $data ) {
66 - if ( $hash == $this->generate_hash( $data )) {
67 - return TRUE;
68 - }
69 -
70 - return FALSE;
71 - }
72 -
73 - /**
74 - * Close the open log file handler if it's open
75 - */
76 - public function __destruct() {
77 - if ( $this->log_fh ) fclose( $this->log_fh );
78 - }
79 -}
 29+$dir = dirname( __FILE__ ) . "/";
 30+$wgAutoloadClasses['PayflowProGateway_Extras'] = $dir . "extras.body.php";
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.php
@@ -45,10 +45,8 @@
4646 * potentially leave you and your users vulnerable to CSRF or other forms of
4747 * attack.
4848 */
49 -global $wgPayflowGatewaySalt, $wgSecretKey;
5049 $wgPayflowGatewaySalt = $wgSecretKey;
5150
52 -global $wgPayflowGatewayDBserver, $wgPayflowGatewayDBname, $wgPayflowGatewayDBuser, $wgPayflowGatewayDBpassword;
5351 $wgPayflowGatewayDBserver = $wgDBserver;
5452 $wgPayflowGatewayDBname = $wgDBname;
5553 $wgPayflowGatewayDBuser = $wgDBuser;
@@ -114,8 +112,6 @@
115113 function pfpGatewayPage( &$url ) {
116114 global $wgScript;
117115
118 - //$url['payflow'] = 'https://payments.wikimedia.org/index.php' . '?title=Special:PayflowProGateway';
119 - //$url['payflow'] = 'http://c2p2.fkbuild.com/index.php?title=Special:PayflowProGateway';
120116 $url['payflow'] = $wgScript . "?title=Special:PayflowProGateway";
121117 return true;
122118 }

Status & tagging log