Port changes from UnityTech/active_merchant

I made some fixes in the original ActiveMerchant fork, as we ran into some issues in production.