Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

flutter stripe

pub package build

�� flutter_stripe is in beta – please provide feedback (and/or contribute) if you find issues ��️

the stripe flutter sdk allows you to build delightful payment experiences in your native android and ios apps using flutter. we provide powerful and customizable ui screens and elements that can be used out-of-the-box to collect your users’ payment details.

stripe-flutter_cover

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.

apple pay: we provide a seamless integration with apple pay.

google pay: the plugin can easily act as payment provider for the pay plugin that enables you to seamlessly integrate google pay or apple pay. all you need to do is add your stripe publishable key to the payment profile.

payment methods: accepting more payment methods helps your business expand its global reach and improve checkout conversion.

sca-ready: the sdk automatically performs native 3d secure authentication if needed to comply with strong customer authentication regulation in europe.

native ui: we provide native screens and elements to securely collect payment details on android and ios.

pre-built payments ui: learn how to integrate payment sheet, the new pre-built payments ui for mobile apps. this pre-built ui lets you accept cards, apple pay, and google pay out of the box, and includes support for saving & reusing cards.

recommended usage

if you’re selling digital products or services within your app, (e.g. subscriptions, in-game currencies, game levels, access to premium content, or unlocking a full version), you must use the app store’s in-app purchase apis. see apple’s and google’s guidelines for more information. for all other scenarios you can use this sdk to process payments via stripe.

installation

dart pub add flutter_stripe

requirements

android

  • android 5.0 (api level 21) and above
  • kotlin version 1.5.0 and above: example
  • using a descendant of theme.appcompact for your activity: example, example night theme
  • using an up-to-date android gradle build tools version: example and an up-to-date gradle version accordingly: example
  • using flutterfragmentactivity instead of flutteractivity in mainactivity.kt: example

this is caused by the stripe sdk requires the use of the appcompact theme for their ui components and the support fragment manager for the payment sheets

ios

compatible with apps targeting ios 11 or above.

usage example

// main.dart
import 'package:flutter_stripe/flutter_stripe.dart';

void main() async {
  widgetsflutterbinding.ensureinitialized();

  // set the publishable key for stripe - this is mandatory
  stripe.publishablekey = stripepublishablekey;
  runapp(paymentscreen());
}

// payment_screen.dart
class paymentscreen extends statelesswidget {

  @override
  widget build(buildcontext context) {
    return scaffold(
      appbar: appbar(),
      body: column(
        children: [
          cardfield(
            oncardchanged: (card) {
              print(card);
            },
          ),
          textbutton(
            onpressed: () async {
              // create payment method
              final paymentmethod =
                  await stripe.instance.createpaymentmethod(paymentmethodparams.card());
            },
            child: text('pay'),
          )
        ],
      ),
    );
  }
}

stripe initialization

to initialize stripe in your flutter app, use the stripe base class.

stripe offers publishablekey, stripeaccountid, threedsecureparams and merchantidentifier. only publishablekey is required.

dart api

the library offers several methods to handle stripe related actions:

future<paymentmethod> createpaymentmethod(...);
future<paymentintent> handlecardaction(...);
future<paymentintent> confirmpaymentmethod(...);
future<void> configure3dsecure(...);
future<bool> isapplepaysupported();
future<void> presentapplepay(...);
future<void> confirmapplepaypayment(...);
future<setupintent> confirmsetupintent(...);
future<paymentintent> retrievepaymentintent(...);
future<string> createtokenforcvcupdate(...);

future<void> initpaymentsheet(...);
future<void> presentpaymentsheet(...);
future<void> confirmpaymentsheetpayment()

the example app offers examples on how to use these methods.

pay plugin support

flutter_stripe fully supports the pay plugin from the google pay team. by including a few lines you can integrate stripe as a payment processor for google / apple pay:

future<void> ongooglepayresult(paymentresult) async {
    final response = await fetchpaymentintentclientsecret();
    final clientsecret = response['clientsecret'];
    final token = paymentresult['paymentmethoddata']['tokenizationdata']['token'];
    final tokenjson = map.castfrom(json.decode(token));

    final params = paymentmethodparams.cardfromtoken(
      token: tokenjson['id'],
    );
    // confirm google pay payment method
    await stripe.instance.confirmpaymentmethod(
      clientsecret,
      params,
    );
}

run the example app

  • navigate to the example folder cd example
  • install the dependencies
    • flutter pub get
  • set up env vars for the flutter app and a local backend.
    • get your test stripe api keys
    • cp lib/.env.example.dart lib/.env.dart and set your stripe publishable key.
    • cp server/.env.example server/.env and set the variable values in your newly created .env file.
  • install the server dependencies: yarn --cwd "server"
  • start the example
    • terminal 1: yarn --cwd "server" start
    • terminal 2: flutter run
additional steps for webhook forwarding

known issues

  • the card field on android has focus issues on older flutter versions – it has been fixed by the flutter framework in
    the master branch. the issue is being tracked in #14.

contributing

you can help us make this project better, feel free to open an new issue or a pull request.

setup

this project uses melos to manage all the packages inside this repo.

  • install melos: dart pub global activate melos
  • setup melos in your local folder: melos bootstrap
useful commands
  • format melos run format
  • analyze melos run analyze
  • test melos run test
  • pub get melos run get
publishing
  • use melos version and melos publish to keep all the repositories in sync

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.