【问题标题】:credit card verification not working with braintree and rails信用卡验证不适用于 Braintree 和 rails
【发布时间】:2014-04-29 14:53:38
【问题描述】:

我在创建客户时尝试使用 Braintree api 进行卡片验证。这是创建客户的代码:

@braintree_id = "#{current_user.profile_name}" + rand(5..1000).to_s
@result = Braintree::Customer.create(
    :id => @braintree_id,
    :first_name => employer_account_params[:first_name],
    :last_name => employer_account_params[:last_name],
    :company => employer_account_params[:company],
    :email => employer_account_params[:email],
    :phone => employer_account_params[:phone],
    :fax => employer_account_params[:fax],
    :website => employer_account_params[:website],
    :credit_card => {
        :number => employer_account_params[:credit_card][:number],
        :expiration_date => employer_account_params[:credit_card][:expiration_date],
        :billing_address => {
          :street_address => employer_account_params[:credit_card][:billing_address][:street_address],
          :extended_address => employer_account_params[:credit_card][:billing_address][:extended_address],
          :locality => employer_account_params[:credit_card][:billing_address][:locality],
          :region => employer_account_params[:credit_card][:billing_address][:region],
          :postal_code => employer_account_params[:credit_card][:billing_address][:postal_code],
          :country_code_alpha2 => employer_account_params[:credit_card][:billing_address][:country_code_alpha2]
        },
        :options => {
            :verify_card => true
            }
    }
)
puts 'result is ' + @result.inspect.to_s
@verification = @result.credit_card_verification
puts 'verification' + @verification.inspect.to_s
puts 'card results: ' + @verification.gateway_rejection_reason.to_s

问题在于 credit_card_verification 始终为零,无论 @result 返回 true 还是 false。这是上面代码中的控制台日志:

11:57:32 web.1  | result is #<Braintree::SuccessfulResult customer:#<Braintree::Customer id: "person2359", company: nil, email: nil, fax: nil, first_name: "sgdgsfd", last_name: nil, phone: nil, website: nil, created_at: 2014-04-29 15:57:32 UTC, updated_at: 2014-04-29 15:57:32 UTC, addresses: [#<Braintree::Address:0x007fe3639cefe8 @gateway=#<Braintree::Gateway:0x007fe364062eb8 @config=#<Braintree::Configuration:0x007fe3640630e8 @endpoint=nil, @environment=:sandbox, @public_key="vfyzr8zb7jqdhpxn", @private_key="[FILTERED]">>, @id="s7", @customer_id="person2359", @first_name=nil, @last_name=nil, @company=nil, @street_address="sdgfsgfgsdf", @extended_address=nil, @locality=nil, @region=nil, @postal_code=nil, @country_code_alpha2=nil, @country_code_alpha3=nil, @country_code_numeric=nil, @country_name=nil, @created_at=2014-04-29 15:57:32 UTC, @updated_at=2014-04-29 15:57:32 UTC>], credit_cards: [#<Braintree::CreditCard token: "66jz9r", billing_address: #<Braintree::Address:0x007fe3639cf8f8 @gateway=#<Braintree::Gateway:0x007fe364062eb8 @config=#<Braintree::Configuration:0x007fe3640630e8 @endpoint=nil, @environment=:sandbox, @public_key="vfyzr8zb7jqdhpxn", @private_key="[FILTERED]">>, @id="s7", @customer_id="person2359", @first_name=nil, @last_name=nil, @company=nil, @street_address="sdgfsgfgsdf", @extended_address=nil, @locality=nil, @region=nil, @postal_code=nil, @country_code_alpha2=nil, @country_code_alpha3=nil, @country_code_numeric=nil, @country_name=nil, @created_at=2014-04-29 15:57:32 UTC, @updated_at=2014-04-29 15:57:32 UTC>, bin: "411111", card_type: "Visa", cardholder_name: nil, created_at: 2014-04-29 15:57:32 UTC, customer_id: "person2359", expiration_month: "11", expiration_year: "2015", last_4: "1111", updated_at: 2014-04-29 15:57:32 UTC, prepaid: "Unknown", payroll: "Unknown", commercial: "Unknown", debit: "Unknown", durbin_regulated: "Unknown", healthcare: "Unknown", country_of_issuance: "Unknown", issuing_bank: "Unknown", image_url: "https://assets.braintreegateway.com/payment_method_logo/visa.png?environment=sandbox&merchant_id=b7gwpzqrspgmyc2x">]>>
11:57:32 web.1  | Completed 500 Internal Server Error in 844ms
11:57:32 web.1  | 
11:57:32 web.1  | NoMethodError (undefined method `credit_card_verification' for #<Braintree::SuccessfulResult:0x007fe3639ce4d0>):
11:57:32 web.1  |   app/controllers/payments_controller.rb:210:in `create_employer_account'
11:57:32 web.1  | 
11:57:32 web.1  | 
11:57:32 web.1  |   Rendered /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.7ms)
11:57:32 web.1  |   Rendered /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.9ms)
11:57:32 web.1  |   Rendered /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
11:57:32 web.1  |   Rendered /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (16.2ms)

如何才能使验证有效?

【问题讨论】:

  • 您确实注意到@result 是一个ErrorResult,其中包含errors,其中列出了发现的验证问题,对吧?
  • 是的,但这仅包含有关不正确的表单提交的错误,即某人输入的信用卡号的位数有误。如果表单提交正确,但该人的信用卡由于某种原因被拒绝,braintree 网站说使用我上面使用的 credit_card_verification 方法。它在这里说:braintreepayments.com/docs/ruby/card_verifications/overview。如果在表单中输入了正确的信息,我将发布我的服务器日志,在这种情况下它仍然无法正常工作。
  • 我刚刚更新了上面的代码
  • 你检查过这个问题吗:stackoverflow.com/questions/19413961/…
  • 谢谢,我看过了,但即使使用 .nil 进行检查,我也遇到了同样的问题?或切换到使用交易。

标签: ruby-on-rails ruby ruby-on-rails-4 braintree


【解决方案1】:

Braintree 只会在传入的参数有效的情况下运行验证,如果失败则只返回验证。

在您的第一个示例(现在从您的帖子中删除)中,创建失败,因为您没有传递有效的参数。

在您的第二个示例中,验证成功,因此不会返回。

您可以使用无效的卡号或Sandbox credit card numbers or unsuccessful verification numbers 之一在沙盒中模拟这些不同的情况。

例子:

result = Braintree::Customer.create(  
  :credit_card => {                   
    :number => "4000111111111115",    
    :expiration_month => "10",        
    :expiration_year => "2014",       
    :cvv => "200",                    
    :options => {:verify_card => true}
  }                                   
)                                     

if result.success?
  # handle success
elsif result.credit_card_verification
  p verification.processor_response_code
  p verification.processor_response_text
else
  # use result.errors to see what part of the request was invalid

【讨论】:

  • 太棒了,谢谢!您是否知道 ruby​​ 文档中的哪个位置说明了如何仅释放托管中的部分资金,或者我应该联系支持人员吗?
  • @Philip7899 您不能对托管交易进行部分退款或部分放款。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-23
  • 2013-05-25
  • 2014-09-06
  • 1970-01-01
  • 1970-01-01
  • 2014-08-14
相关资源
最近更新 更多