1CreditCard(3) User Contributed Perl Documentation CreditCard(3)
2
3
4
6 "Business::CreditCard" - Validate/generate credit card checksums/names
7
9 use Business::CreditCard;
10
11 print validate("5276 4400 6542 1319");
12 print cardtype("5276 4400 6542 1319");
13 print generate_last_digit("5276 4400 6542 131");
14
15 Business::CreditCard is available at a CPAN site near you.
16
18 These subroutines tell you whether a credit card number is self-
19 consistent -- whether the last digit of the number is a valid checksum
20 for the preceding digits.
21
22 The validate() subroutine returns 1 if the card number provided passes
23 the checksum test, and 0 otherwise.
24
25 The cardtype() subroutine returns a string containing the type of card.
26 The list of possible return values is more comprehensive than it used
27 to be, but additions are still most welcome.
28
29 Possible return values are:
30
31 VISA card
32 MasterCard
33 Discover card
34 American Express card
35 enRoute
36 JCB
37 BankCard
38 Switch
39 Solo
40 China Union Pay
41 Laser
42 Isracard
43 Unknown
44
45 "Not a credit card" is returned on obviously invalid data values.
46
47 Versions before 0.31 may also have returned "Diner's Club/Carte
48 Blanche" (these cards are now recognized as "Discover card").
49
50 As of 0.30, cardtype() will accept a partial card masked with "x", "X',
51 ".", "*" or "_". Only the first 2-6 digits and the length are
52 significant; whitespace and dashes are removed. With two digits, Visa,
53 MasterCard, Discover and Amex are recognized (versions before 0.36
54 needed four digits to recognize all Discover cards). With four digits,
55 almost all cards except some Switch cards are recognized. With six
56 digits (the full "BIN" or "IIN"), all cards are recognized. Six digits
57 are also required for receipt_cardtype().
58
59 The generate_last_digit() subroutine computes and returns the last
60 digit of the card given the preceding digits. With a 16-digit card,
61 you provide the first 15 digits; the subroutine returns the sixteenth.
62
63 This module does not tell you whether the number is on an actual card,
64 only whether it might conceivably be on a real card. To verify whether
65 a card is real, or whether it's been stolen, or to actually process
66 charges, you need a Merchant account. See Business::OnlinePayment.
67
68 These subroutines will also work if you provide the arguments as
69 numbers instead of strings, e.g. "validate(5276440065421319)".
70
72 Credit card issuers have recently been forming agreements to process
73 cards on other networks, in which one type of card is processed as
74 another card type.
75
76 By default, Business::CreditCard returns the type the card should be
77 treated as in the US. You can change this to return the type the card
78 should be treated as in a different country by setting
79 $Business::CreditCard::Country to your two-letter country code. This
80 is probably what you want to determine if you accept the card, or which
81 merchant agreement it is processed through.
82
83 You can also set $Business::CreditCard::Country to a false value such
84 as the empty string to return the "base" card type. This is probably
85 only useful for informational purposes when used along with the default
86 type.
87
88 Here are the currently known agreements:
89
90 Most Diner's club is now identified as Discover. (This supercedes the
91 earlier identification of some Diner's club cards as MasterCard inside
92 the US and Canada.)
93 JCB cards in the 3528-3589 range are identified as Discover inside the
94 US and territories.
95 China Union Pay cards are identified as Discover cards in the US,
96 Mexico and most Caribbean countries.
97
99 Discover requires some cards processed on its network to display
100 "PayPal" on receipts instead of "Discover". The receipt_cardtype()
101 subroutine will return "PayPal card" for these cards only, and
102 otherwise the same output as cardtype().
103
104 Use this for receipt display/printing only.
105
106 Note: this subroutine is not exported by default like the others.
107 Before 0.36, you needed to call this subroutine fully-qualified, as
108 Business::CreditCard::receipt_cardtype()
109
110 In 0.36 and later, you can import it into your namespace:
111
112 use Business::CreditCard qw( :DEFAULT receipt_cardtype );
113
115 Jon Orwant
116
117 The Perl Journal and MIT Media Lab
118
120 Current maintainer is Ivan Kohler <ivan-business-creditcard@420.am>.
121
122 Lee Lawrence <LeeL@aspin.co.uk>, Neale Banks <neale@lowendale.com.au>
123 and Max Becker <Max.Becker@firstgate.com> contributed support for
124 additional card types. Lee also contributed a working test.pl.
125 Alexandr Ciornii <alexchorny@gmail.com> contributed code cleanups.
126 Jason Terry <jterry@bluehost.com> contributed updates for Discover BIN
127 ranges.
128
130 Copyright (C) 1995,1996,1997 Jon Orwant Copyright (C) 2001-2006 Ivan
131 Kohler Copyright (C) 2007-2016 Freeside Internet Services, Inc.
132
133 This library is free software; you can redistribute it and/or modify it
134 under the same terms as Perl itself, either Perl version 5.8.8 or, at
135 your option, any later version of Perl 5 you may have available.
136
138 (paraphrasing Neil Bowers) We export all functions by default. It
139 would be better to let the user decide which functions to import. And
140 validate() is a bit of a generic name.
141
142 The question is, after almost 2 decades with this interface (inherited
143 from the original author, who probably never expected it to live half
144 this long), how to change things to behave in a more modern fashion
145 without breaking existing code? "use Business::CreditCard
146 <some_minimum_version>" turns it off? Explicitly ask to turn it off
147 and list that in the SYNOPSIS?
148
149 validate() and @EXPORT transition plan
150 First (done in 0.36):
151
152 validate_card() is the new name for validate(). Both work for now.
153
154 New-style usage (not recommended for code that needs to support B:CC
155 before 0.36):
156
157 use Business::CreditCard qw( :NEW );
158
159 You get validate_card(), cardtype() and receipt_cardtype(). You can
160 also ask for them explicitly / individually:
161
162 use Business::CreditCard qw( validate_card cardtype receipt_cardtype );
163
164 Second (we're at now now):
165
166 Waiting for 0.36+ to become more prevalent.
167
168 Third:
169
170 Recommend new-style usage. Maybe asking for a specific minimum version
171 turns it on too?
172
173 Fourth:
174 (this is the incompatible part):
175
176 Don't export validate() (or anything else [separately?]) by default.
177
178 This is the part that will break things and we probably won't do for a
179 long time, until new-style usage is the norm and the tradeoff of
180 breaking old code is worth it to stop or namespace pollution. Maybe do
181 a 1.00 releaes with the current API and 2.00 is when this happens (with
182 a 1.99_01 pre-release)?
183
185 Business::CreditCard::Object is a wrapper around Business::CreditCard
186 providing an OO interface. Assistance integrating this into the base
187 Business::CreditCard distribution is welcome.
188
189 Business::OnlinePayment is a framework for processing online payments
190 including modules for various payment gateways.
191
192 http://neilb.org/reviews/luhn.html is an excellent overview of similar
193 modules providing credit card number verification (LUHN checking).
194
195
196
197perl v5.32.0 2020-07-28 CreditCard(3)