ruby on rails - How to rescue Mangopay error caused by incorrect Iban or Bic -


hi installed mangopay payment solution on rails app. though check user's iban , bic when update profile regular expressions, when send data mangopay error message (i guess because though iban's , bic have correct format, mangopay finds dont exist): "one or several required parameters missing or incorrect. incorrect resource id raises kind of error. iban: iban or bic not valid"

my code sending theses infos mangopay looks this:

  def create_mangopay_bank_account     bank_account = mangopay::bankaccount.create(current_user.mangopay_natural_user_id, mangopay_user_bank_attributes)     current_user.bank_account_id = bank_account["id"]     current_user.save   end 

how can rescue error ? tried like:

 def create_mangopay_bank_account     if mangopay::bankaccount.create(current_user.mangopay_natural_user_id, mangopay_user_bank_attributes)       bank_account = mangopay::bankaccount.create(current_user.mangopay_natural_user_id, mangopay_user_bank_attributes)       current_user.bank_account_id = bank_account["id"]       current_user.save     else       redirect_to user_path   end 

but doesnt work...

found solution :

 def create_mangopay_bank_account        bank_account = mangopay::bankaccount.create(current_user.mangopay_natural_user_id, mangopay_user_bank_attributes)       current_user.bank_account_id = bank_account["id"]       current_user.save       rescue mangopay::responseerror => e         redirect_to root_path         flash[:alert] = "l'iban ou le bic que vous avez fourni n'est pas valide. veuillez vérifier les informations fournies. si le problème persiste n'hésitez pas à contacter l'équipe tennismatch."     end 

calling rescue enables deal error mangopay


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -