2014-11-03 26 views
0

Im与ActiveMerchant发生奇怪的问题。 我使用activemerchant验证信用卡号码并且工作正常。但是,我发现它似乎没有验证此卡号码3088023605344101,当我输入类型为JCB的卡号时,也会出现大多数验证问题。这里是我的代码看起来像ActiveMerchant说有效卡片的信用卡无效

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] 
        ) 

这是我的控制台正确验证卡的一个例子。

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" 

虽然这似乎工作正常,这是一个引发品牌错误的例子。起初,我不会喂这个品牌,而是让它去找活跃的商家去寻找它。

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"=>[]}  

所以我喂品牌

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"]} 

我已经验证了从不同的网站上的卡号,他们似乎只是罚款。我验证卡的网站是freeformatterigo

我不知道问题是什么,但如果有人知道为什么会发生这种情况,请告诉我。

回答

0

我在active_merchant github上提出的问题表明,他们使用这个正则表达式/^35(28|29|[3-8]\d)\d{12}$/来验证卡的类型是JCB。 所以我刚刚改变了正则表达式,但问题是为什么我提到的那些网站有30系列卡,而IIN是35。所以我需要澄清一下这个问题,即我现在要提出的问题。

这里是改变正则表达式

def type 
    if @card =~ /^5[1-5][0-9]{14}$/ 
    return SUPPORTED_CARD_BRANDS[:MASTERCARD] 
    elsif @card.match(/^4[0-9]{12}([0-9]{3})?$/) 
    return SUPPORTED_CARD_BRANDS[:VISA] 
    elsif @card.match(/^3[47][0-9]{13}$/) 
    return SUPPORTED_CARD_BRANDS[:AMEX] 
    elsif @card =~ /^3(0[0-5]|[68][0-9])[0-9]{11}$/ 
    return SUPPORTED_CARD_BRANDS[:DINNERS] 
    elsif @card =~ /^6011[0-9]{12}$/ 
    return SUPPORTED_CARD_BRANDS[:DISCOVER] 
    elsif @card =~ /^(3[0-9]{4}|2131|1800)[0-9]{11}$/ 
    return SUPPORTED_CARD_BRANDS[:JCB] 
    elsif @card =~ /^(5[06-8]|6)[0-9]{10,17}$/ 
    return SUPPORTED_CARD_BRANDS[:MAESTRO] 
    else 
    return nil 
    end 
end 
相关问题