6

I am integrating paytabs payment gateway in my flutter application. It opens a payment page in in app browser. When the transaction is completed, it redirects to a return_url. I want to redirect back to my app, so that I can do something after the payment has been processed.

How can this be accomplished?

Ali Haider
  • 374
  • 2
  • 3
  • 14
  • How about you use deep link? – KuKu Oct 12 '20 at 10:45
  • Try to use WebView inside an app, not to open separate browser. And I think you need backend which will process retutn_url. As a variand you must work with paytabs mobile api . And look to https://stackoverflow.com/questions/59605005/paytabs-payment-integration-using-dart-flutter-web-and-api – rstrelba Oct 12 '20 at 11:18
  • i am not sure about this,this plugin can open web url within app,it might help`https://pub.dev/packages/flutter_inappwebview`@Ali Haider – Abhijith Oct 12 '20 at 14:22

1 Answers1

6

I found a solution and it worked for me!

InAppWebView

In flutter to open the paytabs transaction page. When the transaction is successful, it redirects me to a return_url. InAppWebView has a method

onLoadStart: (InAppWebViewController controller, String url)

In this method, I checked if the returl_url == url and redirected to my app and closed the InAppWebView accordingly.

onLoadStart: (InAppWebViewController controller, String url) {
          setState(() {
            _con.url = url;
          });
          if (url == "return_url") {
            //close the webview
            _con.webView.goBack();

            //navigate to the desired screen with arguments
            Navigator.of(context).pushReplacementNamed('/OrderSuccess',
                arguments:
                    new RouteArgument(param: 'Credit Card (Paytabs)'));
          }
        },
Ali Haider
  • 374
  • 2
  • 3
  • 14
  • 2
    this answer works fine with android, but it wont work for IOS. You need to handle the **onLoadStop** method as well to support IOS – Nifal Nizar Feb 14 '22 at 04:25