4

Sometimes when developing locally my connection drops, and whilst this hopefully shouldn't happen on production it raises an issue that I should probably handle timeouts from ActiveMerchant when it goes out to the payment gateway, in my case to SagePay.

I can't see a way in the documentation to do this, I was wondering if there was a best practice way to handle this?

Toby
  • 8,483
  • 13
  • 45
  • 68

1 Answers1

0

I believe the question is connected to ruby implementation of AM (correct me if I'm wrong, please).

ActiveMerchant raises ActiveMerchant::ConnectionError when timeout occurs (link to source). Therefore we can simply handle the exception. e.g.:

begin
  # Your ActiveMerchant staff here
rescue ActiveMerchant::ConnectionError => e
  # timeout handler
end

Also sometimes it can be useful to control the timeouts using open_timeout and read_timeout class attributes (link to source), in case of 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
Axel
  • 3,331
  • 11
  • 35
  • 58