Главная страница


ru.cgi.perl

 
 - RU.CGI.PERL ------------------------------------------------------------------
 From : Pavel Reich                          2:5004/75      12 Jun 2001  03:32:44
 To : Max Martynov
 Subject : Re: Web shop
 -------------------------------------------------------------------------------- 
 
 
  Когда-то (Monday June 11 2001 16:11) Max Martynov писал _All_:
 
  MM>     Hаpод, кто нибуть занимался созданием интеpнет магазина с
  MM> online'овой валидацией кpедитных каpточек ? Если есть такие,
  MM> подскажите пожалуйста, где можно поподpобнее почитать пpо создание
  MM> такой штуки (на базе пеpловых скpиптов желательно), есть ли готовый
  MM> софт для этого и как быть с этой самой валидацией кpедиток?
 
 Вот проверка валидности (из CGI/Perl CookBook)
 
 ДWindows ClipboardД
 ############################################################################
 #                                                                          #
 # cc_validate()                     Version 2.0                            #
 # Written by Craig Patchett         craig@patchett.com                     #
 # Created 9/24/96                   Last Modified 3/21/97                  #
 #                                                                          #
 # Copyright 1997 Craig Patchett & Matthew Wright.  All Rights Reserved.    #
 # This subroutine is part of The CGI/Perl Cookbook from John Wiley & Sons. #
 # License to use this program or install it on a server (in original or    #
 # modified form) is granted only to those who have purchased a copy of The #
 # CGI/Perl Cookbook. (This notice must remain as part of the source code.) #
 #                                                                          #
 # Function:      Checks Visa, Mastercard, and American Express credit card #
 #                numbers to make sure they follow bank guidelines for      #
 #                credit card numbers.                                      #
 #                                                                          #
 # Usage:         &cc_validate($card_type, $card_num, $exp_date);           #
 #                                                                          #
 # Variables:     $card_type -- Card type                                   #
 #                              Valid values: 'VS', 'MC', 'AX'              #
 #                $card_num --  Card number. Non-numeric will be revoed     #
 #                              Example: '1234-5678-9012-3456'              #
 #                $exp_date --  Expiration date                             #
 #                              Examples: '05/99', '5/99'                   #
 #                                                                          #
 # Returns:       0 if successful                                           #
 #                1 if invalid card type                                    #
 #                2 if invalid number of digits in card number              #
 #                3 if if card has expired or expiration date is invalid    #
 #                4 if card number is invalid                               #
 #                                                                          #
 # Uses Globals:  Sets $Error_Message with descriptive error message        #
 #                                                                          #
 # Files Created: None                                                      #
 #                                                                          #
 ############################################################################
 sub cc_validate {
 
     local($card_type, $card_num, $exp_date) = @_;
     local(%card_length) = ('VS', '13,15,16', 'MC', '16', 'AX', '15');
     local($old_card_num, $card_length, $total, $d);
 
     # Check to make sure the card type is valid
 
     $card_type =~ tr/a-z/A-Z/;
     if (!$card_length{$card_type}) {
         $Error_Message = "$card_type is not a valid card type.";
         return(1);
     }
 
     # Get rid of non-digits in card number and check for right number
     # of digits
 
     $old_card_num = $card_num;
     $card_num =~ s/\D//g;
     $card_length = length($card_num);
     if (!($card_length{$card_type} =~ /(^|,)$card_length(,|$)/)) {
         $Error_Message = "Card number $old_card_num does not have the correct
 number of digits.";
         return(2);
     }
 
     # Check to see if the card has expired
 
     local($month_now, $year_now) = (localtime)[4,5];
     ++$month_now;
     if ($year_now < 50) { $year_now += 100 }
     $exp_date =~ m|(\d+)/(\d+)|;
     $exp_month = $1;
     $exp_year = ($2 < 50) ? $2 + 100 : $2;
     if ((($year_now == $exp_year) && ($month_now > $exp_month))
       || ($exp_year - $year_now < 0) || ($exp_year - $year_now > 10)) {
 
         $Error_Message = "$exp_date is an invalid expiration date.";
         return(3);
     }
 
     # Check to see if card number is valid (checks only to see if the card
     # number sequence is a valid sequence.
 
     while (length($card_num)) {
         $total += chop($card_num);
         $total += (($d = chop($card_num)) < 9) ? ($d * 2) % 9 : 9;
     }
     if ($total % 10) {
         $Error_Message = "$old_card_num is not a valid credit card number.";
         return(4);
     }
 
     # It passed all the tests!
 
     return(0);
 ДWindows ClipboardД
 
          Pavel
 --- GoldED+/386 under The Doors at 25Reich_homeplace
  * Origin: Хорошо живется поинтам... (2:5004/75)
 
 

Вернуться к списку тем, сортированных по: возрастание даты  уменьшение даты  тема  автор 

 Тема:    Автор:    Дата:  
 Web shop   Max Martynov   11 Jun 2001 16:11:02 
 Web shop   Dima Manuilo   11 Jun 2001 22:18:51 
 Re: Web shop   Sergey Tkachuk   12 Jun 2001 12:02:00 
 Web shop   Serg Kondratuk   12 Jun 2001 14:42:43 
 Re: Web shop   Pavel Reich   12 Jun 2001 03:32:44 
Архивное /ru.cgi.perl/121563b258dcd.html, оценка 2 из 5, голосов 10
Яндекс.Метрика
Valid HTML 4.01 Transitional