stripe_payment_flutter 1.0.9

  • Readme
  • Changelog
  • Example
  • Installing
  • 76

pub package

stripe_payment_flutter #

Conveniently secure payments methods using Stripe.

Quick Glance #

  • This Flutter plugin is a straight port from tipsi-stripe plugin for React Native - we tried to keep the API as close as possible so the documentation applies this this plugin as well.
  • Collect chargable tokens from users' Card Input and Apple & Google Pay
  • For SCA compliant apps, setup payment intents for later confirmation.

Supported features: #

Native Pay -  & G #

  • canMakeNativePayPayments()
  • deviceSupportsNativePay()
  • potentiallyAvailableNativePayNetworks()
  • completeNativePayRequest()
  • cancelNativePayRequest()

Card Form #

  • paymentRequestWithCardForm()

Card Params Object #

  • createTokenWithCard()

Bank Account Params Object #

  • createTokenWithBankAccount()

Create Source Object With Params #

  • createSourceWithParams()

Apple Pay

Dependencies #

Android & iOS #

  • Create a Stripe account and project
  • Retrieve a publishable key from the Stripe dashboard

Stripe Dashboard

Android #

  • Requires AndroidX

Include support in android/gradle.properties

android.useAndroidX=true
android.enableJetifier=true

For proper setup also have a look at: https://github.com/jonasbark/stripe_payment_flutter/issues/88#issuecomment-553798157

Documentation #

As this plugin is a port from tipsi-stripe for React Native you may consult their documentation: https://github.com/tipsi/tipsi-stripe/tree/experimental-connect/website/docs-md It includes:

  • how to setup Google / Apple Pay
  • method documentations

[1.0.6] #

  • fix #97 (thanks @sandeep-at-airlift)
  • support Stripe Connected accounts (thanks @nicowernli)

[1.0.5] #

  • fix Android kotlin compilation problems (#72)
  • fix canMakeNativePayPayments request when it includes a list of networks (thanks @alexstuckey)

[1.0.4] #

  • fix Android configuration for Activities (#68)

[1.0.3] #

  • fix completeNativePayRequest + cancelNativePayRequest methods (thanks @jocelyngirard)

[1.0.2] #

  • cancelling paymentRequestWithCardForm will now return the Future on Android (fixes #55)
  • update minimum deployment target for iOS to 10.0

[1.0.0] #

the stripe_payment_flutter plugin is now ported from tipsi-stripe React Native plugin: https://github.com/tipsi/tipsi-stripe New features include:

Native Pay -  & G #

  • canMakeNativePayPayments()
  • deviceSupportsNativePay()
  • potentiallyAvailableNativePayNetworks()
  • completeNativePayRequest()
  • cancelNativePayRequest()

Card Form #

  • paymentRequestWithCardForm()

Card Params Object #

  • createTokenWithCard()

Bank Account Params Object #

  • createTokenWithBankAccount()

Create Source Object With Params #

  • createSourceWithParams()

[0.3.2] #

  • Add native iOS confirmation
  • readme update

[0.3.1] - 01.10.2019 #

  • Lowered iOS minimum deployment target to 9.0
  • removed dependency to stripe_native
  • removed useNativeReceipt method

[0.3.0] - 29.09.2019 #

Breaking change: Initialize the plugin has changed: StripePayment.setSettings(StripeSettings(publishableKey: "pk_test_"));

Added support for:

[0.2.1] - 27.08.2019 #

  • Update Stripe dependencies

[0.2.0] - 13.08.2019 #

  • BREAKING: This plugin now uses the Payment Intent to create a payment method instead of creating a Source.

[0.1.1] - 07.08.2019 #

  • Breaking: Minimum Android target is 19 (from 18)
  • Breaking: Minimum iOS target is 9.0 (from 8.0)
  • Update Android Stripe dependency to 10.2.1
  • Update iOS Stripe dependency to 16.0.3

[0.1.0] - 22.02.2019 #

  • Breaking change: use AndroidX

[0.0.9] - 07.02.2019 #

  • Updating Android Gradle

[0.0.8] - 08.12.2018 #

[0.0.7] - 03.12.2018 #

  • Increase Kotlin and Gradle versions

[0.0.6] - 16.05.2018 #

  • Dart 2 fixes

[0.0.5] - 20.03.2018 #

  • Compatible with Flutter SDK >=0.1.4 <2.0.0"

[0.0.4] - 29.01.2018 #

  • Initial release.

example/lib/main.dart

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:stripe_payment_flutter/stripe_payment.dart';
import 'dart:io';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Token _paymentToken;
  PaymentMethod _paymentMethod;
  String _error;
  final String _currentSecret = null; //set this yourself, e.g using curl
  PaymentIntentResult _paymentIntent;
  Source _source;

  ScrollController _controller = ScrollController();

  final CreditCard testCard = CreditCard(
    number: '4000002760003184',
    expMonth: 12,
    expYear: 21,
  );

  GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();

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

    StripePayment.setOptions(
        StripeOptions(publishableKey: "pk_test_aSaULNS8cJU6Tvo20VAXy6rp", merchantId: "Test", androidPayMode: 'test'));
  }

  void setError(dynamic error) {
    _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text(error.toString())));
    setState(() {
      _error = error.toString();
    });
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        key: _scaffoldKey,
        appBar: new AppBar(
          title: new Text('Plugin example app'),
          actions: <Widget>[
            IconButton(
              icon: Icon(Icons.clear),
              onPressed: () {
                setState(() {
                  _source = null;
                  _paymentIntent = null;
                  _paymentMethod = null;
                  _paymentToken = null;
                });
              },
            )
          ],
        ),
        body: ListView(
          controller: _controller,
          padding: const EdgeInsets.all(20),
          children: <Widget>[
            RaisedButton(
              child: Text("Create Source"),
              onPressed: () {
                StripePayment.createSourceWithParams(SourceParams(
                  type: 'ideal',
                  amount: 1099,
                  currency: 'eur',
                  returnURL: 'example://stripe-redirect',
                )).then((source) {
                  _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text('Received ${source.sourceId}')));
                  setState(() {
                    _source = source;
                  });
                }).catchError(setError);
              },
            ),
            Divider(),
            RaisedButton(
              child: Text("Create Token with Card Form"),
              onPressed: () {
                StripePayment.paymentRequestWithCardForm(CardFormPaymentRequest()).then((paymentMethod) {
                  _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text('Received ${paymentMethod.id}')));
                  setState(() {
                    _paymentMethod = paymentMethod;
                  });
                }).catchError(setError);
              },
            ),
            RaisedButton(
              child: Text("Create Token with Card"),
              onPressed: () {
                StripePayment.createTokenWithCard(
                  testCard,
                ).then((token) {
                  _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text('Received ${token.tokenId}')));
                  setState(() {
                    _paymentToken = token;
                  });
                }).catchError(setError);
              },
            ),
            Divider(),
            RaisedButton(
              child: Text("Create Payment Method with Card"),
              onPressed: () {
                StripePayment.createPaymentMethod(
                  PaymentMethodRequest(
                    card: testCard,
                  ),
                ).then((paymentMethod) {
                  _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text('Received ${paymentMethod.id}')));
                  setState(() {
                    _paymentMethod = paymentMethod;
                  });
                }).catchError(setError);
              },
            ),
            RaisedButton(
              child: Text("Create Payment Method with existing token"),
              onPressed: _paymentToken == null
                  ? null
                  : () {
                      StripePayment.createPaymentMethod(
                        PaymentMethodRequest(
                          card: CreditCard(
                            token: _paymentToken.tokenId,
                          ),
                        ),
                      ).then((paymentMethod) {
                        _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text('Received ${paymentMethod.id}')));
                        setState(() {
                          _paymentMethod = paymentMethod;
                        });
                      }).catchError(setError);
                    },
            ),
            Divider(),
            RaisedButton(
              child: Text("Confirm Payment Intent"),
              onPressed: _paymentMethod == null || _currentSecret == null
                  ? null
                  : () {
                      StripePayment.confirmPaymentIntent(
                        PaymentIntent(
                          clientSecret: _currentSecret,
                          paymentMethodId: _paymentMethod.id,
                        ),
                      ).then((paymentIntent) {
                        _scaffoldKey.currentState
                            .showSnackBar(SnackBar(content: Text('Received ${paymentIntent.paymentIntentId}')));
                        setState(() {
                          _paymentIntent = paymentIntent;
                        });
                      }).catchError(setError);
                    },
            ),
            RaisedButton(
              child: Text("Authenticate Payment Intent"),
              onPressed: _currentSecret == null
                  ? null
                  : () {
                      StripePayment.authenticatePaymentIntent(clientSecret: _currentSecret).then((paymentIntent) {
                        _scaffoldKey.currentState
                            .showSnackBar(SnackBar(content: Text('Received ${paymentIntent.paymentIntentId}')));
                        setState(() {
                          _paymentIntent = paymentIntent;
                        });
                      }).catchError(setError);
                    },
            ),
            Divider(),
            RaisedButton(
              child: Text("Native payment"),
              onPressed: () {
                if (Platform.isIOS) {
                  _controller.jumpTo(450);
                }
                StripePayment.paymentRequestWithNativePay(
                  androidPayOptions: AndroidPayPaymentRequest(
                    totalPrice: "1.20",
                    currencyCode: "EUR",
                  ),
                  applePayOptions: ApplePayPaymentOptions(
                    countryCode: 'DE',
                    currencyCode: 'EUR',
                    items: [
                      ApplePayItem(
                        label: 'Test',
                        amount: '13',
                      )
                    ],
                  ),
                ).then((token) {
                  setState(() {
                    _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text('Received ${token.tokenId}')));
                    _paymentToken = token;
                  });
                }).catchError(setError);
              },
            ),
            RaisedButton(
              child: Text("Complete Native Payment"),
              onPressed: () {
                StripePayment.completeNativePayRequest().then((_) {
                  _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text('Completed successfully')));
                }).catchError(setError);
              },
            ),
            Divider(),
            Text('Current source:'),
            Text(
              JsonEncoder.withIndent('  ').convert(_source?.toJson() ?? {}),
              style: TextStyle(fontFamily: "Monospace"),
            ),
            Divider(),
            Text('Current token:'),
            Text(
              JsonEncoder.withIndent('  ').convert(_paymentToken?.toJson() ?? {}),
              style: TextStyle(fontFamily: "Monospace"),
            ),
            Divider(),
            Text('Current payment method:'),
            Text(
              JsonEncoder.withIndent('  ').convert(_paymentMethod?.toJson() ?? {}),
              style: TextStyle(fontFamily: "Monospace"),
            ),
            Divider(),
            Text('Current payment intent:'),
            Text(
              JsonEncoder.withIndent('  ').convert(_paymentIntent?.toJson() ?? {}),
              style: TextStyle(fontFamily: "Monospace"),
            ),
            Divider(),
            Text('Current error: $_error'),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  stripe_payment_flutter: ^1.0.9

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_payment_flutter/stripe_payment.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
52
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
76
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:stripe_payment_flutter/stripe_payment.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:stripe_payment_flutter/stripe_payment.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:stripe_payment_flutter/stripe_payment.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:stripe_payment_flutter/stripe_payment.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • stripe_payment_flutter that is a package requiring null.

Health suggestions

Format lib/src/android_pay_payment_request.dart.

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

Format lib/src/apple_pay_payment_request.dart.

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

Format lib/src/card_form_payment_request.dart.

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

Fix additional 7 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/error_codes.dart (Run flutter format to format lib/src/error_codes.dart.)
  • lib/src/payment_intent.dart (Run flutter format to format lib/src/payment_intent.dart.)
  • lib/src/payment_method.dart (Run flutter format to format lib/src/payment_method.dart.)
  • lib/src/source.dart (Run flutter format to format lib/src/source.dart.)
  • lib/src/source_params.dart (Run flutter format to format lib/src/source_params.dart.)
  • lib/src/stripe_payment.dart (Run flutter format to format lib/src/stripe_payment.dart.)
  • lib/src/token.dart (Run flutter format to format lib/src/token.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety