r98581 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98580‎ | r98581 | r98582 >
Date:23:09, 30 September 2011
Author:khorn
Status:ok (Comments)
Tags:
Comment:
Various bug squashings after my last big commit. Also moved all the runHooks commands to inside the gateway adapter object. Still testing all the hook types. r98498
Modified paths:
  • /branches/fundraising/extensions/DonationInterface/donationinterface.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/minfraud/ccfd/CreditCardFraudDetection.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/minfraud/minfraud.body.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/extras/recaptcha/recaptcha.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_common/GatewayForm.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php (modified) (history)
  • /branches/fundraising/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php (modified) (history)

Diff [purge]

Index: branches/fundraising/extensions/DonationInterface/donationinterface.php
@@ -20,10 +20,19 @@
2121
2222 $donationinterface_dir = dirname( __FILE__ ) . '/';
2323
 24+//TODO: It may be a good idea to make all these stop behaving like they're independent extensions.
 25+//Better yet, we should decide if they're a required part of this or not,
 26+//and split 'em entirely off, or roll 'em all the way in to this file.
2427 require_once( $donationinterface_dir . 'donate_interface/donate_interface.php' );
2528 require_once( $donationinterface_dir . 'activemq_stomp/activemq_stomp.php' );
2629
 30+require_once( $donationinterface_dir . 'extras/extras.php' );
 31+require_once( $donationinterface_dir . 'extras/custom_filters/custom_filters.php' );
 32+require_once( $donationinterface_dir . 'extras/conversion_log/conversion_log.php' );
 33+require_once( $donationinterface_dir . 'extras/minfraud/minfraud.php' );
 34+require_once( $donationinterface_dir . 'extras/recaptcha/recaptcha.php' );
2735
 36+
2837 /**
2938 * Global form dir and whitelist
3039 */
Index: branches/fundraising/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
@@ -70,41 +70,16 @@
7171 if ( $form_errors ) {
7272 $this->displayForm( $data, $this->errors );
7373 } else { // The submitted form data is valid, so process it
74 - // allow any external validators to have their way with the data
75 - self::log( $data['order_id'] . " Preparing to query MaxMind" );
76 - wfRunHooks( 'GatewayValidate', array( &$this->adapter ) );
77 - self::log( $data['order_id'] . ' Finished querying Maxmind' );
 74+ $result = $this->adapter->do_transaction( 'Card' );
7875
79 - // if the transaction was flagged for review
80 - if ( $this->action == 'review' ) {
81 - // expose a hook for external handling of trxns flagged for review
82 - wfRunHooks( 'GatewayReview', array( &$this->adapter ) );
83 - }
84 -
85 - // if the transaction was flagged to be 'challenged'
86 - if ( $this->action == 'challenge' ) {
87 - // expose a hook for external handling of trxns flagged for challenge (eg captcha)
88 - wfRunHooks( 'GatewayChallenge', array( &$this->adapter ) );
89 - }
90 -
9176 // if the transaction was flagged for rejection
92 - if ( $this->action == 'reject' ) {
93 - // expose a hook for external handling of trxns flagged for rejection
94 - wfRunHooks( 'GatewayReject', array( &$this->adapter ) );
95 -
 77+ if ( $this->adapter->action == 'reject' ) {
9678 $this->fnPayflowDisplayDeclinedResults( '' );
97 - $this->fnPayflowUnsetEditToken();
9879 }
9980
100 - // if the transaction was flagged for processing
101 - if ( $this->action == 'process' ) {
102 - // expose a hook for external handling of trxns ready for processing
103 - wfRunHooks( 'GatewayProcess', array( &$this->adapter ) );
104 - $this->fnPayflowProcessTransaction( $data, $payflow_data );
 81+ if ( $this->adapter->action == 'process' ) {
 82+ $this->fnPayflowDisplayResults( $result );
10583 }
106 -
107 - // expose a hook for any post processing
108 - wfRunHooks( 'GatewayPostProcess', array( &$this->adapter ) );
10984 }
11085 } else {
11186 // Display form for the first time
@@ -120,114 +95,6 @@
12196 }
12297
12398 /**
124 - * Sends a name-value pair string to Payflow gateway
125 - *
126 - * @param $data Array: array of user input
127 - * @param $payflow_data Array: array of necessary Payflow variables to
128 - * include in string (i.e. Vendor, password)
129 - */
130 - private function fnPayflowProcessTransaction( $data, $payflow_data ) {
131 - global $wgOut, $wgDonationTestingMode, $wgPayflowProGatewayUseHTTPProxy, $wgPayflowProGatewayHTTPProxy, $wgPayflowProTimeout;
132 -
133 - // update contribution tracking
134 - $this->updateContributionTracking( $data, defined( 'OWA' ) );
135 -
136 - // create payflow query string, include string lengths
137 - $queryArray = array(
138 - 'TRXTYPE' => $payflow_data['trxtype'],
139 - 'TENDER' => $payflow_data['tender'],
140 - 'USER' => $payflow_data['user'],
141 - 'VENDOR' => $payflow_data['vendor'],
142 - 'PARTNER' => $payflow_data['partner'],
143 - 'PWD' => $payflow_data['password'],
144 - 'ACCT' => $data['card_num'],
145 - 'EXPDATE' => $data['expiration'],
146 - 'AMT' => $data['amount'],
147 - 'FIRSTNAME' => $data['fname'],
148 - 'LASTNAME' => $data['lname'],
149 - 'STREET' => $data['street'],
150 - 'CITY' => $data['city'],
151 - 'STATE' => $data['state'],
152 - 'COUNTRY' => $data['country'],
153 - 'ZIP' => $data['zip'],
154 - 'INVNUM' => $data['order_id'],
155 - 'CVV2' => $data['cvv'],
156 - 'CURRENCY' => $data['currency'],
157 - 'VERBOSITY' => $payflow_data['verbosity'],
158 - 'CUSTIP' => $payflow_data['user_ip'],
159 - );
160 -
161 - foreach ( $queryArray as $name => $value ) {
162 - $query[] = $name . '[' . strlen( $value ) . ']=' . $value;
163 - }
164 -
165 - $queryString = implode( '&', $query );
166 -
167 - $payflow_query = $queryString;
168 -
169 - // assign header data necessary for the curl_setopt() function
170 - $user_agent = Http::userAgent();
171 - $headers[] = 'Content-Type: text/namevalue';
172 - $headers[] = 'Content-Length : ' . strlen( $payflow_query );
173 - $headers[] = 'X-VPS-Client-Timeout: 45';
174 - $headers[] = 'X-VPS-Request-ID:' . $data['order_id'];
175 - $ch = curl_init();
176 - $paypalPostTo = isset( $wgDonationTestingMode ) ? 'testingurl' : 'paypalurl';
177 - curl_setopt( $ch, CURLOPT_URL, $payflow_data[$paypalPostTo] );
178 - curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
179 - curl_setopt( $ch, CURLOPT_USERAGENT, $user_agent );
180 - curl_setopt( $ch, CURLOPT_HEADER, 1 );
181 - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
182 - curl_setopt( $ch, CURLOPT_TIMEOUT, $wgPayflowProTimeout );
183 - curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 0 );
184 - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
185 - curl_setopt( $ch, CURLOPT_POSTFIELDS, $payflow_query );
186 - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 2 );
187 - curl_setopt( $ch, CURLOPT_FORBID_REUSE, true );
188 - curl_setopt( $ch, CURLOPT_POST, 1 );
189 -
190 - // set proxy settings if necessary
191 - if ( $wgPayflowProGatewayUseHTTPProxy ) {
192 - curl_setopt( $ch, CURLOPT_HTTPPROXYTUNNEL, 1 );
193 - curl_setopt( $ch, CURLOPT_PROXY, $wgPayflowProGatewayHTTPProxy );
194 - }
195 -
196 - // As suggested in the PayPal developer forum sample code, try more than once to get a response
197 - // in case there is a general network issue
198 - $i = 1;
199 -
200 - while ( $i++ <= 3 ) {
201 - self::log( $data['order_id'] . ' Preparing to send transaction to PayflowPro' );
202 - $result = curl_exec( $ch );
203 - $headers = curl_getinfo( $ch );
204 -
205 - if ( $headers['http_code'] != 200 && $headers['http_code'] != 403 ) {
206 - self::log( $data['order_id'] . ' Failed sending transaction to PayflowPro, retrying' );
207 - sleep( 1 );
208 - } elseif ( $headers['http_code'] == 200 || $headers['http_code'] == 403 ) {
209 - self::log( $data['order_id'] . ' Finished sending transaction to PayflowPro' );
210 - break;
211 - }
212 - }
213 -
214 - if ( $headers['http_code'] != 200 ) {
215 - $wgOut->addHTML( '<h3>No response from credit card processor. Please try again later!</h3><p>' );
216 - $when = time();
217 - self::log( $data['order_id'] . ' No response from credit card processor: ' . curl_error( $ch ) );
218 - curl_close( $ch );
219 - return;
220 - }
221 -
222 - curl_close( $ch );
223 -
224 - // get result string
225 - $result = strstr( $result, 'RESULT' );
226 -
227 - // parse string and display results to the user
228 - $this->fnPayflowGetResults( $data, $result );
229 - }
230 -
231 - /**
23299 * "Reads" the name-value pair result string returned by Payflow and creates corresponding error messages
233100 *
234101 * @param $data Array: array of user input
@@ -235,124 +102,43 @@
236103 *
237104 * Credit: code modified from payflowpro_example_EC.php posted (and supervised) on the PayPal developers message board
238105 */
239 - private function fnPayflowGetResults( $data, $result ) {
240 - // prepare NVP response for sorting and outputting
241 - $responseArray = array( );
242 -
243 - /**
244 - * The result response string looks like:
245 - * RESULT=7&PNREF=E79P2C651DC2&RESPMSG=Field format error&HOSTCODE=10747&DUPLICATE=1
246 - * We want to turn this into an array of key value pairs, so explode on '&' and then
247 - * split up the resulting strings into $key => $value
248 - */
249 - $result_arr = explode( "&", $result );
250 - foreach ( $result_arr as $result_pair ) {
251 - list( $key, $value ) = preg_split( "/=/", $result_pair );
252 - $responseArray[$key] = $value;
 106+ private function fnPayflowDisplayResults( $result ) {
 107+ if ( is_array( $result ) && array_key_exists( 'errors', $result ) && is_array( $result['errors'] ) ) {
 108+ foreach ( $result['errors'] as $key => $value ) {
 109+ $errorCode = $key;
 110+ $responseMsg = $value;
 111+ break; //we just want the top, and this is probably the fastest way.
 112+ }
253113 }
254114
255 - // store the response array as an object property for easy retrival/manipulation elsewhere
256 - $this->payflow_response = $responseArray;
 115+ $oid = $this->adapter->getData( 'order_id' );
 116+ $i_oid = $this->adapter->getData( 'i_order_id' );
 117+ $data = $this->adapter->getData();
257118
258 - // errors fall into three categories, "try again please", "sorry it didn't work out", and "approved"
259 - // get the result code for response array
260 - $resultCode = $responseArray['RESULT'];
261 -
262 - // initialize response message
263 - $responseMsg = '';
264 -
265 - // interpret result code, return
266 - // approved (1), denied (2), try again (3), general error (4)
267 - $errorCode = $this->fnPayflowGetResponseMsg( $resultCode, $responseMsg );
268 -
269 - // log that the transaction is essentially complete
270 - self::log( $data['order_id'] . " Transaction complete." );
271 -
272119 // if approved, display results and send transaction to the queue
273120 if ( $errorCode == '1' ) {
274 - self::log( $data['order_id'] . " " . $data['i_order_id'] . " Transaction approved.", 'payflowpro_gateway', LOG_DEBUG );
 121+ self::log( $oid . " " . $i_oid . " Transaction approved.", LOG_DEBUG );
275122 $this->fnPayflowDisplayApprovedResults( $data, $responseArray, $responseMsg );
276123 // give user a second chance to enter incorrect data
277124 } elseif ( ( $errorCode == '3' ) && ( $data['numAttempt'] < '5' ) ) {
278 - self::log( $data['order_id'] . " " . $data['i_order_id'] . " Transaction unsuccessful (invalid info).", 'payflowpro_gateway', LOG_DEBUG );
 125+ self::log( $oid . " " . $i_oid . " Transaction unsuccessful (invalid info).", LOG_DEBUG );
279126 // pass responseMsg as an array key as required by displayForm
280127 $this->errors['retryMsg'] = $responseMsg;
281128 $this->fnPayflowDisplayForm( $data, $this->errors );
282129 // if declined or if user has already made two attempts, decline
283130 } elseif ( ( $errorCode == '2' ) || ( $data['numAttempt'] >= '3' ) ) {
284 - self::log( $data['order_id'] . " " . $data['i_order_id'] . " Transaction declined.", 'payflowpro_gateway', LOG_DEBUG );
 131+ self::log( $oid . " " . $i_oid . " Transaction declined.", LOG_DEBUG );
285132 $this->fnPayflowDisplayDeclinedResults( $responseMsg );
286133 } elseif ( ( $errorCode == '4' ) ) {
287 - self::log( $data['order_id'] . " " . $data['i_order_id'] . " Transaction unsuccessful.", 'payflowpro_gateway', LOG_DEBUG );
 134+ self::log( $oid . " " . $i_oid . " Transaction unsuccessful.", LOG_DEBUG );
288135 $this->fnPayflowDisplayOtherResults( $responseMsg );
289136 } elseif ( ( $errorCode == '5' ) ) {
290 - self::log( $data['order_id'] . " " . $data['i_order_id'] . " Transaction pending.", 'payflowpro_gateway', LOG_DEBUG );
 137+ self::log( $oid . " " . $i_oid . " Transaction pending.", LOG_DEBUG );
291138 $this->fnPayflowDisplayPending( $data, $responseArray, $responseMsg );
292139 }
293140 }
294141
295 -// end display results
296 -
297142 /**
298 - * Interpret response code, return
299 - * 1 if approved
300 - * 2 if declined
301 - * 3 if invalid data was submitted by user
302 - * 4 all other errors
303 - */
304 - function fnPayflowGetResponseMsg( $resultCode, &$responseMsg ) {
305 - $responseMsg = wfMsg( 'payflowpro_gateway-response-default' );
306 -
307 - switch ( $resultCode ) {
308 - case '0':
309 - $responseMsg = wfMsg( 'payflowpro_gateway-response-0' );
310 - $errorCode = '1';
311 - break;
312 - case '126':
313 - $responseMsg = wfMsg( 'payflowpro_gateway-response-126-2' );
314 - $errorCode = '5';
315 - break;
316 - case '12':
317 - $responseMsg = wfMsg( 'payflowpro_gateway-response-12' );
318 - $errorCode = '2';
319 - break;
320 - case '13':
321 - $responseMsg = wfMsg( 'payflowpro_gateway-response-13' );
322 - $errorCode = '2';
323 - break;
324 - case '114':
325 - $responseMsg = wfMsg( 'payflowpro_gateway-response-114' );
326 - $errorCode = '2';
327 - break;
328 - case '4':
329 - $responseMsg = wfMsg( 'payflowpro_gateway-response-4' );
330 - $errorCode = '3';
331 - break;
332 - case '23':
333 - $responseMsg = wfMsg( 'payflowpro_gateway-response-23' );
334 - $errorCode = '3';
335 - break;
336 - case '24':
337 - $responseMsg = wfMsg( 'payflowpro_gateway-response-24' );
338 - $errorCode = '3';
339 - break;
340 - case '112':
341 - $responseMsg = wfMsg( 'payflowpro_gateway-response-112' );
342 - $errorCode = '3';
343 - break;
344 - case '125':
345 - $responseMsg = wfMsg( 'payflowpro_gateway-response-125-2' );
346 - $errorCode = '3';
347 - break;
348 - default:
349 - $responseMsg = wfMsg( 'payflowpro_gateway-response-default' );
350 - $errorCode = '4';
351 - }
352 -
353 - return $errorCode;
354 - }
355 -
356 - /**
357143 * Display response message to user with submitted user-supplied data
358144 *
359145 * @param $data Array: array of posted data from form
@@ -391,8 +177,6 @@
392178 // if we want to show the response
393179 $wgOut->addHTML( Xml::buildTable( $rows, array( 'class' => 'submitted-response' ) ) );
394180 }
395 - // unset edit token
396 - $this->fnPayflowUnsetEditToken();
397181 }
398182
399183 /**
@@ -408,9 +192,6 @@
409193
410194 // display response message
411195 $wgOut->addHTML( '<h3 class="response_message">' . $declinedDefault . ' ' . $responseMsg . '</h3>' );
412 -
413 - // unset edit token
414 - $this->fnPayflowUnsetEditToken();
415196 }
416197
417198 /**
@@ -426,9 +207,6 @@
427208
428209 // display response message
429210 $wgOut->addHTML( '<h3 class="response_message">' . $declinedDefault . ' ' . $responseMsg . '</h3>' );
430 -
431 - // unset edit token
432 - $this->fnPayflowUnsetEditToken();
433211 }
434212
435213 function fnPayflowDisplayPending( $data, $responseArray, $responseMsg ) {
@@ -444,9 +222,6 @@
445223 // display response message
446224 $wgOut->addHTML( '<h2 class="response_message">' . $thankyou . '</h2>' );
447225 $wgOut->addHTML( '<p>' . $responseMsg );
448 -
449 - // unset edit token
450 - $this->fnPayflowUnsetEditToken();
451226 }
452227
453228 //TODO: Remember why the heck I decided to leave this here...
Index: branches/fundraising/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php
@@ -24,7 +24,7 @@
2525 static $instance;
2626
2727 public function __construct( &$gateway_adapter ) {
28 - parent::__construct( &$gateway_adapter ); //gateway_adapter is set in there.
 28+ parent::__construct( $gateway_adapter ); //gateway_adapter is set in there.
2929 // load user action ranges and risk score
3030 $this->action_ranges = $this->getGlobal( 'CustomFiltersActionRanges' );
3131 $this->risk_score = $this->getGlobal( 'CustomFiltersRiskScore' );
@@ -63,12 +63,13 @@
6464 }
6565
6666 static function onValidate( &$gateway_adapter ) {
67 - return self::singleton( &$gateway_adapter )->validate();
 67+ $gateway_adapter->debugarray[] = 'custom filters onValidate hook!';
 68+ return self::singleton( $gateway_adapter )->validate();
6869 }
6970
7071 static function singleton( &$gateway_adapter ) {
7172 if ( !self::$instance ) {
72 - self::$instance = new self( &$gateway_adapter );
 73+ self::$instance = new self( $gateway_adapter );
7374 }
7475 return self::$instance;
7576 }
Index: branches/fundraising/extensions/DonationInterface/extras/minfraud/ccfd/CreditCardFraudDetection.php
@@ -28,8 +28,8 @@
2929 var $API_VERSION;
3030
3131 function __construct( &$gateway_adapter ) {
32 - parent::__construct( &$gateway_adapter );
33 - $this->isSecure = 1; // use HTTPS by default
 32+ parent::__construct( $gateway_adapter );
 33+ $this->isSecure = 1; // use HTTPS by default
3434 // set the allowed_fields hash
3535 $this->allowed_fields["i"] = 1;
3636 $this->allowed_fields["domain"] = 1;
Index: branches/fundraising/extensions/DonationInterface/extras/minfraud/minfraud.body.php
@@ -39,10 +39,10 @@
4040 static $instance;
4141
4242 function __construct( &$gateway_adapter, $license_key = NULL ) {
43 - parent::__construct( &$gateway_adapter );
 43+ parent::__construct( $gateway_adapter );
4444 $dir = dirname( __FILE__ ) . '/';
4545 require_once( $dir . "ccfd/CreditCardFraudDetection.php" );
46 - require_once( $dir . "../../includes/countryCodes.inc" );
 46+ //require_once( $dir . "../../includes/countryCodes.inc" );
4747 global $wgMinFraudLicenseKey, $wgMinFraudActionRanges;
4848
4949 // set the minfraud license key, go no further if we don't have it
@@ -147,7 +147,7 @@
148148 */
149149 public function get_ccfd() {
150150 if ( !$this->ccfd ) {
151 - $this->ccfd = new CreditCardFraudDetection( &$this->gateway_adapter );
 151+ $this->ccfd = new CreditCardFraudDetection( $this->gateway_adapter );
152152 }
153153 return $this->ccfd;
154154 }
@@ -270,12 +270,13 @@
271271 }
272272
273273 static function onValidate( &$gateway_adapter ) {
274 - return self::singleton( &$gateway_adapter )->validate();
 274+ $gateway_adapter->debugarray[] = "Running an onValidate hook!";
 275+ return self::singleton( $gateway_adapter )->validate();
275276 }
276277
277278 static function singleton( &$gateway_adapter ) {
278279 if ( !self::$instance ) {
279 - self::$instance = new self( &$gateway_adapter );
 280+ self::$instance = new self( $gateway_adapter );
280281 }
281282 return self::$instance;
282283 }
Index: branches/fundraising/extensions/DonationInterface/extras/recaptcha/recaptcha.php
@@ -34,8 +34,9 @@
3535 *
3636 * Default to settings in DonationInterface
3737 */
38 -$wgDonationInterfaceRecaptchaUseHTTPProxy = $wgDonationInterfaceUseHTTPProxy;
39 -$wgDonationInterfaceRecaptchaHTTPProxy = $wgDonationInterfaceHTTPProxy;
 38+//TODO: I think we can get rid of these entirely, due to the way we are now checking for globals in the extras.
 39+//$wgDonationInterfaceRecaptchaUseHTTPProxy = $wgDonationInterfaceUseHTTPProxy;
 40+//$wgDonationInterfaceRecaptchaHTTPProxy = $wgDonationInterfaceHTTPProxy;
4041
4142 /**
4243 * Use SSL to communicate with reCaptcha
Index: branches/fundraising/extensions/DonationInterface/globalcollect_gateway/globalcollect_gateway.body.php
@@ -61,7 +61,7 @@
6262 //TODO: This is short-circuiting what I really want to do here.
6363 //so stop it.
6464 $data = $this->adapter->getDisplayData();
65 -
 65+
6666 /*
6767 * The $transactionType should default to false.
6868 *
@@ -71,14 +71,14 @@
7272 */
7373 $transactionType = false;
7474 $transactionType = 'INSERT_ORDERWITHPAYMENT';
75 - $data['transaction_type'] = isset( $data['transaction_type'] ) ? $data['transaction_type'] : $transactionType;
 75+ $data['transaction_type'] = (isset( $data['transaction_type'] ) && !empty( $data['transaction_type'] ) ) ? $data['transaction_type'] : $transactionType;
7676 $this->adapter->setTransactionType( $data['transaction_type'] );
7777 unset( $transactionType );
78 -
 78+
7979 $this->adapter->log( '$transactionType: Default is set to: INSERT_ORDERWITHPAYMENT, this is a temporary hack for backwards compatibility.' );
80 - $this->adapter->log( 'Setting transaction type: ' . (string) $data['transaction_type'] );
81 -
82 -
 80+ $this->adapter->log( 'Setting transaction type: ' . ( string ) $data['transaction_type'] );
 81+
 82+
8383 // dispatch forms/handling
8484 if ( $this->adapter->checkTokens() ) {
8585 if ( $this->adapter->posted && $data['payment_method'] == 'processed' ) {
@@ -86,54 +86,51 @@
8787 $this->adapter->log( "Form posted and payment method set." );
8888
8989 // Check form for errors
90 -
91 - $options = array();
 90+
 91+ $options = array( );
9292 switch ( $this->adapter->getTransactionType() ) {
93 -
 93+
9494 case 'BANK_TRANSFER':
9595 $options['creditCard'] = false;
9696 break;
97 -
 97+
9898 case 'INSERT_ORDERWITHPAYMENT':
9999 $options['creditCard'] = true;
100100 break;
101 -
 101+
102102 default:
103103 $options['creditCard'] = true;
104104 }
105 -
 105+
106106 $form_errors = $this->validateForm( $data, $this->errors, $options );
107107 unset( $options );
108108
109109 //$form_errors = $this->fnValidateForm( $data, $this->errors );
110 -
111110 // If there were errors, redisplay form, otherwise proceed to next step
112111 if ( $form_errors ) {
113112
114113 $this->displayForm( $data, $this->errors );
115114 } else { // The submitted form data is valid, so process it
116115 // allow any external validators to have their way with the data
117 -
118116 // Execute the proper transaction code:
119117 switch ( $this->adapter->getTransactionType() ) {
120 -
 118+
121119 case 'BANK_TRANSFER':
122120 $this->executeBankTransfer( $wgOut );
123121 break;
124 -
 122+
125123 case 'INSERT_ORDERWITHPAYMENT':
126124 $this->executeInsertOrderWithPayment( $wgOut );
127125 break;
128 -
 126+
129127 default:
130 -
131 - $message = 'The transaction type [ ' . $this->adapter->getTransactionType() . ' ] was not found.';
 128+
 129+ $message = 'The transaction type [ ' . $this->adapter->getTransactionType() . ' ] was not found.';
132130 throw new Exception( $message );
133131 }
134132
135133
136134 //TODO: add all the hooks back in.
137 -
138135 }
139136 } else {
140137 // Display form for the first time
@@ -200,66 +197,7 @@
201198 }
202199 }
203200 }
204 -
205 - /**
206 - * Interpret response code, return
207 - * 1 if approved
208 - * 2 if declined
209 - * 3 if invalid data was submitted by user
210 - * 4 all other errors
211 - */
212 - function fnPayflowGetResponseMsg( $resultCode, &$responseMsg ) {
213 - $responseMsg = wfMsg( 'globalcollect_gateway-response-default' );
214201
215 - switch ( $resultCode ) {
216 - case '0':
217 - $responseMsg = wfMsg( 'globalcollect_gateway-response-0' );
218 - $errorCode = '1';
219 - break;
220 - case '126':
221 - $responseMsg = wfMsg( 'globalcollect_gateway-response-126-2' );
222 - $errorCode = '5';
223 - break;
224 - case '12':
225 - $responseMsg = wfMsg( 'globalcollect_gateway-response-12' );
226 - $errorCode = '2';
227 - break;
228 - case '13':
229 - $responseMsg = wfMsg( 'globalcollect_gateway-response-13' );
230 - $errorCode = '2';
231 - break;
232 - case '114':
233 - $responseMsg = wfMsg( 'globalcollect_gateway-response-114' );
234 - $errorCode = '2';
235 - break;
236 - case '4':
237 - $responseMsg = wfMsg( 'globalcollect_gateway-response-4' );
238 - $errorCode = '3';
239 - break;
240 - case '23':
241 - $responseMsg = wfMsg( 'globalcollect_gateway-response-23' );
242 - $errorCode = '3';
243 - break;
244 - case '24':
245 - $responseMsg = wfMsg( 'globalcollect_gateway-response-24' );
246 - $errorCode = '3';
247 - break;
248 - case '112':
249 - $responseMsg = wfMsg( 'globalcollect_gateway-response-112' );
250 - $errorCode = '3';
251 - break;
252 - case '125':
253 - $responseMsg = wfMsg( 'globalcollect_gateway-response-125-2' );
254 - $errorCode = '3';
255 - break;
256 - default:
257 - $responseMsg = wfMsg( 'globalcollect_gateway-response-default' );
258 - $errorCode = '4';
259 - }
260 -
261 - return $errorCode;
262 - }
263 -
264202 //TODO: Remember why the heck I decided to leave this here...
265203 //arguably, it's because it's slightly more "view" related, but... still, shouldn't you get stashed
266204 //in the new GatewayForm class so we can override in chlidren if we feel like it? Odd.
Index: branches/fundraising/extensions/DonationInterface/gateway_common/gateway.adapter.php
@@ -82,7 +82,7 @@
8383 protected $accountInfo;
8484 protected $url;
8585 protected $transactions;
86 -
 86+
8787 /**
8888 * $transaction_type will be set in the GatewayForm::execute()
8989 *
@@ -91,7 +91,6 @@
9292 * @see GatewayForm::execute()
9393 */
9494 protected $transaction_type = false;
95 -
9695 protected $return_value_map;
9796 protected $postdata;
9897 protected $postdatadefaults;
@@ -100,6 +99,8 @@
101100 protected $transaction_results;
102101 protected $form_class;
103102 protected $validation_errors;
 103+ public $action; //Currently, hooks need to be able to set this directly.
 104+ public $debugarray; //TODO: Take me out.
104105
105106 //ALL OF THESE need to be redefined in the children. Much voodoo depends on the accuracy of these constants.
106107 const GATEWAY_NAME = 'Donation Gateway';
@@ -332,6 +333,28 @@
333334 $this->currentTransaction( $transaction );
334335 //update the contribution tracking data
335336 $this->incrementNumAttempt();
 337+
 338+ $this->runPreProcess(); //many hooks get fired here...
 339+ //TODO: Uhmmm... what if none of the validate hooks are enabled?
 340+ //Currently, I think that means the transaction stops here, and that's not quite right.
 341+ //...is it?
 342+ // if the transaction was NOT flagged for processing by something in runPreProcess()...
 343+ if ( $this->action != 'process' ) {
 344+ self::log( "Transaction failed pre-process checks." . print_r( $this->getData(), true ) );
 345+ return array(
 346+ 'status' => false,
 347+ //TODO: appropriate messages.
 348+ 'message' => "$transaction : Failed failed pre-process checks. Somebody PLEASE override me!",
 349+ 'errors' => array(
 350+ '1000000' => 'pre-process failed you.' //...stupid code.
 351+ ),
 352+ 'action' => $this->action,
 353+ );
 354+ }
 355+
 356+ // expose a hook for external handling of trxns ready for processing
 357+ wfRunHooks( 'GatewayProcess', array( &$this ) ); //don't think anybody is using this yet, but you could!
 358+
336359 $this->dataObj->updateContributionTracking( defined( 'OWA' ) );
337360 if ( $this->getCommunicationType() === 'xml' ) {
338361 $this->getStopwatch( "buildRequestXML" );
@@ -369,13 +392,20 @@
370393 $this->setTransactionResult( $this->getResponseStatus( $formatted ), 'status' );
371394
372395 //set errors
 396+ //TODO: This "errors" business is becoming a bit of a misnomer, as the result code and message
 397+ //are frequently packaged togther in the same place, whether the transaction passed or failed.
373398 $this->setTransactionResult( $this->getResponseErrors( $formatted ), 'errors' );
374399
375400 //if we're still okay (hey, even if we're not), get relevent dataz.
376 - $this->setTransactionResult( $this->getResponseData( $formatted ), 'data' );
 401+ $pulled_data = $this->getResponseData( $formatted );
 402+ $this->setTransactionResult( $pulled_data, 'data' );
377403
378 - $this->processResponse( $formatted );
 404+ // expose a hook for any post processing
 405+ wfRunHooks( 'GatewayPostProcess', array( &$this ) ); //conversion log (at least)
379406
 407+ $this->processResponse( $pulled_data );
 408+ $this->dataObj->unsetEditToken();
 409+
380410 //TODO: Actually pull these from somewhere legit.
381411 if ( $this->getTransactionStatus() === true ) {
382412 $this->setTransactionResult( "$transaction Transaction Successful!", 'message' );
@@ -385,6 +415,9 @@
386416 $this->setTransactionResult( "$transaction Transaction... weird. I have no idea what happened there.", 'message' );
387417 }
388418
 419+ // log that the transaction is essentially complete
 420+ self::log( $this->getData( 'order_id' ) . " Transaction complete." );
 421+
389422 return $this->getTransactionAllResults();
390423
391424 //speaking of universal form:
@@ -821,7 +854,7 @@
822855 * @return string|false
823856 */
824857 public function getTransactionType() {
825 -
 858+
826859 return $this->transaction_type;
827860 }
828861
@@ -831,12 +864,12 @@
832865 * @param string|false $transaction_type
833866 */
834867 public function setTransactionType( $transaction_type ) {
835 -
 868+
836869 $transaction_type = empty( $transaction_type ) ? false : $transaction_type;
837 -
 870+
838871 $this->transaction_type = $transaction_type;
839872 }
840 -
 873+
841874 public function getTransactionAllResults() {
842875 if ( !empty( $this->transaction_results ) && is_array( $this->transaction_results ) ) {
843876 return $this->transaction_results;
@@ -932,5 +965,33 @@
933966
934967 public function unsetActionHash() {
935968 $this->dataObj->expunge( 'action' );
936 - }
 969+ }
 970+
 971+ function runPreProcess() {
 972+
 973+ // allow any external validators to have their way with the data
 974+ self::log( $this->getData( 'order_id' ) . " Preparing to query MaxMind" );
 975+ wfRunHooks( 'GatewayValidate', array( &$this ) );
 976+ self::log( $this->getData( 'order_id' ) . ' Finished querying Maxmind' );
 977+
 978+ // if the transaction was flagged for review
 979+ if ( $this->action == 'review' ) {
 980+ // expose a hook for external handling of trxns flagged for review
 981+ wfRunHooks( 'GatewayReview', array( &$this ) );
 982+ }
 983+
 984+ // if the transaction was flagged to be 'challenged'
 985+ if ( $this->action == 'challenge' ) {
 986+ // expose a hook for external handling of trxns flagged for challenge (eg captcha)
 987+ wfRunHooks( 'GatewayChallenge', array( &$this ) );
 988+ }
 989+
 990+ // if the transaction was flagged for rejection
 991+ if ( $this->action == 'reject' ) {
 992+ // expose a hook for external handling of trxns flagged for rejection
 993+ wfRunHooks( 'GatewayReject', array( &$this ) );
 994+ $this->dataObj->unsetEditToken();
 995+ }
 996+ }
 997+
937998 }
Index: branches/fundraising/extensions/DonationInterface/gateway_common/GatewayForm.php
@@ -137,19 +137,19 @@
138138 *
139139 * @see GatewayForm::fnValidateForm()
140140 */
141 - public function validateForm( &$data, &$error, $options = array() ) {
 141+ public function validateForm( &$data, &$error, $options = array( ) ) {
142142
143143 extract( $options );
144 -
 144+
145145 // Set which items will be validated
146 - $address = isset( $address ) ? (boolean) $address : true ;
147 - $amount = isset( $amount ) ? (boolean) $amount : true ;
148 - $creditCard = isset( $creditCard ) ? (boolean) $creditCard : false ;
149 - $email = isset( $email ) ? (boolean) $email : true ;
150 - $name = isset( $name ) ? (boolean) $name : true ;
 146+ $address = isset( $address ) ? ( boolean ) $address : true;
 147+ $amount = isset( $amount ) ? ( boolean ) $amount : true;
 148+ $creditCard = isset( $creditCard ) ? ( boolean ) $creditCard : false;
 149+ $email = isset( $email ) ? ( boolean ) $email : true;
 150+ $name = isset( $name ) ? ( boolean ) $name : true;
151151
152152 // These are set in the order they will most likely appear on the form.
153 -
 153+
154154 if ( $name ) {
155155 $this->validateName( $data, $error );
156156 }
@@ -163,7 +163,7 @@
164164 }
165165
166166 if ( $email ) {
167 - $this->validateEmail( $data, $error );
 167+ $this->validateEmail( $data, $error );
168168 }
169169
170170 if ( $creditCard ) {
@@ -175,9 +175,9 @@
176176 *
177177 * This is done for backward compatibility.
178178 */
179 - return $this->getValidateFormResult() ? 0 : 1 ;
 179+ return $this->getValidateFormResult() ? 0 : 1;
180180 }
181 -
 181+
182182 /**
183183 * Validates the address
184184 *
@@ -187,32 +187,32 @@
188188 * @see GatewayForm::validateForm()
189189 */
190190 public function validateAddress( &$data, &$error ) {
191 -
 191+
192192 if ( empty( $data['street'] ) ) {
193 -
 193+
194194 $error['street'] = wfMsg( $this->adapter->getIdentifier() . '_gateway-error-msg-street' );
195 -
 195+
196196 $this->setValidateFormResult( false );
197197 }
198 -
 198+
199199 if ( empty( $data['city'] ) ) {
200 -
 200+
201201 $error['city'] = wfMsg( $this->adapter->getIdentifier() . '_gateway-error-msg-city' );
202 -
 202+
203203 $this->setValidateFormResult( false );
204204 }
205 -
 205+
206206 if ( empty( $data['state'] ) ) {
207 -
 207+
208208 $error['state'] = wfMsg( $this->adapter->getIdentifier() . '_gateway-error-msg-state' );
209 -
 209+
210210 $this->setValidateFormResult( false );
211211 }
212 -
 212+
213213 if ( empty( $data['zip'] ) ) {
214 -
 214+
215215 $error['zip'] = wfMsg( $this->adapter->getIdentifier() . '_gateway-error-msg-zip' );
216 -
 216+
217217 $this->setValidateFormResult( false );
218218 }
219219 }
@@ -226,14 +226,14 @@
227227 * @see GatewayForm::validateForm()
228228 */
229229 public function validateAmount( &$data, &$error ) {
230 -
 230+
231231 if ( empty( $data['amount'] ) ) {
232 -
 232+
233233 $error['amount'] = wfMsg( $this->adapter->getIdentifier() . '_gateway-error-msg-amount' );
234 -
 234+
235235 $this->setValidateFormResult( false );
236236 }
237 -
 237+
238238 // check amount
239239 $priceFloor = $this->adapter->getGlobal( 'PriceFloor' );
240240 $priceCeiling = $this->adapter->getGlobal( 'PriceCeiling' );
@@ -256,49 +256,40 @@
257257 * @see GatewayForm::validateForm()
258258 */
259259 public function validateCreditCard( &$data, &$error ) {
260 -
 260+
261261 if ( empty( $data['card_num'] ) ) {
262262
263263 $error['card_num'] = wfMsg( $this->adapter->getIdentifier() . '_gateway-error-msg-card_num' );
264264
265265 $this->setValidateFormResult( false );
266266 }
267 -
 267+
268268 if ( empty( $data['cvv'] ) ) {
269269
270270 $error['cvv'] = wfMsg( $this->adapter->getIdentifier() . '_gateway-error-msg-cvv' );
271271
272272 $this->setValidateFormResult( false );
273273 }
274 -
 274+
275275 if ( empty( $data['expiration'] ) ) {
276276
277277 $error['expiration'] = wfMsg( $this->adapter->getIdentifier() . '_gateway-error-msg-expiration' );
278278
279279 $this->setValidateFormResult( false );
280280 }
281 -
 281+
282282 // validate that credit card number entered is correct and set the card type
283283 if ( preg_match( '/^3[47][0-9]{13}$/', $data['card_num'] ) ) { // american express
284 -
285284 $data['card'] = 'american';
286 -
287285 } elseif ( preg_match( '/^5[1-5][0-9]{14}$/', $data['card_num'] ) ) { // mastercard
288 -
289286 $data['card'] = 'mastercard';
290 -
291287 } elseif ( preg_match( '/^4[0-9]{12}(?:[0-9]{3})?$/', $data['card_num'] ) ) {// visa
292 -
293288 $data['card'] = 'visa';
294 -
295289 } elseif ( preg_match( '/^6(?:011|5[0-9]{2})[0-9]{12}$/', $data['card_num'] ) ) { // discover
296 -
297290 $data['card'] = 'discover';
298 -
299291 } else { // an invalid credit card number was entered
 292+ $error['card_num'] = wfMsg( $this->adapter->getIdentifier() . '_gateway-error-msg-card-num' );
300293
301 - $error[ 'card_num' ] = wfMsg( $this->adapter->getIdentifier() . '_gateway-error-msg-card-num' );
302 -
303294 $this->setValidateFormResult( false );
304295 }
305296 }
@@ -312,14 +303,14 @@
313304 * @see GatewayForm::validateForm()
314305 */
315306 public function validateEmail( &$data, &$error ) {
316 -
 307+
317308 if ( empty( $data['email'] ) ) {
318309
319310 $error['email'] = wfMsg( $gateway_identifier . '_gateway-error-email-empty' );
320311
321312 $this->setValidateFormResult( false );
322313 }
323 -
 314+
324315 // is email address valid?
325316 $isEmail = User::isValidEmailAddr( $data['email'] );
326317
@@ -340,22 +331,22 @@
341332 * @see GatewayForm::validateForm()
342333 */
343334 public function validateName( &$data, &$error ) {
344 -
 335+
345336 if ( empty( $data['fname'] ) ) {
346 -
 337+
347338 $error['fname'] = wfMsg( $this->adapter->getIdentifier() . '_gateway-error-msg-fname' );
348 -
 339+
349340 $this->setValidateFormResult( false );
350341 }
351 -
 342+
352343 if ( empty( $data['lname'] ) ) {
353 -
 344+
354345 $error['lname'] = wfMsg( $this->adapter->getIdentifier() . '_gateway-error-msg-lname' );
355 -
 346+
356347 $this->setValidateFormResult( false );
357348 }
358349 }
359 -
 350+
360351 /**
361352 * Build and display form to user
362353 *
@@ -452,6 +443,16 @@
453444 } else {
454445 $wgOut->addHTML( "No Session Donor Vars:<ul>" );
455446 }
 447+
 448+ if ( is_array( $this->adapter->debugarray ) ) {
 449+ $wgOut->addHTML( "Debug Array:<ul>" );
 450+ foreach ( $this->adapter->debugarray as $val ) {
 451+ $wgOut->addHTML( "<li>$val" );
 452+ }
 453+ $wgOut->addHTML( "</ul>" );
 454+ } else {
 455+ $wgOut->addHTML( "No Debug Array<ul>" );
 456+ }
456457 }
457458
458459 public function getPossibleErrors() {
@@ -575,8 +576,7 @@
576577 // submit the data to the paypal redirect URL
577578 $wgOut->redirect( $this->adapter->getPaypalRedirectURL() );
578579 }
579 -
580 -
 580+
581581 /**
582582 * Fetch the array of iso country codes => country names
583583 * @return array
@@ -592,8 +592,8 @@
593593 * @return boolean
594594 */
595595 public function getValidateFormResult() {
596 -
597 - return (boolean) $this->validateFormResult;
 596+
 597+ return ( boolean ) $this->validateFormResult;
598598 }
599599
600600 /**
@@ -602,8 +602,8 @@
603603 * @param boolean $validateFormResult
604604 */
605605 public function setValidateFormResult( $validateFormResult ) {
606 -
607 - $this->validateFormResult = empty( $validateFormResult ) ? false : (boolean) $validateFormResult;
 606+
 607+ $this->validateFormResult = empty( $validateFormResult ) ? false : ( boolean ) $validateFormResult;
608608 }
609609
610610 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r98498Rebuilding the payflowpro gateway and adapter, Part 2 of Several!...khorn01:45, 30 September 2011

Comments

#Comment by Jpostlethwaite (talk | contribs)   21:29, 7 October 2011

Many of these changes appear to code clean up.

Status & tagging log