r58378 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58377‎ | r58378 | r58379 >
Date:21:50, 30 October 2009
Author:diana
Status:ok
Tags:
Comment:
more code review changes and vaious improvements
Modified paths:
  • /trunk/extensions/DonationInterface/activemq_stomp/activemq_stomp.php (modified) (history)
  • /trunk/extensions/DonationInterface/donate_interface/donate_interface.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
@@ -120,8 +120,7 @@
121121 //Display form for the first time
122122 $this->fnPayflowDisplayForm($data, $error);
123123 }
124 - } // end $success
125 -
 124+ }
126125 }
127126
128127 /*
@@ -169,17 +168,17 @@
170169 XML::hidden('amount', $data['amount']);
171170
172171 $donorInput = array(
173 - XML::inputLabel(wfMsg( 'payflowpro_gateway-donor-email' ), "emailAdd", "emailAdd", "30", $data['email'], array('maxlength' => "150")) . '<span class="creditcard_error_msg">'. " " . $error['emailAdd'].'</span>',
174 - XML::inputLabel(wfMsg( 'payflowpro_gateway-donor-fname' ), "fname", "fname", "20", $data['fname'], array('maxlength' => "35", 'class' => 'required')) . '<span class="creditcard_error_msg">'. " " . $error['fname'].'</span>',
175 - XML::inputLabel(wfMsg( 'payflowpro_gateway-donor-mname' ), "mname", "mname", "20", $data['mname'], array('maxlength' => "35")),
176 - XML::inputLabel(wfMsg( 'payflowpro_gateway-donor-lname' ), "lname", "lname", "20", $data['lname'], array('maxlength' => "35")) . '<span class="creditcard_error_msg">'. " " . $error['lname'].'</span>',
177 - XML::inputLabel(wfMsg( 'payflowpro_gateway-donor-street' ), "street", "street", "30", $data['street'], array('maxlength' => "100")) . '<span class="creditcard_error_msg">'. " " . $error['street'].'</span>',
178 - XML::inputLabel(wfMsg( 'payflowpro_gateway-donor-city' ), "city", "city", "20", $data['city'], array('maxlength' => "35")) . '<span class="creditcard_error_msg">'. " " . $error['city'].'</span>',
 172+ XML::inputLabel(wfMsg( 'payflowpro_gateway-donor-email' ), "emailAdd", "emailAdd", "30", $data['email'], array('maxlength' => "64")) . '<span class="creditcard_error_msg">'. " " . $error['emailAdd'].'</span>',
 173+ XML::inputLabel(wfMsg( 'payflowpro_gateway-donor-fname' ), "fname", "fname", "20", $data['fname'], array('maxlength' => "15", 'class' => 'required')) . '<span class="creditcard_error_msg">'. " " . $error['fname'].'</span>',
 174+ XML::inputLabel(wfMsg( 'payflowpro_gateway-donor-mname' ), "mname", "mname", "20", $data['mname'], array('maxlength' => "15")),
 175+ XML::inputLabel(wfMsg( 'payflowpro_gateway-donor-lname' ), "lname", "lname", "20", $data['lname'], array('maxlength' => "15")) . '<span class="creditcard_error_msg">'. " " . $error['lname'].'</span>',
 176+ XML::inputLabel(wfMsg( 'payflowpro_gateway-donor-street' ), "street", "street", "30", $data['street'], array('maxlength' => "30")) . '<span class="creditcard_error_msg">'. " " . $error['street'].'</span>',
 177+ XML::inputLabel(wfMsg( 'payflowpro_gateway-donor-city' ), "city", "city", "20", $data['city'], array('maxlength' => "20")) . '<span class="creditcard_error_msg">'. " " . $error['city'].'</span>',
179178 XML::label(wfMsg( 'payflowpro_gateway-donor-state' ), "state") .
180179 XML::openElement('select', array('name' => "state", 'id' => "state", 'value' => $data['state'])) .
181180 statesMenuXML() .
182181 XML::closeElement('select') . '<span class="creditcard_error_msg">'. " " . $error['state'].'</span>',
183 - XML::inputLabel(wfMsg( 'payflowpro_gateway-donor-postal' ), "zip", "zip", "15", $data['zip'], array('maxlength' => "18")) . '<span class="creditcard_error_msg">'. " " . $error['zip'].'</span>',
 182+ XML::inputLabel(wfMsg( 'payflowpro_gateway-donor-postal' ), "zip", "zip", "15", $data['zip'], array('maxlength' => "9")) . '<span class="creditcard_error_msg">'. " " . $error['zip'].'</span>',
184183 XML::label(wfMsg( 'payflowpro_gateway-donor-country' ), "country") .
185184 XML::openElement('select', array('name' => "country", 'id' => "country", 'value' => $data['country'])) .
186185 $countryMenu .
@@ -213,7 +212,6 @@
214213 $expMos = '';
215214
216215 for($i=1; $i<13; $i++) {
217 - //$expMos .= XML::option(str_pad($i, 2, '0', STR_PAD_LEFT), str_pad($i, 2, '0', STR_PAD_LEFT));
218216 $expMos .= XML::option($wgLang->getMonthName( $i ), str_pad($i, 2, '0', STR_PAD_LEFT));
219217
220218 }
@@ -303,8 +301,7 @@
304302 }
305303 }
306304
307 - //is email address valid?
308 - //$isEmail = eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $data['email']);
 305+ //is email address valid
309306 $isEmail = User::isValidEmailAddr($data['email']);
310307
311308 //create error message (supercedes empty field message)
@@ -318,7 +315,7 @@
319316 {
320317 case 'american' :
321318 //pattern for Amex
322 - $pattern = "/^([34|37]{2})([0-9]{13})$/";
 319+ $pattern = "/^3[47][0-9]{13}$/";
323320
324321 //if the pattern doesn't match
325322 if (!preg_match($pattern,$data['card_num'])) {
@@ -330,7 +327,7 @@
331328
332329 case 'mastercard' :
333330 //pattern for Mastercard
334 - $pattern = "/^([51|52|53|54|55]{2})([0-9]{14})$/";
 331+ $pattern = "/^5[1-5][0-9]{14}$/";
335332
336333 //if pattern doesn't match
337334 if (!preg_match($pattern,$data['card_num'])) {
@@ -342,7 +339,7 @@
343340
344341 case 'visa' :
345342 //pattern for Visa
346 - $pattern = "/^([4]{1})([0-9]{12,15})$/";
 343+ $pattern = "/^4[0-9]{12}(?:[0-9]{3})?$/";
347344
348345 //if pattern doesn't match
349346 if (!preg_match($pattern,$data['card_num'])) {
@@ -368,15 +365,45 @@
369366 private function fnPayflowProcessTransaction($data, $payflow_data) {
370367 global $wgOut;
371368
372 - /* Create name-value pair query string */
 369+ //create payflow query string, include string lengths
 370+ $queryArray = array(
 371+ 'TRXTYPE' => $payflow_data[trxtype],
 372+ 'TENDER' => $payflow_data[tender],
 373+ 'USER' => $payflow_data[user],
 374+ 'VENDOR' => $payflow_data[vendor],
 375+ 'PARTNER' => $payflow_data[partner],
 376+ 'PWD' => $payflow_data[password],
 377+ 'ACCT' => $data[card_num],
 378+ 'EXPDATE' => $data[expiration],
 379+ 'AMT' => $data[amount],
 380+ 'FIRSTNAME' => $data[fname],
 381+ 'LASTNAME' => $data[lname],
 382+ 'STREET' => $data[street],
 383+ 'ZIP' => $data[zip],
 384+ 'INVNUM' => $payflow_data[order_id],
 385+ 'CVV2' => $data[cvv],
 386+ 'CURRENCY' => $data[currency],
 387+ 'VERBOSITY' => $payflow_data[verbosity],
 388+ 'CUSTIP' => $payflow_data[user_ip],
 389+ );
 390+
 391+ foreach ($queryArray as $name => $value) {
 392+ $query[] = $name . '[' . strlen($value) . ']=' . $value;
 393+ }
 394+
 395+ $queryString = implode('&', $query);
 396+
 397+ /* FOR TESTING: This is what the NV pair looks like, with string length included
373398 $payflow_query = "TRXTYPE=$payflow_data[trxtype]&TENDER=$payflow_data[tender]&USER=$payflow_data[user]&VENDOR=$payflow_data[vendor]&PARTNER=$payflow_data[partner]&PWD=$payflow_data[password]&ACCT=$data[card_num]&EXPDATE=$data[expiration]&AMT=$data[amount]&FIRSTNAME=$data[fname]&LASTNAME=$data[lname]&STREET=$data[street]&ZIP=$data[zip]&INVNUM=$payflow_data[order_id]&CVV2=$data[cvv]&CURRENCY=$data[currency]&VERBOSITY=$payflow_data[verbosity]&CUSTIP=$payflow_data[user_ip]";
 399+ */
374400
 401+ $payflow_query = $queryString;
375402
376403 // assign header data necessary for the curl_setopt() function
377 - $user_agent = $_SERVER['HTTP_USER_AGENT'];
378 - $headers[] = "Content-Type: text/xml";
 404+ $user_agent = Http::userAgent();
 405+ $headers[] = "Content-Type: text/namevalue";
379406 $headers[] = "Content-Length : " . strlen ($payflow_query);
380 - $headers[] = "X-VPS-Timeout: 45";
 407+ $headers[] = "X-VPS-Client-Timeout: 45";
381408 $headers[] = "X-VPS-Request-ID:" . $payflow_data['order_id'];
382409
383410 $ch = curl_init();
@@ -401,15 +428,17 @@
402429 $result = curl_exec($ch);
403430 $headers = curl_getinfo($ch);
404431
405 - if ($headers['http_code'] != 200) {
 432+ if ($headers['http_code'] != 200 && $headers['http_code'] != 403) {
406433 sleep(5);
407 - } else if ($headers['http_code'] == 200) {
 434+ } else if ($headers['http_code'] == 200 || $headers['http_code'] == 403) {
408435 break;
409436 }
410437 }
411438
412439 if ($headers['http_code'] != 200) {
413440 $wgOut->addHTML('<h3>No response from credit card processor. Please try again later!</h3><p>');
 441+ $when = time();
 442+ wfDebugLog( 'payflowpro_gateway', 'No response from credit card processor ' . $when );
414443 curl_close($ch);
415444 exit;
416445 }
@@ -475,6 +504,8 @@
476505 // if declined or if user has already made two attempts, decline
477506 } else if (($errorCode == '2') || ($data['numAttempt'] >= '2')) {
478507 $this->fnPayflowDisplayDeclinedResults($responseMsg);
 508+ } else if (($errorCode == '4')) {
 509+ $this->fnPayflowDisplayOtherResults($responseMsg);
479510 }
480511
481512 }// end display results
@@ -607,6 +638,26 @@
608639 $wgOut->addHTML('<h3 class="response_message">' . $declinedDefault . $responseMsg . "</h3>");
609640
610641
 642+ }
 643+
 644+ /*
 645+ * Display response message when there is a system error unrelated to user's entry
 646+ *
 647+ * @params
 648+ * $data array of posted data from form
 649+ * $responseMsg message supplied by getResults function
 650+ *
 651+ */
 652+ function fnPayflowDisplayOtherResults($responseMsg) {
 653+ global $wgOut;
 654+
 655+ //general decline message
 656+ $declinedDefault = wfMsg( 'php-response-declined' );
 657+
 658+ // display response message
 659+ $wgOut->addHTML('<h3 class="response_message">' . $declinedDefault . $responseMsg . "</h3>");
 660+
 661+
611662 }
612663
613664
Index: trunk/extensions/DonationInterface/donate_interface/donate_interface.php
@@ -118,8 +118,11 @@
119119 }
120120
121121 //get available currencies
 122+
122123 foreach($values as $key) {
123 - $currencies = $key['currencies'];
 124+ if (isset($key['currencies'])) {
 125+ $currencies = $key['currencies'];
 126+ } else { $currencies = array( 'USD' => "USD: U.S. Dollar" ); }
124127 }
125128
126129 $currencyMenu = '';
@@ -223,18 +226,18 @@
224227 function fnDonateRedirectToProcessorPage($userInput, $url) {
225228 global $wgOut,$wgPaymentGatewayHost;
226229
227 - $chosenGateway = $userInput['payment_method'];
 230+ $chosenGateway = $userInput['gateway'];
228231
 232+ $redirectionData = wfArrayToCGI( $userInput );
 233+
 234+ //$wgOut->redirect(
 235+ //$wgPaymentGatewayHost . $url[$chosenGateway] . $redirectionData
 236+ //);
 237+
229238 $wgOut->redirect(
230 - $wgPaymentGatewayHost . $url[$chosenGateway] . '&amount=' .
231 - $userInput['amount'] . '&currency_code=' . $userInput['currency'] .
232 - '&gateway=' . $userInput['payment_method'] . '&referrer=' .
233 - $userInput['referrer'] . '&utm_source=' . $userInput['utm_source'] .
234 - '&utm_medium=' . $userInput['utm_medium'] . '&utm_campaign=' .
235 - $userInput['utm_campaign'] .'&language=' . $userInput['language'] .
236 - '&comment=' . $userInput['comment'] . '&comment-option=' .
237 - $userInput['comment-option'] .'&email=' . $userInput['email']
238 - );
 239+ $url[$chosenGateway] . '&' . $redirectionData
 240+ );
 241+
239242 }
240243
241244 /**
@@ -306,9 +309,9 @@
307310
308311 // declare variables used to hold post data
309312 $userInput = array (
310 - 'currency' => 'USD',
 313+ 'currency_code' => 'USD',
311314 'amount' => '0.00',
312 - 'payment_method' => '',
 315+ 'gateway' => '',
313316 'referrer' => '',
314317 'utm_source' => '',
315318 'utm_medium' => '',
@@ -333,9 +336,9 @@
334337
335338 // create array of user input from post data
336339 $userInput = array (
337 - 'currency' => $wgRequest->getText( 'currency_code', 'USD' ),
 340+ 'currency_code' => $wgRequest->getText( 'currency_code', 'USD' ),
338341 'amount' => $amount,
339 - 'payment_method' => $wgRequest->getText( 'payment_method', 'payflow' ),
 342+ 'gateway' => $wgRequest->getText( 'payment_method', 'payflow' ),
340343 'referrer' => $wgRequest->getText( 'referrer', '' ),
341344 'utm_source' => $wgRequest->getText( 'utm_source', '' ),
342345 'utm_medium' => $wgRequest->getText( 'utm_medium', '' ),
Index: trunk/extensions/DonationInterface/activemq_stomp/activemq_stomp.php
@@ -69,7 +69,6 @@
7070 function sendSTOMP($transaction) {
7171 global $wgOut;
7272 global $wgStompServer;
73 - //var_dump($wgStompServer);
7473
7574 // include a library
7675 require_once("Stomp.php");
@@ -85,7 +84,9 @@
8685 // send a message to the queue
8786 $result = $con->send("/queue/test", $message, array('persistent' => 'true'));
8887
89 - // TODO: Add back up logging if no result!
 88+ if (!$result) {
 89+ wfDebugLog('activemq_stomp', 'Send to Q failed for this message: ' . $message);
 90+}
9091
9192 $con->disconnect();
9293

Status & tagging log