Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php |
— | — | @@ -278,7 +278,7 @@ |
279 | 279 | /** |
280 | 280 | * Checks posted form data for errors and returns array of messages |
281 | 281 | */ |
282 | | - private function fnPayflowValidateForm( $data, &$error ) { |
| 282 | + private function fnPayflowValidateForm( &$data, &$error ) { |
283 | 283 | // begin with no errors |
284 | 284 | $error_result = '0'; |
285 | 285 | |
— | — | @@ -324,59 +324,35 @@ |
325 | 325 | $error_result = '1'; |
326 | 326 | } |
327 | 327 | |
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'; |
340 | 333 | break; |
341 | 334 | |
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'; |
352 | 338 | 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'; |
364 | 343 | 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'; |
376 | 348 | break; |
377 | 349 | |
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 | + |
381 | 357 | return $error_result; |
382 | 358 | } |
383 | 359 | |
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.i18n.php |
— | — | @@ -50,10 +50,7 @@ |
51 | 51 | 'payflowpro_gateway-error-msg-js' => 'Please enter your', |
52 | 52 | 'payflowpro_gateway-error-msg-invalid-amount' => '**Please enter a valid amount**', |
53 | 53 | '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**', |
58 | 55 | 'payflowpro_gateway-error-msg-amount' => 'donation amount', |
59 | 56 | 'payflowpro_gateway-error-msg-emailAdd' => 'e-mail address', |
60 | 57 | 'payflowpro_gateway-error-msg-fname' => 'first name', |