Flutter

Before proceeding, ensure that you have set up a partner account with us. If you have not yet done so, please follow this guide to create a partner account in less than 30 seconds and copy your Staging API KEY.

1. iOS Caveat

In order for plugin to work correctly, you need to add new key to ios/Runner/Info.plist

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSAllowsArbitraryLoadsInWebContent</key>
    <true/>
</dict>

NSAllowsArbitraryLoadsInWebContent is for iOS 10+ and NSAllowsArbitraryLoads for iOS 9.

2. Usage

Launch WebView with Flutter

class _MyAppState extends State<MyApp> {
  String _transactionStatus= '';
  final _transfiConnectPlugin = TransfiConnect();

  @override
  void initState() {
    super.initState();
  }

  Future<void> closeWebView() async {
    await _transfiConnectPlugin.closeWebView();
  }

  Future<void> openWebView() async {
   String status;
   const String url = "https://buy.transfi.com/?apiKey=[YOUR_API_KEY][QUERY_PARAMETERS]";
    try {
      status =
          await _transfiConnectPlugin.openWebView(url) ?? 'Unknown';
          switch(status){
            case "success":
            //handle success
            break;
            case "error":
            //handle error
            break;
            default:
            //handle error
            break;
          }

    } on PlatformException {
      status = 'Something went wrong';
    }
    if (!mounted) return;
    setState(() {
      _transactionStatus = status;
    });
  }

 @override
 Widget build(BuildContext context) {
   return
     MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              ElevatedButton(
                onPressed: openWebView,
                child: const Text('Open transfi'),
              ),
              Text(_transactionStatus),
            ],
          ),
        ),
      ),
    );
  }
}

2. Flutter package

You can check out Flutter Transfi repo here.