Solved

Credit Card Authorize

Posted on 2002-04-10
10
280 Views
Last Modified: 2013-11-18
hi all

I want to make a program that can check if a credit card is valid or not through the internet....

The program will do the following:

1 - The user will enter the credit card information.
2 - the program sends information via internet to some company.
3 - the program waits for the answer.
4 - the program tells the user if the CC is valid or expired or ....

Thanx U

DM
0
Comment
Question by:D-Master
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6932995
What's your question?
0
 
LVL 7

Expert Comment

by:God_Ares
ID: 6933679
well you can check if the enter number is a correct creditcard number but i don't know how to validate if the card is in use or not.

look at

http://www.rispens.net/pagina/creditcard.php?Afdeling=1&cctest=9

sorry it's in dutch..

quich translation:

Nummer is niet juist = number is incorrect
CreditCard-nummer (cijfers achter elkaar):
= enter your creditcard number here (freely translated)

CreditCard-uitgever  = creditcard company



btw search on : Creditcard validation  lots of info out there.



0
 
LVL 3

Expert Comment

by:VSF
ID: 6933847
unit Creditc;

{*****************************************************************************
Credit Card Number Validator Unit for Delphi
Version: 1.1

Date: December 20, 1996
This unit is based on the public domain program ccard by Peter Miller.
It is released to the public for free of charge use, but the author
reserves all rights.
copyright 1996 by Shawn Wilson Harvell ( shawn@inet.net )

usage:

Add this unit to the uses clause of any unit that needs access to the

validation function.

IsValidCreditCardNumber( CardNumber, ReturnMessage ) returns Boolean

   for example, use it in an if statement that Messages user if invalid.

CardNumber is a string containing the number that you want to validate
ReturnMessage is a string where the function can place any messages it
may return ( meaning that it will overwrite whatever is in it )
returns true if valid, false otherwise.
dashes and space in the input value are taken care of by the function,
if other characters are possible, you may wish to remove them as well.
The function RemoveChar will take care of this quite easily, simply
pass the input string and the char you wish to delete.
Users are free to modify this unit for their own use, but in
distributing you should advise all users of the changes made.
Use this unit at your own risk, it does not come with any warranties
either express or implied.  Damages resulting from the use of this
unit are the sole responsibility of the user.
This should work as is for Delphi versions 1 and 2, some slight
modifications may be necessary for Turbo Pascal ( mainly due to use to
conversion functions from the SysUtils unit ).
If you do find this useful, have any comments or suggestions, please
drop the author an email at shawn@inet.net
Revision History

Version 1.1 -- December 20, 1996

blooper with Discover cards, added their length mask to the "database"

version 1.0 -- October 26, 1996

initial release


*****************************************************************************}

interface

uses SysUtils;

function IsValidCreditCardNumber( CardNumber: String; var MessageText: String ): Boolean;

implementation

const
   CardPrefixes: array[ 1..19 ] of string  = ( '2014', '2149', '300', '301', '302',
                  '303', '304', '305', '34', '36', '37',
                  '38', '4', '51', '52', '53', '54', '55', '6011' );
   CardTypes: array[ 1..19 ] of String =
              ( 'enRoute',
                'enRoute',
                'Diner Club/Carte Blanche',
                'Diner Club/Carte Blanche',
                'Diner Club/Carte Blanche',
                'Diner Club/Carte Blanche',
                'Diner Club/Carte Blanche',
                'Diner Club/Carte Blanche',
                'American Express',
                'Diner Club/Carte Blanche',
                'American Express',
                'Diner Club/Carte Blanche',
                'Visa',
                'MasterCard',
                'MasterCard',
                'MasterCard',
                'MasterCard',
                'MasterCard',
                'Discover' );


function RemoveChar(const Input: String; DeletedChar: Char): String;
var
  Index: Word;                    { counter variable                              }
begin
  { all this function does is iterate through string looking for char, if found   }
  { it deletes it                                                                 }
  Result := Input;
for Index := Length( Result ) downto 1 do
    if Result[ Index ] = DeletedChar then Delete( Result, Index, 1 );
end;


function ShiftMask( Input: Integer ): Integer;
begin
   { simply a wrapper for this left bit shift operation                           }
   result := ( 1 shl ( Input - 12 ) );
end;


function ConfirmChecksum( CardNumber: String ): Boolean;
var
   CheckSum: Integer;             { Holds the value of the operation              }
   Flag: Boolean;                 { used to indicate when ready                   }
   Counter: Integer;              { index counter                                 }
   PartNumber: String;            { used to extract each digit of number          }
   Number: Integer;               { used to convert each digit to integer         }
begin
   {**************************************************************************
   This is probably the most confusing part of the code you will see, I know
   that it is some of the most confusing I have ever seen.  Basically, this
   function is extracting each digit of the number and subjecting it to the
   checksum formula established by the credit card companies.  It works from
   the end to the front.
   **************************************************************************}
   { get the starting value for our counter }
   Counter := Length( CardNumber  );
   CheckSum := 0;
   PartNumber := '';
   Number := 0;
   Flag := false;
   while ( Counter >= 1 ) do
   begin
      { get the current digit }
      PartNumber :=  Copy( CardNumber, Counter, 1 );
      Number := StrToInt( PartNumber ); { convert to integer }
      if ( Flag ) then { only do every other digit }
      begin
         Number := Number * 2;
         if ( Number >= 10 ) then Number := Number - 9;
      end;
      CheckSum := CheckSum + Number;
      Flag := not( Flag );
      Counter := Counter - 1;
   end;
   result := ( ( CheckSum mod 10 ) = 0 );
end;


function GetMask( CardName: String  ): Integer;
begin
   { the default case }
   result := 0;
   if ( CardName = 'MasterCard' ) then result := ShiftMask( 16 );
   if ( CardName = 'Visa' ) then result := ( ShiftMask( 13 ) or ShiftMask( 16 ) );
   if ( CardName = 'American Express' ) then result := ShiftMask( 15 );
   if ( CardName = 'Diner Club/Carte Blanche' ) then result := ShiftMask( 14 );
   if ( CardName = 'Discover' ) then result := ShiftMask( 16 );
end;


function IsValidCreditCardNumber( CardNumber: String; var MessageText: String ): Boolean;
var
   StrippedNumber: String;        { used to hold the number bereft of extra chars }
   Index: Integer;                { general purpose counter for loops, etc        }
   TheMask: Integer;              { number we will use for the mask               }
   FoundIt: Boolean;              { used to indicate when something is found      }
   CardName: String;              { stores the name of the type of card           }
   PerformChecksum: Boolean;      { the enRoute type of card doesn't get it       }
begin
   { first, get rid of spaces, dashes }
   StrippedNumber := RemoveChar( CardNumber, ' ' );
   StrippedNumber := RemoveChar( StrippedNumber, '-' );
   { if the string was zero length, then OK too }
   if ( StrippedNumber = '' ) then
   begin
      result := true;
      exit;
   end;
   { initialize return variables }
   MessageText := '';
   result := true;
   { set our flag variable }
   FoundIt := false;
   { check for invalid characters right off the bat }
   for Index := 1 to Length( StrippedNumber ) do
   begin
      case StrippedNumber[ Index ] of
         '0'..'9': FoundIt := FoundIt;   { non op in other words }
      else
         MessageText := 'Detectada entrada de caracteres invalidos!';
         result := false;
         exit;
      end;
   end;
   { now let's determine what type of card it is }
   for Index := 1 to 19 do
   begin
      if ( Pos( CardPrefixes[ Index ], StrippedNumber ) = 1 ) then
      begin
         { we've found the right one }
         FoundIt := true;
         CardName := CardTypes[ Index ];
         TheMask := GetMask( CardName );
      end;
   end;
   { if we didn't find it, indicates things are already ary }
   if ( not FoundIt ) then
   begin
      CardName := 'Tipo de cartco desconhecido!';
      TheMask := 0;
      MessageText := 'Tipo de cartco desconhecido!';
      result := false;
      exit;
   end;
   { check the length }
   if ( ( Length( StrippedNumber ) > 28 ) and result ) then
   begin
      MessageText := 'Numero muito grande!';
      result := false;
      exit;
   end;
   { check the length }
   if ( ( Length( StrippedNumber ) < 12 ) or
    ( ( shiftmask( length( strippednumber ) ) and themask ) = 0 ) ) then
   begin
      messagetext := 'Leitura de numero incorreta';
      result := false;
      exit;
   end;
   { check the checksum computation }
   if ( cardname = 'enroute' ) then
      performchecksum := false
   else
      performchecksum := true;
   if ( performchecksum and ( not confirmchecksum( strippednumber ) ) ) then
   begin
      messagetext := 'Erro de Checagem';
      result := false;
      exit;
   end;
   { if result is still true, then everything is ok }
   if ( result ) then
      messagetext := 'Nzmero Aprovado! tipo de cartco: ' + cardname;
   { if the string was zero length, then ok too }
   if ( strippednumber = '' ) then
      result := true;
end;

end.

Hope it helps!
VSF
www.victory.hpg.com.br
www.boatoda.hpg.com.br
0
 
LVL 3

Expert Comment

by:VSF
ID: 6933857
God_Ares:
You must be kidding me.... I would not dare to put my credit card number and type on that!
God knows what will they use it for later!

VSF
0
 
LVL 7

Expert Comment

by:God_Ares
ID: 6934036
VSF

Who knows :)
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Author Comment

by:D-Master
ID: 6937888
hi all
I don't need a unit for credit card validation
I want to know if the credit card is really working , not expired and not stolen via internet...

Thats what I need
Thanx
0
 
LVL 7

Expert Comment

by:God_Ares
ID: 6940448
you should contact a creditcard department and ask if the provide such a service.
0
 
LVL 7

Expert Comment

by:God_Ares
ID: 6950321
i think you should give VSF points for his answer.
0
 
LVL 3

Author Comment

by:D-Master
ID: 6952593
hi all
I don't need a unit for credit card validation
I want to know if the credit card is really working , not expired and not stolen via internet...

Thats what I need
Thanx
0
 
LVL 6

Accepted Solution

by:
Stuart_Johnson earned 50 total points
ID: 6952600
As God_Ares said, "you should contact a creditcard department and ask if the provide such a service."

This sort of service MAYBE offered by some banks or financial institutions, but I wouldn't imagine it would be a free service.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Often people are aiming at development of perfect Magento websites. Though, it is easier said than done. You know what’s much easier? To ruin everything. It can be done in seconds. Many of us experimented with design, tried to change some values dir…
Are you using email marketing software? If not, you're missing out on effortless marketing and the reaching of desired conversion rates through email marketing software.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now