stripe_sdk 2.4.2

Flutter Stripe SDK #

A native dart package for Stripe. There are various other flutter plugins that wrap existing Stripe libraries, but this package uses a different approach. It does not wrap existing Stripe libraries, but instead accesses the Stripe API directly.

See examples for additional examples.

Features #

  • Supports all types of SCA, including 3DS, 3DS2, BankID and others.
  • Handle payments with complete SCA support.
  • Add, remove and update payment methods, sources and cards, optionally with SCA.
  • Manage customer information.
  • Create all types of Stripe tokens.
  • Forms, widgets and utilities to use directly, or create your own UI!

Supported APIs #

  • PaymentIntent, with SCA
  • SetupIntent, with SCA
  • PaymentMethod
  • Customer
  • Cards
  • Sources
  • Tokens

Planned features #

  • Add additional UI widgets
  • Support for additional APIs
  • Offer complete UI flow for adding payment method
  • Offer complete UI flow for checkout

Overview #

  • The return type for each function is Future<Map<String, dynamic>>, where the value depends on the stripe API version.

The library has three classes to access the Stripe API:

  • Stripe for generic, non-customer specific APIs, using publishable keys.
  • CustomerSession for customer-specific APIs, using stripe ephemeral keys.
  • StripeApi enables raw REST calls against the Stripe API.

Stripe #

Aims to provide high-level functionality similar to the official mobile Stripe SDKs.

CustomerSession #

Requires a Stripe ephemeral key.

Provides functionality similar to CustomerSession in the Stripe Android SDK.

StripeApi #

Provides basic low-level methods to access the Stripe REST API.

  • Limited to the APIs that can be used with a public key or ephemeral key.
  • Library methods map to a Stripe API call with the same name.
  • Additional parameters can be provided as an optional argument.

Stripe and CustomerSession use this internally.

Initialization #

All classes offer a singleton instance that can be initated by calling the init(...) methods and then accessed through .instance. Regular instances can also be created using the constructor, which allows them to be managed by e.g. dependency injection instead.

Stripe #

// or, to manage your own instances
final stripe = Stripe("pk_xxx);

CustomerSession #

CustomerSession.init((apiVersion) => server.getEphemeralKeyFromServer(apiVersion));
// or, to manage your own instances
final session = CustomerSession((apiVersion) => server.getEphemeralKeyFromServer(apiVersion))

StripeApi #

// or, to manage your own instances
final stripeApi = StripeApi("pk_xxx);

UI #

Use CardForm to add or edit credit card details, or build your own form using the pre-built FormFields.

final formKey = GlobalKey<FormState>();
final card = StripeCard();

final form = CardForm(card:card, formKey: formKey);
onPressed: () async {
                if (formKey.currentState.validate()) {


The library offers complete support for SCA on iOS and Android. It handles all types of SCA, including 3DS, 3DS2, BankID and others. It handles SCA by launching the authentication flow in a web browser, and returns the result to the app.

final clientSecret = await server.createPaymentIntent(Stripe.getReturnUrl());
final paymentIntent = await Stripe.instance.confirmPayment(clientSecret, "pm_card_visa");

Android #

You need to declare this intent filter in android/app/src/main/AndroidManifest.xml:

<manifest ...>
  <!-- ... other tags -->
  <application ...>
    <activity ...>
      <!-- ... other tags -->

      <!-- Deep Links -->
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
          android:host="" />


For iOS you need to declare the scheme in ios/Runner/Info.plist (or through Xcode's Target Info editor, under URL Types):

<!-- ... other tags -->
    <!-- ... other tags -->
    <!-- ... other tags -->

Stripe SDK Changelog #

2.4.2 #

  • Allow custom form field error text
  • Fix bug where card number input field would allow more than 16 digits

2.4.1 #

  • Add support for custom input decorators on card form and form fields

2.4.0 #

  • Minor breaking change: Split package into two separate sub-libraries:

    • stripe_sdk: API related functionality
    • stripe_sdk_ui: UI widgets and utilities
  • Replaced ListView with Column inside the CardForm

  • Updated dependencies

2.3.0 #

  • Add CardForm widget, which can be used to add or edit credit cards.
    • Complete validation for card number, expiration date and CVC
    • Individual FormField widgets can be used to create a custom form
  • Fix bug in Stripe.authenticatePayment

2.2.0 #

  • Add support for connected accounts
    • Add optional constructor parameter stripeAccount for all APIs

2.1.1 #

  • Remove unused stripeAccount property on StripeApi

2.1.0 #

  • Add Stripe.confirmSetupIntentWithPaymentMethod

2.0.0 #

  • Rewrite of internal API
  • Fixed several issues and bugs
  • Restructured public API with breaking changes
    • Split Stripe into StripeApi and Stripe
    • SCA related features moved to Stripe
    • Moved basic Stripe API requests to StripeApi

See README and examples for further details details.

1.1.1 #

  • Misc minor updates and fixes

1.1.0 #

  • Complete support for SetupIntent with SCA
  • Fix bug with confirmPayment
  • Internal refactoring

1.0.1 #

  • Support multiple simultaneous authentication flows
  • Improve documentation and examples
  • Allow specifying apiVersion for CustomerSession
  • Allow multiple instances of Stripe and CustomerSession

1.0.0+1 #

  • Improve examples

1.0.0 #

  • Improve API for SCA-related features
  • Improve examples

0.0.2 #

  • Remove typed models
  • Add some support for payment intents
  • Complete support for payment methods
  • Complete support for tokens
  • Add examples
  • Major cleanup

0.0.1+2 #

  • Add analysis_options.yaml
  • Fix dartanalyzer issues
  • Fix other misc packaging issues

0.0.1+1 #

  • Initial release


import 'dart:async';

import 'package:stripe_sdk/stripe_sdk.dart';

const publishableKey = "my-key";

/// StripeApi provides direct access to Stripe REST API
exampleSetupStripeApi() async {
  // See Stripe API documentation for details
  final cardData = {};
  await StripeApi.instance.createPaymentMethod(cardData);

/// CustomerSession provides access to customer specific APIs
exampleSetupSession() {
      (apiVersion) => _fetchEphemeralKeyFromMyServer(apiVersion));

Future<String> _fetchEphemeralKeyFromMyServer(String apiVersion) {
  // Send the apiVersion to your server, create the key and return the raw http body.
  return Future.value("raw-http-body");

/// This method supports the default payment flow as documented by Stripe.
exampleConfirmPayment() async {
  final paymentIntentClientSecret =
      await _createPaymentIntent(Stripe.getReturnUrl());
  final paymentIntent = await Stripe.instance
      .confirmPayment(paymentIntentClientSecret, "pm-paymentMethod");
  if (paymentIntent['status'] == 'success') {
    // Confirmation successfull
  } else {
    // Handle other states

/// Create payment intent and return the client secret.
/// The `return_url` must be set on the PaymentIntent.
Future<String> _createPaymentIntent(String returnUrl) {
  return Future.value("client_secret");

/// This method supports the manual payment flow as documented by Stripe.
exampleAuthenticatePayment() async {
  final paymentIntentClientSecret =
      await _createAndConfirmPaymentIntent(Stripe.getReturnUrl());
  final paymentIntent =
      await Stripe.instance.authenticatePayment(paymentIntentClientSecret);
  if (paymentIntent['status'] == "success") {
    // Authentication was successfull
  } else {
    // See stripe documentation for details on other possible statuses

/// Create and confirm a payment intent on your server.
/// The `returnUrl` must be set on the PaymentIntent by your server.
/// Return the payment intent client secret.
Future<String> _createAndConfirmPaymentIntent(String returnUrl) {
  return Future.value("client_secret");

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  stripe_sdk: ^2.4.2

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:stripe_sdk/stripe_sdk.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 21, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
http ^0.12.0 0.12.0+4
mask_text_input_formatter ^1.0.5 1.0.6
uni_links ^0.2.0 0.2.0
url_launcher ^5.1.2 5.4.2
Transitive dependencies
async 2.4.0
charcode 1.1.3
collection 1.14.11 1.14.12
flutter_web_plugins 0.0.0
http_parser 3.1.3
meta 1.1.8
path 1.6.4
pedantic 1.9.0
plugin_platform_interface 1.0.2
sky_engine 0.0.99
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
url_launcher_macos 0.0.1+4
url_launcher_platform_interface 1.0.6
url_launcher_web 0.1.1+1
vector_math 2.0.8
Dev dependencies