嗨,我在我的rails应用程序上安装了Mangopay支付解决方案。即使当用户使用正则表达式更新他们的配置文件时,我检查用户的IBAN和bic,有时当我将数据发送到Mangopay时,我会收到错误消息(我猜是因为即使Iban和Bic具有正确的格式,mangopay发现它们实际上并不存在):“一个或多个必需的参数丢失或不正确。错误的资源ID也会引发此类错误。IBAN: IBAN或BIC无效。”
我将这些信息发送到Mangopay的代码如下:
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我怎样才能挽救这个错误?我试过这样的方法:
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但是它不工作..。
发布于 2015-05-30 18:16:57
找到解决方案:
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调用救援可以处理来自mangopay的错误
发布于 2017-09-19 21:48:01
下面是我是如何做到这一点的,通过将代码封装在一个begin救援块中。
def create_mangopay_bank_account
begin
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
rescue MangoPay::ResponseError => exception
#handle your error here
redirect_to user_path
end
endhttps://stackoverflow.com/questions/30535543
复制相似问题