Prãshant Saraswat
Prãshant Saraswat

Reputation: 366

How to get return URL from WebView after successful payment in Xamarin.Forms app?

I have integrated a payment gateway in my Xamarin Forms app. After filling the payment details I am opening the payment page in WebView to complete the payment. When the payment is completed it returns a URL with the payment status code. Now the question is that how can I get this return URL in my Xamarin Forms app?

Upvotes: 0

Views: 1357

Answers (1)

Almir Vuk
Almir Vuk

Reputation: 3173

First of all, I strongly recommend you to take a look if that payment system which you are using has some kind of support via SDK or API which you can use to complete that paying process, without using WebView.

On the other hand, if you are already decided to use WebView for that, you can use Navigating event from Xamarin.Forms WebView.

Navigating is an event that is raised when navigation starts.

Use it in C#:

yourWebView.Navigating += YourWebView_Navigating;

Or in XAML:

<WebView Navigating="YourWebView_Navigating" 
...

and in your code-behind you have the access to WebNavigatingEventArgs it:

void YourWebView_Navigating(object sender, WebNavigatingEventArgs e)
{
    if (e.Url // check the value of it
    // other code logic.

Using it you will get access to WebNavigatingEventArgs which holds a property called Url, with that info you can check the URL value and combine that with other logic in your app, navigate the user away or whatever you intended to do after successful payment.

Hope this was helpful for you, wishing you lots of luck with coding!

Upvotes: 1

Related Questions