A native dart package for Stripe

Overview

pub package

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.

Flutter support:

  • iOS
  • Android
  • Web

See example/main.dart for additional short examples.

See https://github.com/ezet/stripe-sdk/tree/master/example for a complete demo application, with a working example backend.

Demo backend: https://github.com/ezet/stripe-sdk-demo-api

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!

Experimental

  • Managed UI flow for adding payment methods with SCA (using SetupIntent).

Supported APIs

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

Planned features

  • Offer managed UI flow for checkout

Demo application

There is a complete demo application available at https://github.com/ezet/stripe-sdk/tree/master/example/app.

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 initiated 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

Stripe.init('pk_xxx');
// or, to manage your own instance, or multiple instances
final stripe = Stripe('pk_xxx');

CustomerSession

The function that retrieves the ephemeral key must return the JSON response as a plain string.

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

StripeApi

StripeApi.init('pk_xxx');
// 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: () {
  if (formKey.currentState.validate()) {
    formKey.currentState.save();
  }
}

SCA/PSD2

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. The returnUrlForSca parameter must match the configuration of your AndroidManifest.xml and Info.plist as shown in the next steps.

Stripe.init('pk_xxx', returnUrlForSca: 'stripesdk://3ds.stripesdk.io');
final clientSecret = await server.createPaymentIntent(Stripe.instance.getReturnUrlForSca());
final paymentIntent = await Stripe.instance.confirmPayment(clientSecret, paymentMethodId: 'pm_card_visa');

Android

You need to declare the following intent filter in android/app/src/main/AndroidManifest.xml. This example is for the url stripesdk://3ds.stripesdk.io:

<manifest ...>
  <!-- ... other tags -->
  <application ...>
    <activity ...>
    
      <!-- The launchMode should be singleTop or singleTask,
        to avoid launching a new instance of the app when SCA has been completed. -->
      android:launchMode="singleTop"

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

      <!-- Deep Links -->
      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
          android:scheme="stripesdk"
          android:host="3ds.stripesdk.io" />
      </intent-filter>
    </activity>
  </application>
</manifest>

IOS

For iOS you need to declare the scheme in ios/Runner/Info.plist (or through Xcode's Target Info editor, under URL Types). This example is for the url stripesdk://3ds.stripesdk.io:

<!-- ... other tags -->
<plist>
    <dict>
    <!-- ... other tags -->
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>3ds.stripesdk.io</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>stripesdk</string>
        </array>
        </dict>
    </array>
    <!-- ... other tags -->
    </dict>
</plist>

Experimental

Experimental features are marked as deprecated and the API is subject to change until it is deemed stable. Feel free to use these features but be aware that breaking changes might be introduced in minor updates.

Add Payment Method

Use AddPaymentMethodScreen.withSetupIntent(...) to launch a managed UI flow for adding a payment method. This will also handle SCA if required.

Payment Methods

PaymentMethodsScreen offers a prebuilt UI that can:

  • List all current payment methods
  • Add new payment methods, using setup intents
  • Delete existing payment methods

Additional examples

Glappen

This is a complete application, with a mobile client and a backend API. Documentation is lacking, but it can serve as an example for more advanced use.

App: https://github.com/ezet/glappen-client Backend: https://github.com/ezet/glappen-firebase-api

You might also like...

Animation package for Flutter, inspired by Animate.css

Animation package for Flutter, inspired by Animate.css

animator Enables you to create stunning flutter animations, faster, efficient and with less code. Null safety: For null safety please use flutter_anim

Dec 6, 2022

☀️ A Flutter package for some material design app intro screens with some cool animations.

☀️ A Flutter package for some material design app intro screens with some cool animations.

IntroViews is inspired by Paper Onboarding and developed with love from scratch. Checkout our fully responsive live example app. Table of contents Fea

Dec 30, 2022

A package for flip panel with built-in animation

A package for flip panel with built-in animation

Flip Panel A package for flip panel with built-in animation How to use import 'package:flip_panel/flip_panel.dart'; Create a flip panel from iterable

Dec 29, 2022

A light weight package for flutter apps, that easily shows a splash screen with a nice fade animation.

Animated Splash Screen Using the package Get the library environment: sdk: "=2.1.0 3.0.0" Add dependency in pubspec.yaml dependencies: animated_

Oct 6, 2022

A flutter package which will help you to generate pin code fields with beautiful design and animations

A flutter package which will help you to generate pin code fields with beautiful design and animations

A flutter package which will help you to generate pin code fields with beautiful design and animations. Can be useful for OTP or pin code inputs 🤓 🤓

Dec 23, 2022

Page Transition package for multiple navigation types

f_page_transition A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to get you st

Oct 29, 2021

This package helps you daily usable function and ready-made Widgets with ease.

This package helps you daily usable function and ready-made Widgets with ease.

Show some love and like to support the project Documentation API Docs are available. Platform Support Android iOS MacOS Web Linux Windows ✔️ ✔️ ✔️ ✔️

Dec 23, 2022

A set of transition patterns within the animations package using flutter.

A set of transition patterns within the animations package using flutter.

Flutter Motion Transitions A fultter app to demonstrate Material motion system. Material Motion System The four main Material transition patterns are

Oct 13, 2022

Change Application's name, package name, icon and Splash in one shot by one Command on Android & IOS

Change Application's name, package name, icon and Splash in one shot by one Command on Android & IOS

Change Application's name, package name, icon and Splash in one shot by one Command on Android & IOS. Installing dart pub global activate before_publi

Oct 27, 2022
Owner
Bash_
Bash_
🔔 A flutter package to create cool and beautiful text animations. [Flutter Favorite Package]

Animated Text Kit A flutter package which contains a collection of some cool and awesome text animations. Recommended package for text animations in C

Ayush Agarwal 1.4k Jan 6, 2023
Render After Effects animations natively on Flutter. This package is a pure Dart implementation of a Lottie player.

Lottie for Flutter Lottie is a mobile library for Android and iOS that parses Adobe After Effects animations exported as json with Bodymovin and rende

Xavier H. 894 Jan 2, 2023
Flutter package for creating awesome animations.

?? Simple Animations Simple Animations is a powerful package to create beautiful custom animations in no time. ?? fully tested ?? well documented ?? e

Felix Blaschke 879 Dec 31, 2022
A flutter package that adds support for vector data based animations.

animated_vector Description and inspiration A package that adds support for vector data based animations. The data format is heavily inspired from the

Potato Open Sauce Project 6 Apr 26, 2022
A package to create nice and smooth animations for flutter

animation_director A package to create nice and smooth animations for flutter Introduction A simple package to build beautiful and smooth animations f

null 10 Nov 28, 2022
A flutter package which makes it easier to display the difference between two images.

?? Before After A flutter package which makes it easier to display the differences between two images.. The source code is 100% Dart, and everything r

Sahil Kumar 741 Dec 30, 2022
A Flutter package for a quick and handy giffy dialog.

?? Giffy Dialogs A beautiful and custom alert dialog for flutter highly inspired from FancyAlertDialog-Android. The source code is 100% Dart, and ever

Sahil Kumar 626 Dec 29, 2022
A Flutter Package providing Avatar Glow Widget

Avatar Glow This Flutter package provides a Avatar Glow Widget with cool background glowing animation. Live Demo: https://apgapg.github.io/avatar_glow

Ayush P Gupta 250 Dec 22, 2022
A Flutter package with a selection of simple yet very customizable set of loading animations.

Flutter Loading Animations A simple yet very customizable set of loading animations for Flutter projects. Installation Add the following to your pubsp

Andre Cytryn 171 Sep 23, 2022
A beautiful animated flutter widget package library. The tab bar will attempt to use your current theme out of the box, however you may want to theme it.

Motion Tab Bar A beautiful animated widget for your Flutter apps Preview: | | Getting Started Add the plugin: dependencies: motion_tab_bar: ^0.1.5 B

Rezaul Islam 237 Nov 15, 2022