Get form url when submitting from api

Hi, I have a form with payment module.

The payment module is using $_SERVER['REQUEST_URI'] to get the current url and sets it as the redirect url for the payment gateway.

it works fine when submitting the form from browser.
User gets redirected to the third party payment gateway and then redirects back to the forms page.

But when form is being submitted throw api the redirect url becomes which is not currect and is the submit url for the forms api.

So how can I get the correct url to set for the payment gateway redirect when submitting the form with api.

also posted here