Mailing List Archive

[interchange] add unit tests for credit cards
commit 46d36ed458731bb66aee904bb58320b1a2e4fba2
Author: Josh Lavin <jlavin@endpoint.com>
Date: Wed Jul 20 15:57:43 2016 -0700

add unit tests for credit cards

t/credit_cards.t | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/t/credit_cards.t b/t/credit_cards.t
new file mode 100644
index 0000000..4303514
--- /dev/null
+++ b/t/credit_cards.t
@@ -0,0 +1,58 @@
+use strict;
+use warnings;
+use lib 'lib';
+use Test::More;
+use Vend::Order;
+
+is( Vend::Order::guess_cc_type(''), '', 'credit card: blank' );
+
+is( Vend::Order::guess_cc_type('4123456789012'), 'visa', 'credit card: visa 12' );
+is( Vend::Order::guess_cc_type('4123456789012345'), 'visa', 'credit card: visa 15' );
+
+is( Vend::Order::guess_cc_type('5123456789012345'), 'mc', 'credit card: mc, 1 then 14' );
+is( Vend::Order::guess_cc_type('2221001234567890'), 'mc', 'credit card: mc BIN 2, 5 then 10 #1' );
+is( Vend::Order::guess_cc_type('2720991234567890'), 'mc', 'credit card: mc BIN 2, 5 then 10 #2' );
+is( Vend::Order::guess_cc_type('2700991234567890'), 'mc', 'credit card: mc BIN 2, 5 then 10 #3' );
+
+is( Vend::Order::guess_cc_type('3001234567890112'), 'discover', 'credit card: discover diners club 300' );
+is( Vend::Order::guess_cc_type('3095123456789012'), 'discover', 'credit card: discover diners club 3095' );
+is( Vend::Order::guess_cc_type('3612345678901212'), 'discover', 'credit card: discover diners club 36' );
+is( Vend::Order::guess_cc_type('6011123456789012'), 'discover', 'credit card: discover 6011' );
+is( Vend::Order::guess_cc_type('6441234567890123'), 'discover', 'credit card: discover 644' );
+is( Vend::Order::guess_cc_type('6512345678901234'), 'discover', 'credit card: discover 65' );
+is( Vend::Order::guess_cc_type('6221234567890123'), 'discover', 'credit card: discover chinaunionpay 622, no country' );
+is( Vend::Order::guess_cc_type('6251234567890123'), 'discover', 'credit card: discover chinaunionpay 625, no country' );
+# not setting Values to test country
+
+is( Vend::Order::guess_cc_type('341234567890123'), 'amex', 'credit card: amex 34' );
+is( Vend::Order::guess_cc_type('371234567890123'), 'amex', 'credit card: amex 37' );
+
+# defunct
+#is( Vend::Order::guess_cc_type('36123456789012'), 'dinersclub', 'credit card: dinersclub 36' );
+#is( Vend::Order::guess_cc_type('30012345678901'), 'dinersclub', 'credit card: dinersclub 300' );
+#is( Vend::Order::guess_cc_type('38123456789012'), 'carteblanche', 'credit card: carteblanche' );
+
+is( Vend::Order::guess_cc_type('201412345678901'), 'enroute', 'credit card: enroute 2014' );
+is( Vend::Order::guess_cc_type('214912345678901'), 'enroute', 'credit card: enroute 2149' );
+
+is( Vend::Order::guess_cc_type('3123456789012345'), 'jcb', 'credit card: jcb' );
+is( Vend::Order::guess_cc_type('3213112345678901'), 'jcb', 'credit card: jcb 32131' );
+is( Vend::Order::guess_cc_type('3180012345678901'), 'jcb', 'credit card: jcb 31800' );
+
+is( Vend::Order::guess_cc_type('4903020123456789012'), 'switch', 'credit card: switch' );
+is( Vend::Order::guess_cc_type('564182123456789012'), 'switch', 'credit card: switch 564182' );
+is( Vend::Order::guess_cc_type('633300123456789012'), 'switch', 'credit card: switch 63300' );
+is( Vend::Order::guess_cc_type('675900123456789012'), 'switch', 'credit card: switch 675900' );
+
+is( Vend::Order::guess_cc_type('5610001234567890'), 'bankcard', 'credit card: bankcard 5610' );
+is( Vend::Order::guess_cc_type('5602211234567890'), 'bankcard', 'credit card: bankcard 56022' );
+
+is( Vend::Order::guess_cc_type('633450123456789012'), 'solo', 'credit card: solo 633450' );
+is( Vend::Order::guess_cc_type('676700123456789012'), 'solo', 'credit card: solo 676700' );
+
+is( Vend::Order::guess_cc_type('630409123456789012'), 'laser', 'credit card: laser 630409' );
+is( Vend::Order::guess_cc_type('6771123456789012'), 'laser', 'credit card: laser 6771' );
+
+is( Vend::Order::guess_cc_type('123'), 'other', 'credit card: other' );
+
+done_testing();

_______________________________________________
interchange-cvs mailing list
interchange-cvs@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-cvs
Re: [interchange] add unit tests for credit cards [ In reply to ]
On 07/21/2016 12:58 AM, Josh Lavin wrote:
> commit 46d36ed458731bb66aee904bb58320b1a2e4fba2
> Author: Josh Lavin <jlavin@endpoint.com>
> Date: Wed Jul 20 15:57:43 2016 -0700
>
> add unit tests for credit cards
>
> t/credit_cards.t | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 58 insertions(+), 0 deletions(-)


Josh, it would be also interesting if these results match up with Business::CreditCard.
Also we might check recent changes in this module.

And thanks for adding these tests!

Regards
Racke

> ---
> diff --git a/t/credit_cards.t b/t/credit_cards.t
> new file mode 100644
> index 0000000..4303514
> --- /dev/null
> +++ b/t/credit_cards.t
> @@ -0,0 +1,58 @@
> +use strict;
> +use warnings;
> +use lib 'lib';
> +use Test::More;
> +use Vend::Order;
> +
> +is( Vend::Order::guess_cc_type(''), '', 'credit card: blank' );
> +
> +is( Vend::Order::guess_cc_type('4123456789012'), 'visa', 'credit card: visa 12' );
> +is( Vend::Order::guess_cc_type('4123456789012345'), 'visa', 'credit card: visa 15' );
> +
> +is( Vend::Order::guess_cc_type('5123456789012345'), 'mc', 'credit card: mc, 1 then 14' );
> +is( Vend::Order::guess_cc_type('2221001234567890'), 'mc', 'credit card: mc BIN 2, 5 then 10 #1' );
> +is( Vend::Order::guess_cc_type('2720991234567890'), 'mc', 'credit card: mc BIN 2, 5 then 10 #2' );
> +is( Vend::Order::guess_cc_type('2700991234567890'), 'mc', 'credit card: mc BIN 2, 5 then 10 #3' );
> +
> +is( Vend::Order::guess_cc_type('3001234567890112'), 'discover', 'credit card: discover diners club 300' );
> +is( Vend::Order::guess_cc_type('3095123456789012'), 'discover', 'credit card: discover diners club 3095' );
> +is( Vend::Order::guess_cc_type('3612345678901212'), 'discover', 'credit card: discover diners club 36' );
> +is( Vend::Order::guess_cc_type('6011123456789012'), 'discover', 'credit card: discover 6011' );
> +is( Vend::Order::guess_cc_type('6441234567890123'), 'discover', 'credit card: discover 644' );
> +is( Vend::Order::guess_cc_type('6512345678901234'), 'discover', 'credit card: discover 65' );
> +is( Vend::Order::guess_cc_type('6221234567890123'), 'discover', 'credit card: discover chinaunionpay 622, no country' );
> +is( Vend::Order::guess_cc_type('6251234567890123'), 'discover', 'credit card: discover chinaunionpay 625, no country' );
> +# not setting Values to test country
> +
> +is( Vend::Order::guess_cc_type('341234567890123'), 'amex', 'credit card: amex 34' );
> +is( Vend::Order::guess_cc_type('371234567890123'), 'amex', 'credit card: amex 37' );
> +
> +# defunct
> +#is( Vend::Order::guess_cc_type('36123456789012'), 'dinersclub', 'credit card: dinersclub 36' );
> +#is( Vend::Order::guess_cc_type('30012345678901'), 'dinersclub', 'credit card: dinersclub 300' );
> +#is( Vend::Order::guess_cc_type('38123456789012'), 'carteblanche', 'credit card: carteblanche' );
> +
> +is( Vend::Order::guess_cc_type('201412345678901'), 'enroute', 'credit card: enroute 2014' );
> +is( Vend::Order::guess_cc_type('214912345678901'), 'enroute', 'credit card: enroute 2149' );
> +
> +is( Vend::Order::guess_cc_type('3123456789012345'), 'jcb', 'credit card: jcb' );
> +is( Vend::Order::guess_cc_type('3213112345678901'), 'jcb', 'credit card: jcb 32131' );
> +is( Vend::Order::guess_cc_type('3180012345678901'), 'jcb', 'credit card: jcb 31800' );
> +
> +is( Vend::Order::guess_cc_type('4903020123456789012'), 'switch', 'credit card: switch' );
> +is( Vend::Order::guess_cc_type('564182123456789012'), 'switch', 'credit card: switch 564182' );
> +is( Vend::Order::guess_cc_type('633300123456789012'), 'switch', 'credit card: switch 63300' );
> +is( Vend::Order::guess_cc_type('675900123456789012'), 'switch', 'credit card: switch 675900' );
> +
> +is( Vend::Order::guess_cc_type('5610001234567890'), 'bankcard', 'credit card: bankcard 5610' );
> +is( Vend::Order::guess_cc_type('5602211234567890'), 'bankcard', 'credit card: bankcard 56022' );
> +
> +is( Vend::Order::guess_cc_type('633450123456789012'), 'solo', 'credit card: solo 633450' );
> +is( Vend::Order::guess_cc_type('676700123456789012'), 'solo', 'credit card: solo 676700' );
> +
> +is( Vend::Order::guess_cc_type('630409123456789012'), 'laser', 'credit card: laser 630409' );
> +is( Vend::Order::guess_cc_type('6771123456789012'), 'laser', 'credit card: laser 6771' );
> +
> +is( Vend::Order::guess_cc_type('123'), 'other', 'credit card: other' );
> +
> +done_testing();
>
> _______________________________________________
> interchange-cvs mailing list
> interchange-cvs@icdevgroup.org
> http://www.icdevgroup.org/mailman/listinfo/interchange-cvs
>


--
Ecommerce and Linux consulting + Perl and web application programming.
Please visit our Perl Dancer Conference in Vienna: https://www.perl.dance.
Next presentation at YAPC Europe in Cluj: http://act.yapc.eu/ye2016/talk/6780.

_______________________________________________
interchange-cvs mailing list
interchange-cvs@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-cvs
Re: [interchange] add unit tests for credit cards [ In reply to ]
Quoting Stefan Hornburg (Racke) (racke@linuxia.de):
> On 07/21/2016 12:58 AM, Josh Lavin wrote:
> > commit 46d36ed458731bb66aee904bb58320b1a2e4fba2
> > Author: Josh Lavin <jlavin@endpoint.com>
> > Date: Wed Jul 20 15:57:43 2016 -0700
> >
> > add unit tests for credit cards
> >
> > t/credit_cards.t | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > 1 files changed, 58 insertions(+), 0 deletions(-)
>
>
> Josh, it would be also interesting if these results match up with Business::CreditCard.
> Also we might check recent changes in this module.

I'm committing a patch to add additional test credit card numbers from
Business::CreditCard.

I also updated the guess_cc_type() sub to more closely match
Business::CreditCard's cardtype(), for various number changes and also
support of "Isracard".

However, I am a bit leery of going overboard on the updating of the
Discover card section, which is here:

https://metacpan.org/source/IVAN/Business-CreditCard-0.36/CreditCard.pm#L256

I tried to keep the changes that extended card number length, but I'm
not sure of the ones that seem to constrict it. If anyone wants to take
this over, and also review my patch, that'd be great. :-)

The tests were certainly a nice feature to have when making these
changes!

--
Josh Lavin
End Point Corporation

_______________________________________________
interchange-cvs mailing list
interchange-cvs@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-cvs