i using braintree process payments via web application, no problems far, plenty of documentation little unsure of how handle errors in controller. don't think should looking display error messages user pose security risk handle errors better now, perhaps capturing selection of generic errors?
the point of question here how go capturing these, within rescue
or create method errors go through , display custom messages errors?
at moment have simple controller action
@result = braintree::transaction.sale( amount: @amount, payment_method_nonce: params[:payment_method_nonce], options: { submit_for_settlement: true } ) if @result.success? redirect_to thank_you_path else flash[:alert] = 'something went wrong while processing transaction. please try again!' gon.client_token = generate_client_token render :new end
i display generic "something went wrong" message when @result not successful.
i'm sure there better ways deal , appreciated suggestions
thnaks
the result instance of object, having whole information transaction status.
you might extract whatever information want , print out client.
e.g. group messages error code, 1 might use smth this:
unless @result.success? flash[:alert] = case @result.transaction.processor_response_code.to_s when /^2/ "contact bank" else "something went wrong" end ... end
Comments
Post a Comment