Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby ActiveMerchant表示有效卡的信用卡无效_Ruby_Ruby On Rails 4_Activemerchant - Fatal编程技术网

Ruby ActiveMerchant表示有效卡的信用卡无效

Ruby ActiveMerchant表示有效卡的信用卡无效,ruby,ruby-on-rails-4,activemerchant,Ruby,Ruby On Rails 4,Activemerchant,我遇到了一个关于ActiveMerchant的奇怪问题。 我正在使用activemerchant验证一个信用卡号码,它工作正常。但是,我发现它似乎无法验证此卡号3088023605344101,而且大多数验证问题都是在我输入JCB类型的卡号时出现的。下面是我的代码 cc = CreditCard.new( :first_name => client_details[:firstname], :last_name

我遇到了一个关于
ActiveMerchant
的奇怪问题。 我正在使用
activemerchant
验证一个信用卡号码,它工作正常。但是,我发现它似乎无法验证此卡号
3088023605344101
,而且大多数验证问题都是在我输入
JCB
类型的卡号时出现的。下面是我的代码

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:052>cc=CreditCard.new(:first\u name=>'Steve',:last\u name=>'Smith',:month=>'9',:year=>'2015',:number=>'5201457519355638',:verification\u value=>'123')
=>#和


我不确定问题出在哪里,但是如果有人知道为什么会发生这种情况,请告诉我

我在活动商户github上提出的问题建议他们使用这个regex
/^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
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"]} 
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