ActiveMerchant表示信用卡无效 [英] ActiveMerchant says invalid credit card for a valid card

查看:151
本文介绍了ActiveMerchant表示信用卡无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了带有 ActiveMerchant 的怪异问题。
我正在使用 activemerchant 来验证信用卡号,并且该卡工作正常。但是,我发现以某种方式似乎无法验证该卡号 3088023605344101 ,当我输入<$ c类型的卡号时,大多数验证问题也会出现$ c> JCB 。这是我的代码

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

所以我喂品牌

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

我已经验证了不同站点的卡号,它们似乎还不错。我验证了卡片的网站是 freeformatter igo

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.

推荐答案

我在active_merchant github上提出的问题建议他们使用此正则表达式 / ^ 35(28 | 29 | [3-8] \d)\d {12} $ / 以验证卡的类型是否为 JCB
因此,我只是相应地更改了正则表达式,但问题是为什么我提到的那些网站的IIN为 35 <,却有 30 系列卡。因此,我需要对此进行澄清,我现在要就SO提出这个问题。

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 type JCB. So I just changed the regex accordingly but the question is why are those sites I mentioned have 30 series cards while the IIN is 35. So I need to clarification on this, a question for which Im going to raise on SO now.

这是已更改的正则表达式

Here is the changed regex

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

这篇关于ActiveMerchant表示信用卡无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆