Im running through a weird issue with ActiveMerchant
.
I'm using activemerchant
to validate a credit card number and its been working fine. However, I found that it somehow doesn't seem to validate this card number 3088023605344101
, also most of the validation issues arise when I input a card number of the type JCB
. Here is what my code looks like
cc = CreditCard.new(
:first_name => client_details[:firstname],
:last_name => client_details[:lastname],
:month => client_details[:month],
:year => client_details[:year],
:number => client_details[:cardnum],
:verification_value => client_details[:cvv]
)
Here is an example from my console which correctly validates the card.
2.1.1 :052 > cc = CreditCard.new(:first_name => 'Steve',:last_name => 'Smith', :month => '9',:year => '2015',:number => '5201457519355638', :verification_value => '123')
=> #<ActiveMerchant::Billing::CreditCard:0x00000109d3acc0 @first_name="Steve", @last_name="Smith", @month="9", @year="2015", @number="5201457519355638", @verification_value="123">
2.1.1 :053 > cc.valid?
=> true
2.1.1 :054 > cc.brand
=> "master"
while this seems to be working fine, here is an example which that throws brand error. At first, I don't feed in the brand and leave it to active merchant to find it.
2.1.1 :056 > cc = CreditCard.new(:first_name => 'Steve',:last_name => 'Smith', :month => '9',:year => '2015',:number => '3088023605344101', :verification_value => '123')
=> #<ActiveMerchant::Billing::CreditCard:0x0000010a0d91d8 @first_name="Steve", @last_name="Smith", @month="9", @year="2015", @number="3088023605344101", @verification_value="123">
2.1.1 :057 > cc.valid?
=> false
2.1.1 :058 > cc.errors
=> {"brand"=>["is required"], "number"=>[]}
So I feed brand
2.1.1 :059 > cc = CreditCard.new(:first_name => 'Steve',:last_name => 'Smith', :month => '9',:year => '2015',:number => '3088023605344101', :verification_value => '123', :brand => 'jcb')
=> #<ActiveMerchant::Billing::CreditCard:0x00000109d886c8 @first_name="Steve", @last_name="Smith", @month="9", @year="2015", @number="3088023605344101", @verification_value="123", @brand="jcb">
2.1.1 :060 > cc.valid?
=> false
2.1.1 :061 > cc.errors
=> {"number"=>[], "brand"=>["does not match the card number"]}
I have validated the card numbers from different site and they seem to be just fine. The sites I validated the card from are freeformatter and igo
Im not sure what the problem is, but if anyone knows why this is happening then do let me know.
The issue I raised on active_merchant github suggested that they use this regex
/^35(28|29|[3-8]\d)\d{12}$/
to validate if the card is of typeJCB
. So I just changed the regex accordingly but the question is why are those sites I mentioned have30
series cards while the IIN is35
. So I need to clarification on this, a question for which Im going to raise on SO now.Here is the changed regex