如何解决由不正确的Iban或Bic引起的Mangopay错误

时间:2015-05-29 17:22:08

标签: ruby-on-rails error-handling payment

您好我在我的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

但它不起作用......

2 个答案:

答案 0 :(得分:0)

找到解决方案:

 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

调用rescue可以处理来自mangopay的错误

答案 1 :(得分:0)

这是我如何做到这一点,将代码包含在一个开始救援块中。

    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
    end
相关问题