Flutter Integrate Paypal Buttons with WebView
So after many, many hours of googling and looking at alternatives, I got the idea to NOT use a WebView at all. Rather than using the webview_flutter plugin, which is limited in this case, I am now using url_launcher and uni_links.
I first call url_launcher
to open a browser, with an HTML page that is hosted somewhere on our domains. This html page was built to show only from the mobile app.
With uni_links
, when the component didChangeDependencies
(of course after configuring the links in Info.plist
and AndroidManifest.xml
), I initialise them like this:
Future<Null> initUniLinks() async { _sub = getUriLinksStream().listen((Uri uri) async { //Do something with uri... for example... Map<String, String> queryParameters = uri.queryParameters; String action = queryParameters["action"]; switch (action) { case "onSuccess": //Do something... break; });}
So essentially what is happening, is I am opening a proper browser window. Then using normal HTML and Javascript, I still detect the PayPal onApprove()
function etc. However, then the functions execute, I open the uni link
, which results in opening the application where we left off.
This is a good alternative if WebView is giving you issues. Much more config, but it works just fine for my case.
I'm still open to any other proposals :) - even though I have moved on from this - will be interesting to find out more!
The request you are sending is comming from Origin null as stated by the logs.Meaning the origin of the request is coming from a local page, instead of a trusted origin that needs to be defined in your paypal account.Paypal's api should be implemented on a server that would serve this webpage youThe endpoint on paypal does not accept that.Read more here: Paypal Access-Control-Allow-Origin