Richie C
Richie C

Reputation: 1

In Flutter - How do I push user to a "Thank-you" page in the app after returning from PayPal completed transaction page in web browser

My flutter app requires payments to be made via PayPal in a web browser outside the app. Once the payment is completed the user will be returned to the app and a thank you page should be pushed.

I'm using _launchURL to initiate the web browser from within the app and the following example PayPal url to define the payment.

https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&[email protected]&currency_code=USD&amount=123.99&return=http://example.com&item_name=Document+Studio

Using SystemChannels.lifecycle.setMessageHandler I should be able to test when the app returns from the web browser (AppLifecycleState.resumed). But how do I capture the return URL (http://example.com) or some other value from the web browser to confirm that it has come from the transaction complete page and should be pushed to the apps thank-you page?

Is there a way to pass a value from the browser back to the app?

My other thought was to use Uni_links to "Deep Link" the thank you page within the app and have that as the return url parameter in the PayPal url?

I'm a bit lost with the solution and am only new to flutter, so any advice/guidance would be appreciated.

Upvotes: 0

Views: 1348

Answers (1)

E.Bradford
E.Bradford

Reputation: 813

I am assuming you are using this _launchURL. To do what you desire create a ThankYou class and call it in the following manner. You might want to check resultingValue prior to calling your ThankYou screen. I haven't used the url functionality enough to know what it returns, if anything. It might be null, an int of some sort, such as 404 url not found, perhaps a String?

import 'ThankYou.dart';

_launchURL() async {
  const url = 'https://flutter.io';
  if (await canLaunch(url)) {
        await launch(url).then((resultingValue){
      Navigator.push(
          context,
          MaterialPageRoute(
              builder: (context) => ThankYou()));

    });

  } else {
    throw 'Could not launch $url';
  }
}

Upvotes: 0

Related Questions