【问题标题】:result.credit_card_verification is returning nil even on error in braintreeresult.credit_card_verification 即使在 Braintree 中出现错误时也返回 nil
【发布时间】:2013-10-25 04:33:29
【问题描述】:

我正在使用 Braintree 进行支付处理,并且我正在尝试使用 Ruby 从 Braintree 获取 Processor Response Codes

这是我的代码:

 verification = result.credit_card_verification
 response_code = verification.try(:processor_response_code)

即使出现错误,我的验证也为零。

还有其他东西可以获取处理器响应代码吗?

我从here得到这个代码

这是我的结果。错误:

:errors: !ruby/object:Braintree::Errors
  errors: !ruby/object:Braintree::ValidationErrorCollection
    errors: []
    nested:
      :customer: !ruby/object:Braintree::ValidationErrorCollection
        errors: []
        nested:
          :credit_card: !ruby/object:Braintree::ValidationErrorCollection
            errors:
            - !ruby/object:Braintree::ValidationError
              code: '81707'
              attribute: cvv
              message: CVV must be 4 digits for American Express and 3 digits for
                other card types.
            - !ruby/object:Braintree::ValidationError
              code: '81713'
              attribute: expiration_year
              message: Expiration year is invalid.
            - !ruby/object:Braintree::ValidationError
              code: '81703'
              attribute: number
              message: Credit card type is not accepted by this merchant account.
            - !ruby/object:Braintree::ValidationError
              code: '81715'
              attribute: number
              message: Credit card number is invalid.
            nested:
              :billing_address: !ruby/object:Braintree::ValidationErrorCollection
                errors: []
                nested: {}

【问题讨论】:

  • 我在布伦特里工作。如果您有验证错误,则不会进行验证。 result.errors 长什么样子?
  • @agf 我已经更新了我的问题。实际上,我想处理所有错误并根据处理器响应代码中列出的错误类型显示一些通用消息。顺便说一句,是否必须先显示此验证错误,然后再管理处理器响应代码?(或者您可以说最佳实践)

标签: ruby-on-rails ruby ruby-on-rails-3 payment-processing braintree


【解决方案1】:

我在布伦特里工作。如果您需要比 Stack Overflow 更多的帮助,请联系our support team

处理Braintree result objects 是渐进式的。

如果result.success?false,则检查result.errors,它代表validation errors

如果result.errorsnil,则请求有效。在这种情况下,您将拥有一个 transactionverification 对象,就像 result.success?true 一样。

然后您可以查看result.verificationstatusprocessor_response_codegateway_rejection_reason 等。

链接的文档提供了有关处理错误结果的更多详细信息。

【讨论】:

  • 为什么不在所有部分的开发文档中明确说明?为什么只有交易部分有解释?如果我做交易,它会说明如何,但如果我做保险库的东西,处理结果就没有任何意义。在如此复杂的结果对象上,文档读者不能假设它对事务的工作方式与对 create_customer_data 的工作方式相同。顺便说一句吗?
  • 或者如果你提供了无效的参数,你会得到一个 Braintree::AuthorizationError 的事实。异常名称不是很清楚。
  • @RutgerKarlsson verification docs also give this information,是的,它对于任何可以创建事务/验证的对象都是一致的。
猜你喜欢
  • 2021-09-18
  • 2016-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-20
  • 2015-04-01
  • 1970-01-01
  • 2021-01-13
相关资源
最近更新 更多