flutter_pay 0.9.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 75

Google Pay Preparing #

TODO

See Android documentation

Apple Pay Preparing #

TODO

See Apple documentation

Usage #

Firstly, you need to make sure, that Pay api is available on device:

import 'package:flutter_pay/flutter_pay.dart';
//..

FlutterPay flutterPay = FlutterPay();

bool isAvailable = await flutterPay.canMakePayments();
/..

If you need to check if user has at least one active card:

import 'package:flutter_pay/flutter_pay.dart';
//..

FlutterPay flutterPay = FlutterPay();

bool isAvailable = await flutterPay.canMakePaymentsWithActiveCard();

//Also you can state allowed payment card networks:
bool isAvailable = await flutterPay.canMakePaymentsWithActiveCard(
	allowedPaymentNetworks: [
		PaymentNetwork.visa, 
		PaymentNetwork.masterCard,
	],
);

To make payment is makePayment method. This function will return to you token that you need to send to your gateway to complete payment. Example:

import 'package:flutter_pay/flutter_pay.dart';

FlutterPay flutterPay = FlutterPay();

PaymentItem item = PaymentItem(name: "T-Shirt", price: 10.98);

String token = await flutterPay.makePayment(
	merchantIdentifier: "merchant.com.flutterPay",
	currencyCode: "RUB",
	countryCode: "RU",
	allowedPaymentNetworks: [
		PaymentNetwork.visa, 
		PaymentNetwork.masterCard,
	],
	paymentItems: [item],
	merchantName: "Super Shop", 
	gatewayName: "stripe",
);

Note that some arguments affects only Apple Pay or Google Pay. For example, paymentItems affects only Apple Pay. And the last item is used for grand total label.

merchantName affects only Google Pay and will be shown to user.

gatewayName also affects only Google Pay. See Google Pay integration section.

Payment Network matrix #

Payment NetworkiOSAndroid
Visa++
MasterCard++
American Express++
Interac++
Discover++
JCB++
Maestro+
Electron+
Cartes Bancarries+
Union Pay+
EftPos+
Elo+
ID Credit+
Mada+
Private Label+
Quic Pay+
Suica+
V Pay+

Roadmap #

  • [x] Basic implementation
  • [ ] Complete docs
  • [ ] Add merchant capabilities support
  • [ ] Add billing and shipping info support

0.9.1 #

Fixed pana errors

0.9.0 #

Initial release

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_pay/flutter_pay.dart';

void main() => runApp(MyApp());

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

class _MyAppState extends State<MyApp> {
  FlutterPay flutterPay = FlutterPay();

  String result = "Result will be shown here";

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

  void makePayment() async {
    List<PaymentItem> items = [
      PaymentItem(name: "Маргарита 30 см", price: 30.0)
    ];

    flutterPay.makePayment(
        merchantIdentifier: "merchant.flutterpay.example",
        currencyCode: "RUB",
        countryCode: "RU",
        paymentItems: items,
        merchantName: "-",
        gatewayName: "_");
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Container(
          padding: EdgeInsets.all(12.0),
          child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  this.result,
                  style: TextStyle(
                    fontSize: 16.0,
                  ),
                ),
                FlatButton(
                  child: Text("Can make payments?"),
                  onPressed: () async {
                    try {
                      bool result = await flutterPay.canMakePayments;
                      setState(() {
                        this.result = "Can make payments: $result";
                      });
                    } catch (e) {
                      setState(() {
                        this.result = "$e";
                      });
                    }
                  },
                ),
                FlatButton(
                  child: Text("Can make payments with verified card: $result"),
                  onPressed: () async {
                    try {
                      bool result =
                          await flutterPay.canMakePaymentsWithActiveCard(
                        allowedPaymentNetworks: [
                          PaymentNetwork.visa,
                          PaymentNetwork.masterCard,
                        ],
                      );
                      setState(() {
                        this.result = "$result";
                      });
                    } catch (e) {
                      setState(() {
                        this.result = "Error: $e";
                      });
                    }
                  },
                ),
                FlatButton(
                    child: Text("Try to pay?"),
                    onPressed: () {
                      makePayment();
                    })
              ]),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_pay: ^0.9.1

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_pay/flutter_pay.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
50
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]
75
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:flutter_pay/flutter_pay.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

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

Package does not support Flutter platform web

Because:

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

Package does not support Flutter platform windows

Because:

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

Package not compatible with SDK dart

Because:

  • flutter_pay that is a package requiring null.

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
Dev dependencies
effective_dart ^1.2.0
flutter_test