Hi I installed Mangopay payment solution on my rails app. Even though I check the user's Iban and Bic when they update their profile with regular expressions, sometimes when I send the data to Mangopay I get an error message (I guess because even though iban's and bic have a correct format, mangopay finds that they dont actually exist): "One or several required parameters are missing or incorrect. An incorrect resource ID also raises this kind of error. IBAN: IBAN or BIC not valid"
My code for sending theses infos to Mangopay looks like 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 I rescue this error ? I tried something 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 it doesnt work...
Found the solution :
calling rescue enables to deal with the error from mangopay