Ovid has asked for the wisdom of the Perl Monks concerning the following question:
Does anyone have any suggestions for a robust method of parsing credit card track data? Background: I need to be able to print credit card numbers on receipts, with all but the last four number turned to asterisks. If the credit card is swiped through the reader, as opposed to the number being keyed in by hand, then I get the magnetic "track data" (which you can read about here). Unfortunately, I can't seem to find clear specs on this. Further, American Express seems to have a slightly different format than other credit cards.
Based upon a combination of the above article and an actual examination of various credit cards in the office, I have the following snippet of code:
# works with both a keyed number and a track data my $card_num = $tender->ccnumber; $card_num =~ s/^.? # Start sentinel [bB]? # Format code="B" ( # Capture to $1 [^^]+ # Primary account number ) # End of card .* # Slurp up the rest /$1/x; $card_num =~ s/^(.+)(.{4})$/('*'x(length $1)).$2/e;
Unfortunately, this is just an ad hoc solution and I would love to find something more robust. I couldn't find any CPAN modules and the oracle let me down.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parsing credit card track data
by Arien (Pilgrim) on Aug 22, 2002 at 23:37 UTC | |
Re: Parsing credit card track data
by mattr (Curate) on Aug 26, 2002 at 10:49 UTC |