r79209 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79208‎ | r79209 | r79210 >
Date:21:53, 29 December 2010
Author:awjrichards
Status:deferred
Tags:
Comment:
Updated credit card validation to determine validity and the credit card type based on the credit card number entered; Removed now erroneous messages pertaining to credit card type error messages and replaced them with one new message for an invalid credit card number
Modified paths:
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php
@@ -278,7 +278,7 @@
279279 /**
280280 * Checks posted form data for errors and returns array of messages
281281 */
282 - private function fnPayflowValidateForm( $data, &$error ) {
 282+ private function fnPayflowValidateForm( &$data, &$error ) {
283283 // begin with no errors
284284 $error_result = '0';
285285
@@ -324,59 +324,35 @@
325325 $error_result = '1';
326326 }
327327
328 - // validate that credit card number entered is correct for the brand
329 - switch( $data['card'] ) {
330 - case 'american':
331 - // pattern for Amex
332 - $pattern = '/^3[47][0-9]{13}$/';
333 -
334 - // if the pattern doesn't match
335 - if ( !preg_match( $pattern, $data['card_num'] ) ) {
336 - $error_result = '1';
337 - $error['card'] = wfMsg( 'payflowpro_gateway-error-msg-amex' );
338 - }
339 -
 328+ // validate that credit card number entered is correct and set the card type
 329+ switch( $data[ 'card_num' ] ) {
 330+ // american express
 331+ case preg_match( '/^3[47][0-9]{13}$/', $data[ 'card_num' ] ):
 332+ $data[ 'card' ] = 'american';
340333 break;
341334
342 - case 'mastercard':
343 - // pattern for Mastercard
344 - $pattern = '/^5[1-5][0-9]{14}$/';
345 -
346 - // if pattern doesn't match
347 - if ( !preg_match( $pattern, $data['card_num'] ) ) {
348 - $error_result = '1';
349 - $error['card'] = wfMsg( 'payflowpro_gateway-error-msg-mc' );
350 - }
351 -
 335+ // mastercard
 336+ case preg_match( '/^5[1-5][0-9]{14}$/', $data[ 'card_num' ] ):
 337+ $data[ 'card' ] = 'mastercard';
352338 break;
353 -
354 - case 'visa':
355 - // pattern for Visa
356 - $pattern = '/^4[0-9]{12}(?:[0-9]{3})?$/';
357 -
358 - // if pattern doesn't match
359 - if ( !preg_match( $pattern, $data['card_num'] ) ) {
360 - $error_result = '1';
361 - $error['card'] = wfMsg( 'payflowpro_gateway-error-msg-visa' );
362 - }
363 -
 339+
 340+ // visa
 341+ case preg_match( '/^4[0-9]{12}(?:[0-9]{3})?$/', $data[ 'card_num' ] ):
 342+ $data[ 'card' ] = 'visa';
364343 break;
365 -
366 - case 'discover':
367 - // pattern for Discover
368 - $pattern = '/^6(?:011|5[0-9]{2})[0-9]{12}$/';
369 -
370 - // if pattern doesn't match
371 - if ( !preg_match( $pattern, $data['card_num'] ) ) {
372 - $error_result = '1';
373 - $error['card'] = wfMsg( 'payflowpro_gateway-error-msg-discover' );
374 - }
375 -
 344+
 345+ // discover
 346+ case preg_match( '/^6(?:011|5[0-9]{2})[0-9]{12}$/', $data[ 'card_num' ] ):
 347+ $data[ 'card' ] = 'discover';
376348 break;
377349
378 -
379 -
380 - } // end switch
 350+ // an invalid credit card number was entered
 351+ default:
 352+ $error_result = '1';
 353+ $error[ 'card_num' ] = wfMsg( 'payflowpro_gateway-error-msg-card-num' );
 354+ break;
 355+ }
 356+
381357 return $error_result;
382358 }
383359
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.i18n.php
@@ -50,10 +50,7 @@
5151 'payflowpro_gateway-error-msg-js' => 'Please enter your',
5252 'payflowpro_gateway-error-msg-invalid-amount' => '**Please enter a valid amount**',
5353 'payflowpro_gateway-error-msg-email' => '**Please enter a valid e-mail address**',
54 - 'payflowpro_gateway-error-msg-amex' => '**Please enter a correct card number for American Express.**',
55 - 'payflowpro_gateway-error-msg-mc' => '**Please enter a correct card number for MasterCard.**',
56 - 'payflowpro_gateway-error-msg-visa' => '**Please enter a correct card number for Visa.**',
57 - 'payflowpro_gateway-error-msg-discover' => '**Please enter a correct card number for Discover.**',
 54+ 'payflowpro_gateway-error-msg-card-num' => '**Please enter a valid credit card number for one of the accepted credit card types**',
5855 'payflowpro_gateway-error-msg-amount' => 'donation amount',
5956 'payflowpro_gateway-error-msg-emailAdd' => 'e-mail address',
6057 'payflowpro_gateway-error-msg-fname' => 'first name',

Status & tagging log