nomemory/mockneat

Allow option to provide BIN prefix when generating credit card number

lazycodeninja opened this issue ยท 4 comments

Congratulations on a cool library, "neat" is an appropriate name. ๐Ÿ‘

I was planning to use the creditCards() method to easily generate a credit card number, but need it to be generated with a specific BIN else it will be rejected as invalid in the system I'm testing. From the code the card prefix is taken from the CreditCardType enum, which in the case of Visa is just the first digit (4). From what I've read this is the IIN, the issuer identification number.

It would be nice if CreditCards had another method to specify a pool of BINs to use when generating the number, e.g.

String cardNumber1 = mockNeat.creditCards().visa().bins(445434).val();
String cardNumber2 = mockNeat.creditCards().visa().bins(445434, 414433).val();

I thought I'd try to code this up and submitting a pull request, but it's a little trickier than I thought. At first glance I thought it was a simple builder pattern and I'd just need another method in CreditCards to set the BIN, but after looking at the code I see that this isn't the case; it's not possible to chain methods from anything other than MockUnitString. I thought it may be possible instead to just bypass the type when specifying the bin, e.g.

String cardNumber1 = mockNeat.creditCards().bin(445434).val();

since we no longer need the prefix provided by CreditCardType, but then the length is unknown.

@lazycodeninja

Thanks for the interest.

In the latest version 0.2.4, added today, check the custom() method on creditCards().

Example:

// Prints 100 credit card numbers that start with 445434 or 414433
// and have a length = 15
 M.creditCards()
         .custom(15, 445434, 414433)
         .consume(100, (i, cc) -> System.out.println(cc));

The method works like this (the documentation is not yet written for it):

custom(length, prefix1, prefix2, ..., prefixN)

Where prefix is the IIN/BIN combination.

Hope it helps.

Thanks you very much, that was very quick.

Yes the new method does just what I need. ๐Ÿ‘

@lazycodeninja,

Glad it helped.