Stripe Financial connections (only available for us bank accounts)

Route payments between multiple parties#

To learn more about how it works read: Official Stripe connect docs.

1. Create#

First, you need a Stripe account. Register now.

Server-side#

This integration requires endpoints on your server that talk to the Stripe API. Use one official libraries for access to the Stripe API from your server. Follow the steps to create an Financial account session here.

Client-side#

The Flutter SDK is open source, fully documented.

To install the SDK, follow these steps:

  • Run the command flutter pub add flutter_stripe
  • This will add a line like this to your project's pubspec.yaml with the latest package version

For details on the latest SDK release and past versions, see the Releases page on GitHub. To receive notifications when a new release is published, watch releases for the repository.

When your app starts, configure the SDK with your Stripe publishable key so that it can make requests to the Stripe API.

void main() async {
  Stripe.publishableKey = stripePublishableKey;
  runApp(const App());
}

Use your test mode keys while you test and develop, and your live mode keys when you publish your app.

2. Create an account holder. [Server Side]#

To attach data to an account holder you must first create one.
For detailed api instructions checkout the official docs.

3. Create a Financial connections session [Server Side]#

Before you can retrieve data from a user's bank account through Stripe financial connections, your user must authenticate their account with the authentication flow.

Click here to learn more how to setup a session.

4. Collect a financials account [Client Side]#

On the client side you need to receive the sessionsecret in order to start the authorisation flow on the mobile. The example code looks like this:

 Future<void> _collectAccount(BuildContext context) async {
    // Precondition:
    // 1. Make sure to create a financial connection session on the backend and
    // forward the client secret of the session to the app.
    final result = await retrieveSessionClientSecret();
    final clientSecret = await result['clientSecret'];

    // 2. use the client secret to confirm the payment and handle the result.
    try {
      final result = await Stripe.instance.collectFinancialConnectionsAccounts(
        clientSecret: clientSecret,
      );

      setState(() {
        response = result.toString();
      });
    } on Exception catch (e) {
      if (e is StripeException) {
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(
            content: Text('Error from Stripe: ${e.error.localizedMessage}'),
          ),
        );
      } else {
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(
            content: Text('Unforeseen error: ${e}'),
          ),
        );
      }
    }
  }
  
  @override
  Widget build(BuildContext context) {
    return ExampleScaffold(
      title: 'Financial connections',
      tags: ['Financial connections'],
      padding: EdgeInsets.all(16),
      children: [
        LoadingButton(
          onPressed: () async {
            await _collectAccount(context);
          },
          text: 'Collect financial account',
        ),
        Divider(),
        SizedBox(height: 20),
        ResponseCard(response: response),
      ],
    );
  }

The collectFinancialConnectionsAccounts method from the Flutter Stripe sdk returns a future that completes when the users completes the modal authentication flow. The result is in case if success a FinancialConnectionSessionResult or in case of failure (or cancellation) a StripeException.