stripe_sdk 2.3.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 73

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 #

The library offers two main API surfaces:

  • Stripe for generic, non-customer specific APIs, using publishable keys.
  • CustomerSession for customer-specific APIs, using stripe ephemeral keys.

Planned features #

  • Improve UI widgets
  • Support for additional APIs
  • Offer complete UI flow for adding payment method
  • Offer complete UI flow for checout

Supported APIs #

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

Overview #

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

The library API is split into three separate classes, described below.

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();
CardForm(card:card, formKey: formKey);
onPressed: () async {
                if (formKey.currentState.validate()) {


The library offers complete support for SCA on iOS and Android. 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.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.3.0

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 Oct 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/src/model/model_utils.dart.

Run flutter format to format lib/src/model/model_utils.dart.

Format lib/src/text_utils.dart.

Run flutter format to format lib/src/text_utils.dart.

Format lib/src/widgets/card_number_form_field.dart.

Run flutter format to format lib/src/widgets/card_number_form_field.dart.

Format lib/src/widgets/masked_text_controller.dart.

Run flutter format to format lib/src/widgets/masked_text_controller.dart.


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+2
uni_links ^0.2.0 0.2.0
url_launcher ^5.1.2 5.1.6
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.11 1.14.12
http_parser 3.1.3
meta 1.1.7
path 1.6.4
pedantic 1.8.0+1
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies