From 64d0446f24411746424c4a9f004ace7238c2d3fe Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sun, 15 Mar 2015 22:39:52 -0400 Subject: Epirts.card.cardType(): Implement --- (limited to 'epirts.js') diff --git a/epirts.js b/epirts.js index ad3044f..c7d4712 100644 --- a/epirts.js +++ b/epirts.js @@ -94,6 +94,19 @@ var Stripe = Epirts = (function() { }; pub.cardType = function(number) { + var p; + var i; + + /* Approximate IIN prefixes */ + p = {}; + for (i = 40; i <= 49; ++i) p[i] = 'Visa'; + for (i = 51; i <= 55; ++i) p[i] = 'MasterCard'; + p[34] = p[37] = 'American Express'; + p[35] = 'JCB'; + p[60] = p[62] = p[64] = p[65] = 'Discover'; + p[30] = p[36] = p[38] = p[39] = 'Diners Club'; + + return p[(number + '').slice(0, 2)] || 'Unknown'; }; return pub; -- cgit v0.9.1