首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复由不正确的Iban或Bic导致的Mangopay错误

如何修复由不正确的Iban或Bic导致的Mangopay错误
EN

Stack Overflow用户
提问于 2015-05-30 01:22:08
回答 2查看 292关注 0票数 0

嗨,我在我的rails应用程序上安装了Mangopay支付解决方案。即使当用户使用正则表达式更新他们的配置文件时,我检查用户的IBAN和bic,有时当我将数据发送到Mangopay时,我会收到错误消息(我猜是因为即使Iban和Bic具有正确的格式,mangopay发现它们实际上并不存在):“一个或多个必需的参数丢失或不正确。错误的资源ID也会引发此类错误。IBAN: IBAN或BIC无效。”

我将这些信息发送到Mangopay的代码如下:

代码语言:javascript
复制
  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

我怎样才能挽救这个错误?我试过这样的方法:

代码语言:javascript
复制
 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

但是它不工作..。

EN

回答 2

Stack Overflow用户

发布于 2015-05-30 18:16:57

找到解决方案:

代码语言:javascript
复制
 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的错误

票数 0
EN

Stack Overflow用户

发布于 2017-09-19 21:48:01

下面是我是如何做到这一点的,通过将代码封装在一个begin救援块中。

代码语言:javascript
复制
    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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30535543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档