How to open unity desktop app from web browser?

Hello Friends,

Actually I am working on a PC/Mac game and I have integrated a payment gateway also. What I want is that after payment success it should automatically open the application.

Currently if a user taps “Pay” button then he/she is take to payment page which gets open in a browser. then after payment he/she has to manually return to app. If any one has answer please help me. Thanks in advance.

I don’t think there is any built-in way in Unity to do this.

You first need to be able to detect purchase completions. This is relatively easy, as you can just signal the program from the server when paypal reports success.

Opening the App again is harder, and I can think of some alternatives:

Open new browser, close it after buying

You would need to ensure that the payment page is opened in a new browser window, and that tabs and URL bar is disabled. That way you should be able to close it after the purchase is done without annoying the user by closing its main browser window. Once it is closed, if the user did not meanwhile switch to other window, your program should automagically recover focus. You can start the browser as a child process to close it easily.

This will need further work, but for instance, to open a Chrome new window you can:

// Requires using the System.Diagnostics namespace
Process proc = new Process();
proc.StartInfo.FileName = @"chrome";
proc.StartInfo.Arguments = @"unity3d.com --new-window";
proc.Start();

Once that window is closed, focus should return on its own.

Explicitly switch focus again once the payment is done

This can be done through low level WINAPI functions such as SwitchToThisWindow.
However, they tend to not work very realiably, and you will need plugins / pinvoke to use it, so unless you can find a better one, I would try the first approach.