flutter_payments_stripe_sdk 1.0.7

  • Readme
  • Changelog
  • Example
  • Installing
  • 71

Stripe Flutter SDK #

The Stripe Flutter SDK makes it quick and easy to build an excellent payment experience in your Flutter app. We provide powerful and customizable UI screens and elements that can be used out-of-the-box to collect your users' payment details.

Get started with Stripe 📚 integration guides and example projects, or 📘 browse the SDK reference.

Features #

Simplified Security: We make it simple for you to collect sensitive data such as credit card numbers and remain PCI compliant. This means the sensitive data is sent directly to Stripe instead of passing through your server. For more information, see our Integration Security Guide.

SCA-Ready: The SDK automatically performs native 3D Secure authentication if needed to comply with Strong Customer Authentication regulation in Europe.

Stripe API: If you want to use low-level APIs, use our Stripe Dart.

Native UI: We provide native screens and elements to collect payment and shipping details. For example, PaymentCardTextField is a Widget that collects and validates card details.

Contributing #

We welcome contributions of any kind including new features, bug fixes, and documentation improvements. Please first open an issue describing what you want to build if it is a major change so that we can discuss how to move forward. Otherwise, go ahead and open a pull request for minor changes such as typo fixes and one liners.

[1.0.7] - 31/05/2020 #

  • returnCardImage utils added
  • AssetImage get brandImage added inside StripeCard
  • replace brand string with CardBrand enum

[1.0.6] - 30/05/2020 #

  • Bug fix

[1.0.5] - 30/05/2020 #

  • Fixed an issue with confirmSetupIntent that prevented the creation of the payment method

[1.0.4] - 29/05/2020 #

  • Bug fix

[1.0.3] - 29/05/2020 #

  • Update readme

[1.0.2] - 29/05/2020 #

  • Update description

[1.0.1] - 27/05/2020 #

  • Bug fix

[1.0.0] - 27/05/2020 #

  • Initial Release

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_payments_stripe_sdk/flutter_payments_stripe_sdk.dart';
import 'dart:convert' show json;
import 'package:http/http.dart' as http;
import 'package:flutter_payments_stripe_sdkexample/separator_line.dart';
import 'dart:convert' as convert;

import 'package:flutter_payments_stripe_sdkexample/text_icon.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Stripe Flutter SDK Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var rows = ["Create a payment intent", "Create a setup intent"];
  //TODO: INSERT YOUR API KEY
  var stripe = Stripe("pk_test_...");
  var clientSecret = "";
  var setupIntentClientSecret = "";
  //TODO: INSERT YOUR BACKED URL
  var backendUrl = "";
  //TODO: INSERT A CUSTOMER ID
  var customerID = "";
  //
  var testPaymentMethodID = "pm_card_threeDSecure2Required";

  startCheckout() async {
    var url = "$backendUrl/stripe/payment_intents/create";
    var body = {
      "params": {"amount": "200", "currency": "eur", "customer": customerID}
    };
    var response = await http.post(url,
        headers: {'Content-Type': 'application/json'},
        body: convert.json.encode(body));
    var j = json.decode(response.body);
    if (j["data"] != null && j["data"]["clientSecret"] != null) {
      clientSecret = j["data"]["clientSecret"];
      print(clientSecret);
    } else {
      print("SOMETHING WRONG");
    }
  }

  startSetupIntent() async {
    var url = "$backendUrl/stripe/setup_intents/create";
    var body = {
      "params": {"customer": customerID}
    };
    var response = await http.post(url,
        headers: {'Content-Type': 'application/json'},
        body: convert.json.encode(body));
    var j = json.decode(response.body);
    if (j["data"] != null && j["data"]["clientSecret"] != null) {
      setupIntentClientSecret = j["data"]["clientSecret"];
      print(setupIntentClientSecret);
    } else {
      print("SOMETHING WRONG");
    }
  }

  performAction(String item) async {
    if (backendUrl.isEmpty) {
      print("Insert a backed url");
      return;
    }
    if (item == "Create a payment intent") {
      await startCheckout();
      var res = await stripe.paymentIntents.confirmPaymentIntent(clientSecret,
          data: ConfirmPaymentIntentRequest(
              paymentMethod: testPaymentMethodID,
              returnUrl: stripe.getReturnUrlForSca(),
              useStripeSdk: false));
      if (res.runtimeType == StripeError) {
        print((res as StripeError).toJson());
      } else if (res.runtimeType == PaymentIntent) {
        print((res as PaymentIntent).toJson());
      }
    } else if (item == "Create a setup intent") {
      await startSetupIntent();
      var res = await stripe.setupIntents.confirmSetupIntent(
          setupIntentClientSecret,
          data: ConfirmSetupIntentRequest(
              paymentMethod: PaymentMethodData(
                type: PaymentMethodType.card,
                card: CardMethod(
                  cvc: "555",
                  expMonth: 12,
                  expYear: 24,
                  number: "4242424242424242"
                )
              ),
              useStripeSdk: false,
              returnUrl: stripe.getReturnUrlForSca()));
      if (res.runtimeType == StripeError) {
        print((res as StripeError).toJson());
      } else if (res.runtimeType == SetupIntent) {
        print((res as SetupIntent).toJson());
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Stripe Flutter SDK Example'),
      ),
      body: Padding(
          padding: EdgeInsets.all(0.0),
          child: ListView.separated(
            itemBuilder: (context, index) {
              if (index == rows.length) {
                return Padding(
                  padding: const EdgeInsets.fromLTRB(0, 20, 0, 20),
                  child: PaymentCardTextField(onCardChanged: (card) {
                    print(card.toPaymentMethod());
                  }),
                );
              }
              var item = rows[index];
              return TextIcon(
                title: item,
                shapedSelectedBackground: false,
                tapHandler: (d) {
                  performAction(item);
                },
              );
            },
            separatorBuilder: (context, index) {
              return SeparatorLine(margin: EdgeInsets.fromLTRB(20, 0, 0, 0));
            },
            itemCount: rows.length + 1,
          )),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_payments_stripe_sdk: ^1.0.7

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:flutter_payments_stripe_sdk/flutter_payments_stripe_sdk.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
43
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]
71
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:flutter_payments_stripe_sdk/flutter_payments_stripe_sdk.dart, package:flutter_payments_stripe_sdk/src/api/stripe.dart, package:uni_links/uni_links.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:flutter_payments_stripe_sdk/flutter_payments_stripe_sdk.dart, package:flutter_payments_stripe_sdk/src/api/stripe.dart, package:uni_links/uni_links.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:flutter_payments_stripe_sdk/flutter_payments_stripe_sdk.dart, package:flutter_payments_stripe_sdk/src/api/stripe.dart, package:uni_links/uni_links.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:flutter_payments_stripe_sdk/flutter_payments_stripe_sdk.dart, package:flutter_payments_stripe_sdk/src/api/stripe.dart, package:url_launcher/url_launcher.dart] that declares support for platforms: android, ios, linux, macos, web

Package not compatible with SDK dart

because of import path [flutter_payments_stripe_sdk] that is in a package requiring null.

Health issues and suggestions

Document public APIs. (-0.25 points)

1025 out of 1052 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/src/api/model/card.dart.

Run flutter format to format lib/src/api/model/card.dart.

Format lib/src/api/resources/setup_intents.dart.

Run flutter format to format lib/src/api/resources/setup_intents.dart.

Format lib/src/ui/components/payment_card_text_field.dart.

Run flutter format to format lib/src/ui/components/payment_card_text_field.dart.

Fix additional 3 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/ui/model/card.dart (Run flutter format to format lib/src/ui/model/card.dart.)
  • lib/src/utils/card_utils.dart (Run flutter format to format lib/src/utils/card_utils.dart.)
  • lib/src/utils/image_utils.dart (Run flutter format to format lib/src/utils/image_utils.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
http ^0.12.1 0.12.1
json_annotation ^3.0.0 3.0.1
uni_links ^0.4.0 0.4.0
url_launcher ^5.4.7 5.5.0
Transitive dependencies
charcode 1.1.3
collection 1.14.12 1.14.13
flutter_web_plugins 0.0.0
http_parser 3.1.4
meta 1.1.8 1.2.1
path 1.7.0
pedantic 1.9.0 1.9.1
platform_detect 1.4.0
plugin_platform_interface 1.0.2
pub_semver 1.4.4
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
url_launcher_linux 0.0.1+1
url_launcher_macos 0.0.1+7
url_launcher_platform_interface 1.0.7
url_launcher_web 0.1.2
vector_math 2.0.8
Dev dependencies
build_runner ^1.0.0
flutter_test
json_serializable ^3.3.0