square_in_app_payments 1.3.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 93

Flutter plugin for In-App Payments SDK #

Build Status Pub

The Flutter plugin for Square In-App Payments SDK is a wrapper for the native Android and iOS SDKs and supports the following native In-App Payments SDK versions:

  • iOS: 1.3.0
  • Android: 1.3.0

Additional documentation #

In addition to this README, the following is available in the flutter plugin GitHub repo:

Build requirements #

  • Android minSdkVersion is API 21 (Lollipop, 5.0) or higher.
  • Android Target SDK version: API 27 (Oreo, 8.1).
  • Android SDK build tools: 26.0.3
  • Android Gradle Plugin: 3.0.0 or greater.
  • Support library: 27.1.1
  • Google Play Services: 16.0.1
  • Google APIs Intel x86 Atom_64 System Image

iOS #

  • Xcode version: 9.1 or greater.
  • iOS Base SDK: 11.1 or greater.
  • Deployment target: iOS 11.0 or greater.

In-App Payments SDK requirements and limitations #

  • In-App Payments SDK cannot issue refunds. Refunds can be issued programmatically using the Transactions API or manually in the Square Dashboard.

Sample applications #

License #

Copyright 2019 Square Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Changelog #

v1.3.0 November 20, 2019 #

  • Bump Square In-App Payments SDK dependency to 1.3.0.
  • Add support for Strong Customer Authentication (SCA).

v1.2.3 September 10, 2019 #

  • Bump Square In-App Payments SDK dependency to 1.2.0.
  • Add support for Sandbox v2.

v1.2.2 July 23, 2019 #

  • Fixed an exception introduced in a recent Flutter update.

v1.2.1 June 5, 2019 #

  • Added paymentType parameter to support apple pay pending amount configuration.

v1.1.1 Mar 29, 2019 #

  • Bump Square In-App Payments iOS SDK dependency to 1.1.1.
  • Enable iOS and android In-App Payments SDK version override.
  • Fix #35 - support AndroidX release build

v1.1.0 Feb 27, 2019 #

  • Support Square In-App Payments iOS and Android SDK 1.1.0.
  • For SDK 1.1.0 change, please check this Change Log.

v1.0.3 Feb 14, 2019 #

  • Compatible to AndroidX migration.
  • CardEntryDidCancelCallback is renamed to CardEntryCancelCallback.
  • Some updates to improve error messages.
  • Minor code style improvements.

v1.0.2 Jan 22, 2019 #

  • Fix Apple Pay issue #18.
  • Refine Apple Pay quick start example.

v1.0.1 Jan 9, 2019 #

  • Initial release.

example/lib/main.dart

/*
 Copyright 2018 Square Inc.
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 
 http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
*/
import 'dart:async';
import 'dart:io' show Platform;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:square_in_app_payments/models.dart';
import 'package:square_in_app_payments/in_app_payments.dart';
import 'package:square_in_app_payments/google_pay_constants.dart'
    as google_pay_constants;
import 'colors.dart';
import 'config.dart';
import 'widgets/buy_sheet.dart';

void main() => runApp(MaterialApp(
      title: 'Super Cookie',
      home: HomeScreen(),
    ));

class HomeScreen extends StatefulWidget {
  HomeScreenState createState() => HomeScreenState();
}

class HomeScreenState extends State<HomeScreen> {
  bool isLoading = true;
  bool applePayEnabled = false;
  bool googlePayEnabled = false;

  static final GlobalKey<ScaffoldState> scaffoldKey =
      GlobalKey<ScaffoldState>();

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

    SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
  }

  Future<void> _initSquarePayment() async {
    await InAppPayments.setSquareApplicationId(squareApplicationId);

    var canUseApplePay = false;
    var canUseGooglePay = false;
    if (Platform.isAndroid) {
      await InAppPayments.initializeGooglePay(
          squareLocationId, google_pay_constants.environmentTest);
      canUseGooglePay = await InAppPayments.canUseGooglePay;
    } else if (Platform.isIOS) {
      await _setIOSCardEntryTheme();
      await InAppPayments.initializeApplePay(applePayMerchantId);
      canUseApplePay = await InAppPayments.canUseApplePay;
    }

    setState(() {
      isLoading = false;
      applePayEnabled = canUseApplePay;
      googlePayEnabled = canUseGooglePay;
    });
  }

  Future _setIOSCardEntryTheme() async {
    var themeConfiguationBuilder = IOSThemeBuilder();
    themeConfiguationBuilder.saveButtonTitle = 'Pay';
    themeConfiguationBuilder.errorColor = RGBAColorBuilder()
      ..r = 255
      ..g = 0
      ..b = 0;
    themeConfiguationBuilder.tintColor = RGBAColorBuilder()
      ..r = 36
      ..g = 152
      ..b = 141;
    themeConfiguationBuilder.keyboardAppearance = KeyboardAppearance.light;
    themeConfiguationBuilder.messageColor = RGBAColorBuilder()
      ..r = 114
      ..g = 114
      ..b = 114;

    await InAppPayments.setIOSCardEntryTheme(themeConfiguationBuilder.build());
  }

  Widget build(BuildContext context) => MaterialApp(
      theme: ThemeData(canvasColor: Colors.white),
      home: Scaffold(
          body: isLoading
              ? Center(
                  child: CircularProgressIndicator(
                  valueColor:
                      AlwaysStoppedAnimation<Color>(mainBackgroundColor),
                ))
              : BuySheet(
                  applePayEnabled: applePayEnabled,
                  googlePayEnabled: googlePayEnabled,
                  applePayMerchantId: applePayMerchantId,
                  squareLocationId: squareLocationId)));
}

Use this package as a library

1. Depend on it

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


dependencies:
  square_in_app_payments: ^1.3.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:square_in_app_payments/google_pay_constants.dart';
import 'package:square_in_app_payments/in_app_payments.dart';
import 'package:square_in_app_payments/models.dart';
import 'package:square_in_app_payments/models.g.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
89
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
93
Learn more about scoring.

We analyzed this package on Apr 4, 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 suggestions

Format lib/in_app_payments.dart.

Run flutter format to format lib/in_app_payments.dart.

Format lib/models.dart.

Run flutter format to format lib/models.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (built_value).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
built_collection ^4.0.0 4.3.2
built_value ^6.1.5 6.8.2 7.0.9
flutter 0.0.0
meta ^1.1.6 1.1.8
Transitive dependencies
analyzer 0.38.5 0.39.5
analyzer_plugin 0.2.1
args 1.6.0
async 2.4.1
build_config 0.4.2
charcode 1.1.3
checked_yaml 1.0.2
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
dart_style 1.3.3
fixnum 0.10.11
front_end 0.1.27 0.1.29
glob 1.2.0
html 0.14.0+3
js 0.6.1+1
json_annotation 3.0.1
kernel 0.3.27 0.3.29
logging 0.11.4
matcher 0.12.6
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.9.3
path 1.6.4
pedantic 1.9.0
pub_semver 1.4.4
pubspec_parse 0.1.5
quiver 2.1.3
sky_engine 0.0.99
source_span 1.7.0
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
watcher 0.9.7+14
yaml 2.2.0
Dev dependencies
build ^1.1.0 1.2.2
build_runner ^1.2.3
built_value_generator ^6.3.0 6.8.2 7.0.9
source_gen ^0.9.4+1 0.9.4+6 0.9.5