You basically want to replace a background, which is seen through something reflective/refractive.
To do it, simply set direct, reflections, and refractions override to pure black in render setup > scene, then save your image with alpha channel, and then replace your background. Attaching examples.
It does not look perfect in this example with so thick glass, but should be much better in a real life scene.