3

I'm using braintree for payment processing and I'm trying to get Processor Response Codes from Braintree with Ruby.

Here is my code :

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

I'm getting verification as nil even when there is error.

Is there something else to get Processor Response Codes?

I got this code from here

Here is my result.erros :

: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: {}
Sachin Prasad
  • 5,365
  • 12
  • 54
  • 101
  • I work at Braintree. If you have a validation error, there won't be a verification. What does `result.errors` look like? – agf Oct 17 '13 at 00:12
  • @agf I have updated my question. Actually I want to handle all the errors and show some generic message depending on the error types listed at Processor Response Codes. BTW is it compulsory to display this validation errors first and after that manage Processor Response Codes?(Or you can say best practices) – Sachin Prasad Oct 17 '13 at 05:19

1 Answers1

4

I work at Braintree. If you'd like more help than you can get here on Stack Overflow, please reach out to our support team.

Handling Braintree result objects is progressive.

If result.success? is false, then you check for result.errors, which represent validation errors.

If result.errors is nil, then the request was valid. In this case, you will have a transaction or verification object just as if result.success? was true.

You can then look at the result.verification's status, processor_response_code, gateway_rejection_reason, etc.

The linked documentation provides more details on handling error results.

agf
  • 171,228
  • 44
  • 289
  • 238
  • 3
    And why not state that clearly in the dev docs on all sections??? Why does only the transaction section have an explanation?. If I do transactions it is stated how, but if I do vault stuff, there is nothing on handling results. On such a complex result object the doc readers can't assume it works the same way for transactions as it does for create_customer_data. Does it by the way? – Rutger Karlsson Oct 22 '13 at 21:39
  • 3
    Or the fact that you get an Braintree::AuthorizationError if you supply invalid params. The exeption name is not über clear. – Rutger Karlsson Oct 22 '13 at 21:46
  • @RutgerKarlsson The [verification docs also give this information](https://www.braintreepayments.com/docs/ruby/card_verifications/overview#verification_result_explanations), and yes, it is consistent for any object that can create a transaction / verification. – agf Oct 22 '13 at 21:54