Solved

Credit Card Authorize

Posted on 2002-04-10
10
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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 video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

738 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