Can we have an example for handling errors with Braintree payment?
Our Braintree payments are working, but the issue is when a credit card is not valid, the Pay gem will throw a 500 error and we need a way to rescue this.
Here is the trace message:
Here is the trace message:
web | I, [] INFO -- : [Braintree] [15/Mar/2022 05:27:47 UTC] GET /merchants/.../customers/222853418 200 web | I, [] INFO -- : [Braintree] [15/Mar/2022 05:27:48 UTC] POST /merchants/.../payment_methods 422 web | Completed 500 Internal Server Error in 1817ms (ActiveRecord: 3.3ms | Allocations: 29310) web | web | web | Error during failsafe response: undefined method `cause' for #<Braintree::ErrorResult params:{...} errors:<> credit_card_verification: #<Braintree::CreditCardVerification status: "processor_declined", processor_response_code: "2000", processor_response_text: "Do Not Honor", amount: "0.0", currency_iso_code: "USD", cvv_response_code: "M", avs_error_response_code: nil, avs_postal_code_response_code: "I", avs_street_address_response_code: "I", network_response_code: "XX", network_response_text: "sample network response text", merchant_account_id: "...", gateway_rejection_reason: nil, id: "", credit_card: {:token=>nil, :bin=>"400011", :last_4=>"1115", :card_type=>"Visa", :expiration_month=>"12", :expiration_year=>"2034", :customer_location=>"US", :cardholder_name=>nil, :unique_number_identifier=>"", :account_type=>"credit", :global_id=>nil, :prepaid=>"Unknown", :healthcare=>"Unknown", :debit=>"Unknown", :durbin_regulated=>"Unknown", :commercial=>"Unknown", :payroll=>"Unknown", :issuing_bank=>"Unknown", :country_of_issuance=>"Unknown", :product_id=>"Unknown"}, billing: {:first_name=>nil, :last_name=>nil, :company=>nil, :street_address=>nil, :extended_address=>nil, :locality=>nil, :region=>nil, :postal_code=>nil, :country_name=>nil}, created_at: ...>> web | web | yield exception while exception = exception.cause web | ^^^^^^ web | /Users//.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/actionpack-7.0.1/lib/action_dispatch/middleware/exception_wrapper.rb:156:in `causes_for'
It seems I can't rescue this behavior with a normal rescue like this:
begin charge = account.payment_processor.charge(subtotal) # the controller will stop right here after the 500 status rescue ## tried different error types: Pay::Error, Pay::BratinTreeError ## this doesn't get run end
Is there anyway we can recover this error?
Notifications
You’re not receiving notifications from this thread.