add support for overriding merchantId and better exceptional handling