stripe_native 1.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 81

Stripe Native #

Create chargeable stripe tokens using Apple and Google Pay.

This plugin will give you easy access to the Apple and Google Pay payment sheets. And provide one-time source tokens that are used to create a Stripe Charge.

Apple Pay

Setup #

Both (Required) #

To begin one will need a Stripe project, from there collect a publishable key.

iOS (Required) #

On the Apple Developer portal, one will need to create a merchant identifier. Then connect that identifier to the Stripe project.

From the Stripe dashboard, create a signing certificate to share with Apple, then upload the signed certificate to Stripe.

Merchant Identifier

Lastly, open the apps' iOS module. Add the newly created identifier to the project's signing capabilities.

Signing Capablities

Android (Optional) #

On the Google Play console, add the merchant identifier to the app capabilites. This makes the merchant known to Google Pay. With it, users will not see a warning saying this app is an unidentified merchant.

Functions #

Set Publishable Key #

Prior to calling native pay, set the publishable key.

StripeNative.setPublishableKey("pk_test_yZuUz6Sqm83H4lA7SrlAvYCh003MvJiJlR");

Set Merchant Identifier #

Prior to calling native pay, set the merchant identifier.

StripeNative.setMerchantIdentifier("merchant.rbii.stripe-example");

Set Currency Key #

In order to change the currency, pass in an ISO currency code prior to opening a payment sheet. On iOS it also requires passing in a country code.

StripeNative.setCurrencyKey("EUR");
// Not required on Android
StripeNative.setCountryKey("FR");

Native-Pay #

There are two ways to create a payment sheet. With a list of items and prices, or with some subtotal, tax and tip.

Both methods require a merchant name to display at the bottom of the sheet.

// subtotal, tax, tip, merchant name
var order = Order(5.50, 1.0, 2.0, "Some Store");
var token = await StripeNative.useNativePay(order);
const itemPrices = <String, double>{"Nice Hat": 5.00, "Used Hat" : 1.50};
var receipt = Receipt(itemPrices, "Hat Store");
var token = await StripeNative.useReceiptNativePay(receipt);

Confirm Payment (iOS) #

On iOS the payment sheet spins and ends with a check or X depending on the result passed in. During the spinning, query an endpoint for a charge using the token. This function does not affect Android.

// call charge endpoint w/ token
const wasCharged = await AppAPI.charge(token, amount);
// then show success or failure
StripeNative.confirmPayment(wasCharged);

0.0.1 #

Apple & Google Pay initial Implementations #

Call payment sheets using a Receipt or Order

  • Receipt: A list of items and prices
  • Order: subtotal, tax, and tip
  • Both require a merchant name

0.0.2 #

Add swift version requirements

1.0.0 #

Documentation and release

1.0.1 #

Flutter formatting, and description increase

1.0.2 #

description decrease

1.0.3 #

naming in receipt readme

1.0.4 #

add example readme

1.0.5 #

add dartdoc

1.1.0 #

setCurrencyKey and setCountryKey

1.1.1 #

null currency key fix

1.1.2 #

switch wallet environment using publishable key hint

1.1.3 #

add error to iOS for unsupported country key (pod 1.0.1)

1.1.4 #

add prefixes for country codes, StripeNativeErrors -> FlutterErrors

1.2.0 #

  • Android: Bump AGP & Gradle
  • Require Flutter 1.12.13+hotfix.5 (stable)
  • Update pubspec.yaml format
  • Update .gitignore & remove unused files from repository
  • iOS: Bump to Swift 5.0
  • iOS: Define clang module

example/lib/main.dart

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

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

class NativePayExample extends StatefulWidget {
  @override
  _NativePayExampleState createState() => _NativePayExampleState();
}

class _NativePayExampleState extends State<NativePayExample> {

  @override
  void initState() {
    super.initState();
    StripeNative.setPublishableKey("pk_test_yZuUz6Sqm83H4lA7SrlAvYCh003MvJiJlR");
    StripeNative.setMerchantIdentifier("merchant.rbii.stripe-example");
  }

  Future<String> get receiptPayment async {
    /* custom receipt w/ useReceiptNativePay */
    const receipt = <String, double>{"Nice Hat": 5.00, "Used Hat" : 1.50};
    var aReceipt = Receipt(receipt, "Hat Store");
    return await StripeNative.useReceiptNativePay(aReceipt);
  }

  Future<String> get orderPayment async {
    // subtotal, tax, tip, merchant name
    var order = Order(5.50, 1.0, 2.0, "Some Store");
    return await StripeNative.useNativePay(order);
  }

  Widget get nativeButton => Padding(padding: EdgeInsets.all(10), child: RaisedButton(padding: EdgeInsets.all(10),
        child: Text("Native Pay"),
        onPressed: () async {

          // var token = await orderPayment;
          var token = await receiptPayment;

          print(token);
          /* After using the plugin to get a token, charge that token. On iOS the Apple-Pay sheet animation will signal failure or success using confirmPayment. Google-Pay does not have a similar implementation, so I may flash a SnackBar using wasCharged in a real application.
          call own charge endpoint w/ token
          const wasCharged = await AppAPI.charge(token, amount);
          then show success or failure
          StripeNative.confirmPayment(wasCharged);
          */
          // Until this method below is called, iOS will spin a loading indicator on the Apple-Pay sheet
          StripeNative.confirmPayment(true); // iOS load to check.
          // StripeNative.confirmPayment(false); // iOS load to X.

        }
    ));

  @override
  Widget build(BuildContext context) => MaterialApp(home: Scaffold(body: Center(child: nativeButton)));


}

Use this package as a library

1. Depend on it

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


dependencies:
  stripe_native: ^1.2.0

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

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-1 points)

31 out of 31 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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test