flutter_checkout_payment 0.1.0+2

  • Readme
  • Changelog
  • Example
  • Installing
  • new68

Flutter Checkout Payment #

pub.dev Donate Paypal GitHub Follow

Explain #

This plugin is for Checkout online payment. It's implemented the native SDKs to work on Flutter environment.

Getting Started #

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

dependencies:
  flutter_checkout_payment: ^0.1.0+2

Android #

You have to edit AndroidManifest.xml file with following.

<manifest ...
    xmlns:tools="http://schemas.android.com/tools" 
    ... />
    ...
    <application
        ...
        tools:replace="android:label" 
        ... >
    ...
    </appliaction>
</manifest>

iOS #

The SDK build for >= iOS 10.0, so you need to set the platform version in the Podfile to iOS 10 or above.

platform: :ios, '10.0'

Usage #

You just have to import the package with

import 'package:flutter_checkout_payment/flutter_checkout_payment.dart';

Then, you need to initialize the API with you public key. Your public key is found on Checkout dashboard.

await FlutterCheckoutPayment.init(key: "YOUR_PUBLIC_KEY");

And when you are ready for production you have to set the environment to Live.

await FlutterCheckoutPayment.init(key: "YOUR_PUBLIC_KEY", environment: Environment.LIVE);

Now, you can generate the Token which you will use to proceed the payment.

String token = await FlutterCheckoutPayment.generateToken(number: "4242424242424242", name: "name", expiryMonth: "05", expiryYear: "21", cvv: "100");

Public Static Methods Summary #

ReturnDescription
Future<bool>init(@required String key, Environment environment default Environment.SANDBOX})
Initialize the Checkout API with key and environment. Return a bool of the successful status.
Future<String>generateToken({@required String number, @required String name, @required String expiryMonth, @required String expiryYear, @required String cvv, BillingModel billingModel})
Generate the token which it will be used to make the payment, return the String value.
Future<bool>isCardValid({@required String number})
Check whether the card number is valid or not, return a bool with the result.

The rest of methods are under development.

Objects #

class BillingModel {
  final String addressLine1;
  final String addressLine2;
  final String postcode;
  final String country;
  final String city;
  final String state;
  final PhoneModel phoneModel;
}

class PhoneModel {
  final String countryCode;
  final String number;
}

Checkout Android SDK: https://github.com/checkout/frames-android

Checkout iOS SDK: https://github.com/checkout/frames-ios

This plugin is mainly developed for GRANDTK company.

Issues or Contributions #

This is a beta version of plugin, so I am very appreciated for any issues or contribution you can help me with.

License #

MIT: http://mit-license.org.

Copyright (c) 2019 Shady Boshra. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Find me on Stackoverflow #

profile for Shady Boshra at Stack Overflow, Q&A for professional and enthusiast programmers

0.1.0+2 #

Edit package description.

0.1.0+1 #

Edit README.md file.

0.1.0 #

Upgrade version to 0.1.0.

0.0.1 #

First beta version.

example/lib/main.dart

import 'dart:async';

import 'package:credit_card/credit_card_form.dart';
import 'package:credit_card/credit_card_model.dart';
import 'package:credit_card/credit_card_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_checkout_payment/flutter_checkout_payment.dart';
import 'package:flutter_checkout_payment/models/BillingModel.dart';
import 'package:flutter_checkout_payment/models/PhoneModel.dart';

import 'Keys.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Test",
      home: HomeScreen(),
    );
  }
}

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  String _isInit = "false";

  String cardNumber = '';
  String expiryDate = '';
  String cardNameHolder = '';
  String cvv = '';
  bool cvvFocused = false;

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPaymentSDK() async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      bool isSuccess = await FlutterCheckoutPayment.init(key: "${Keys.TEST_KEY}");
      //bool isSuccess =  await FlutterCheckoutPayment.init(key: "${Keys.TEST_KEY}", environment: Environment.LIVE);
      print(isSuccess);
      if (mounted) setState(() => _isInit = "true");
    } on PlatformException {
      if (mounted) setState(() => _isInit = "error");
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Checkout Payment Plugin'),
        ),
        body: SafeArea(
          child: Column(
            children: <Widget>[
              SizedBox(height: 10),
              Text("Checkout Init: $_isInit", style: TextStyle(fontSize: 18)),
              CreditCardWidget(
                cardNumber: cardNumber,
                expiryDate: expiryDate,
                cardHolderName: cardNameHolder,
                cvvCode: cvv,
                showBackView: cvvFocused,
                height: 180,
                width: 305,
                animationDuration: Duration(milliseconds: 1000),
              ),
              Expanded(
                child: SingleChildScrollView(
                  child: CreditCardForm(onCreditCardModelChange: _onModelChange),
                ),
              ),
              Column(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: <Widget>[
                Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: <Widget>[
                  RaisedButton(
                    child: Padding(
                        padding: const EdgeInsets.all(12),
                        child: Text(
                          "Generate Token",
                          style: TextStyle(fontSize: 14, color: Colors.blue),
                        )),
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(30.0),
                    ),
                    onPressed: _generateToken,
                  ),
                  RaisedButton(
                    child: Padding(
                        padding: const EdgeInsets.all(12),
                        child: Text(
                          "Card Validation",
                          style: TextStyle(fontSize: 14, color: Colors.blue),
                        )),
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(30.0),
                    ),
                    onPressed: _cardValidation,
                  )
                ]),
                RaisedButton(
                  child: Padding(
                      padding: const EdgeInsets.all(12),
                      child: Text(
                        "Generate Token with Address",
                        style: TextStyle(fontSize: 14, color: Colors.blue),
                      )),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(30.0),
                  ),
                  onPressed: _generateTokenWithAddress,
                )
              ]),
              SizedBox(height: 10)
            ],
          ),
        ));
  }

  void _onModelChange(CreditCardModel model) {
    setState(() {
      cardNumber = model.cardNumber;
      expiryDate = model.expiryDate;
      cardNameHolder = model.cardHolderName;
      cvv = model.cvvCode;
      cvvFocused = model.isCvvFocused;
    });
  }

  Future<void> _generateToken() async {
    try {
      // Show loading dialog
      showDialog(
          context: this.context,
          barrierDismissible: false,
          child: WillPopScope(
              onWillPop: () => Future<bool>.value(false),
              child: AlertDialog(
                title: Text("Loading..."),
                content: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[CircularProgressIndicator()]),
              )));

      String number = cardNumber.replaceAll(" ", "");
      String expiryMonth = expiryDate.substring(0, 2);
      String expiryYear = expiryDate.substring(3);

      print("$cardNumber, $cardNameHolder, $expiryMonth, $expiryYear, $cvv");

      String token = await FlutterCheckoutPayment.generateToken(
          number: number, name: cardNameHolder, expiryMonth: expiryMonth, expiryYear: expiryYear, cvv: cvv);

      // Hide loading dialog
      Navigator.pop(context);

      // Show result dialog
      showDialog(
          context: this.context,
          child: AlertDialog(
            title: Text("Token"),
            content: Text("$token"),
            actions: <Widget>[FlatButton(child: Text("Close"), onPressed: () => Navigator.pop(context))],
          ));
    } catch (ex) {
      // Hide loading dialog
      Navigator.pop(context);

      // Show error dialog
      showDialog(
          context: this.context,
          child: AlertDialog(
            title: Text("Error"),
            content: Text("${ex.toString()}"),
            actions: <Widget>[FlatButton(child: Text("Close"), onPressed: () => Navigator.pop(context))],
          ));
    }
  }

  Future<void> _generateTokenWithAddress() async {
    try {
      // Show loading dialog
      showDialog(
          context: this.context,
          barrierDismissible: false,
          child: WillPopScope(
              onWillPop: () => Future<bool>.value(false),
              child: AlertDialog(
                title: Text("Loading..."),
                content: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[CircularProgressIndicator()]),
              )));

      String number = cardNumber.replaceAll(" ", "");
      String expiryMonth = expiryDate.substring(0, 2);
      String expiryYear = expiryDate.substring(3);

      print("$cardNumber, $cardNameHolder, $expiryMonth, $expiryYear, $cvv");

      String token = await FlutterCheckoutPayment.generateToken(
          number: number,
          name: cardNameHolder,
          expiryMonth: expiryMonth,
          expiryYear: expiryYear,
          cvv: cvv,
          billingModel: BillingModel(
              addressLine1: "address line 1",
              addressLine2: "address line 2",
              postcode: "postcode",
              country: "UK",
              city: "city",
              state: "state",
              phoneModel: PhoneModel(countryCode: "+44", number: "07123456789")));

      // Hide loading dialog
      Navigator.pop(context);

      // Show result dialog
      showDialog(
          context: this.context,
          child: AlertDialog(
            title: Text("Token"),
            content: Text("$token"),
            actions: <Widget>[FlatButton(child: Text("Close"), onPressed: () => Navigator.pop(context))],
          ));
    } catch (ex) {
      // Hide loading dialog
      Navigator.pop(context);

      // Show error dialog
      showDialog(
          context: this.context,
          child: AlertDialog(
            title: Text("Error"),
            content: Text("${ex.toString()}"),
            actions: <Widget>[FlatButton(child: Text("Close"), onPressed: () => Navigator.pop(context))],
          ));
    }
  }

  Future<void> _cardValidation() async {
    try {
      // Show loading dialog
      showDialog(
          context: this.context,
          barrierDismissible: false,
          child: WillPopScope(
              onWillPop: () => Future<bool>.value(false),
              child: AlertDialog(
                title: Text("Loading..."),
                content: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[CircularProgressIndicator()]),
              )));

      String number = cardNumber.replaceAll(" ", "");

      print("$cardNumber");

      bool isValid = await FlutterCheckoutPayment.isCardValid(number: number);

      // Hide loading dialog
      Navigator.pop(context);

      // Show result dialog
      showDialog(
          context: this.context,
          child: AlertDialog(
            title: Text("Validation? "),
            content: Text("$isValid"),
            actions: <Widget>[FlatButton(child: Text("Close"), onPressed: () => Navigator.pop(context))],
          ));
    } catch (ex) {
      // Hide loading dialog
      Navigator.pop(context);

      // Show error dialog
      showDialog(
          context: this.context,
          child: AlertDialog(
            title: Text("Error"),
            content: Text("${ex.toString()}"),
            actions: <Widget>[FlatButton(child: Text("Close"), onPressed: () => Navigator.pop(context))],
          ));
    }
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_checkout_payment: ^0.1.0+2

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_checkout_payment/flutter_checkout_payment.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
36
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]
68
Learn more about scoring.

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

  • Dart: 2.8.1
  • pana: 0.13.8-dev
  • Flutter: 1.17.0

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
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test