使用 ActiveMerchant 时如何处理超时?
Posted
技术标签:
【中文标题】使用 ActiveMerchant 时如何处理超时?【英文标题】:How do I handle timeouts when using ActiveMerchant? 【发布时间】:2013-11-26 10:24:59 【问题描述】:有时在本地开发时,我的连接会中断,虽然这种情况希望不会发生在生产环境中,但它引发了一个问题,即当 ActiveMerchant 发送到支付网关时,我可能应该处理来自 SagePay 的超时。
我在文档中看不到执行此操作的方法,我想知道是否有最佳实践方法来处理此问题?
【问题讨论】:
【参考方案1】:我相信这个问题与 AM 的 ruby 实现有关(如果我错了,请纠正我)。
ActiveMerchant
在发生超时时引发 ActiveMerchant::ConnectionError
(link to source)。因此我们可以简单地处理异常。例如:
begin
# Your ActiveMerchant staff here
rescue ActiveMerchant::ConnectionError => e
# timeout handler
end
有时使用open_timeout
和read_timeout
类属性(link to source)控制超时也很有用,如果是SagePay
:
ActiveMerchant::SagePay.open_timeout = 5 # timeout for opening the connection is set to 5 seconds
ActiveMerchant::SagePay.read_timeout = 10 # timeout for reading from opened connection is set to 10
【讨论】:
以上是关于使用 ActiveMerchant 时如何处理超时?的主要内容,如果未能解决你的问题,请参考以下文章
ActiveMerchant 如何处理 Authorize.net 上的定期付款取消信用卡帐户?
使用 QNetworkAccessManager 时如何处理代理