flutter_kushki 0.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 72

flutter_kushki #

Kushki frontend payment gateway integration for Flutter

Installing #

  1. Add dependency to pubspec.yaml

    Get the latest version in the 'Installing' tab on pub.dartlang.org

dependencies:
    flutter_kushki: ^0.0.5
  1. Import the package
import 'package:flutter_kushki/kushki.dart'; // Main class
import 'package:flutter_kushki/kushki_environment.dart'; // Environments
import 'package:flutter_kushki/kushki_card.dart'; // Card model

Usage #

Instantiate the class

    kushki = new Kushki(
      '<your_merchant_id>',
      currency: 'USD',
      environment: KushkiEnvironment.TESTING,
    );

Create the card data

    final _card = KushkiCard();
    _card.name = 'Kushki Test';
    _card.number = '4381082002222866';
    _card.cvv = '633';
    _card.expiryMonth = '07';
    _card.expiryYear = '21';

Get the card token

    try {
      final String token = await kushki.requestToken(_card, 30.52);
      print(token);
    } catch (e) {
      print(e.toString());
    }

TODO: #

  • [x] requestToken()
  • [ ] getBinInfo()
  • [ ] requestSubscriptionToken()
  • [ ] requestCardAsyncToken()
  • [ ] getBankList()
  • [ ] requestTransferSubscriptionToken()
  • [ ] requestSecureValidation()
  • [ ] requestCashToken()
  • [ ] requestCashOutToken()
  • [ ] requestTransferToken()

0.0.5 #

  • Documentation fixes

0.0.4 #

  • File format changes
  • Added some documentation to the methods and classes

0.0.3 #

  • Changed this project from a plugin to a package
  • Removed dependency of Java and iOS Kushki packages
  • Requests are done directly to Kushki's API

0.0.2 #

  • Completed get card token

0.0.1 #

  • Intial Kushki implementation

example/lib/main.dart

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

import 'package:flutter_credit_card/flutter_credit_card.dart';
import 'package:flutter_kushki/kushki.dart';
import 'package:flutter_kushki/kushki_environment.dart';
import 'package:flutter_kushki/kushki_card.dart';

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

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

class _MyAppState extends State<MyApp> {
  Kushki _kushki;
  TextEditingController _merchantIdController;

  @override
  void initState() {
    super.initState();
    _merchantIdController = TextEditingController();
  }

  // Create the Kushki class instance
  Future<void> initKushki(BuildContext context) async {
    setState(() {
      _kushki = new Kushki(
        _merchantIdController.text,
        currency: 'USD',
        environment: KushkiEnvironment.TESTING,
      );
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Kushki example app'),
        ),
        body: SingleChildScrollView(
          child: Column(
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.only(left: 16, right: 16),
                child: TextFormField(
                  decoration: InputDecoration(labelText: 'Merchant ID'),
                  controller: _merchantIdController,
                  validator: (value) {
                    if (value.isEmpty) {
                      return "Please input your Kushki's Merchant ID";
                    }
                    return null;
                  },
                ),
              ),
              MaterialButton(
                color: Colors.blueAccent,
                child: Text('Set ID'),
                onPressed: () async {
                  initKushki(context);
                },
              ),
              _kushki != null
                  ? Form(
                      kushki: _kushki,
                    )
                  : Container(),
            ],
          ),
        ),
      ),
    );
  }
}

class Form extends StatefulWidget {
  final Kushki kushki;

  const Form({Key key, this.kushki}) : super(key: key);

  @override
  _FormState createState() => _FormState();
}

class _FormState extends State<Form> {
  final _card = KushkiCard();
  final totalAmount = 30.52;
  _FormState();
  String _cardToken;

  bool isCvvFocused = false;

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

    _card.name = 'Kushki Test';
    _card.number = '4381082002222866';
    _card.cvv = '633';
    _card.expiryMonth = '07';
    _card.expiryYear = '21';
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        CreditCardWidget(
          cardNumber: _card.number,
          expiryDate: '${_card.expiryMonth}/${_card.expiryYear}',
          cardHolderName: _card.name,
          cvvCode: _card.cvv,
          showBackView:
              isCvvFocused, //true when you want to show cvv(back) view
        ),
        CreditCardForm(
          onCreditCardModelChange: onCreditCardModelChange,
        ),
        MaterialButton(
          color: Colors.blueAccent,
          child: Text('Get the card token'),
          onPressed: () async {
            try {
              final String token =
                  await widget.kushki.requestToken(_card, totalAmount);
              setState(() {
                _cardToken = token;
              });
              Scaffold.of(context).showSnackBar(
                SnackBar(
                  content: Text("Token: $token"),
                  backgroundColor: Colors.blue,
                ),
              );
            } catch (e) {
              print(e.toString());
              Scaffold.of(context).showSnackBar(
                SnackBar(
                  content: Text(e.message),
                  backgroundColor: Colors.red,
                ),
              );
            }
          },
        ),
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: Text(_cardToken ?? 'Card token result from API'),
        ),
      ],
    );
  }

  void onCreditCardModelChange(CreditCardModel creditCardModel) {
    final String date = creditCardModel.expiryDate;
    final dates = date.split('/');

    setState(() {
      _card.number = creditCardModel.cardNumber;

      if (dates.length == 2) {
        _card.expiryMonth = dates[0];
        _card.expiryYear = dates[1];
      }
      _card.name = creditCardModel.cardHolderName;
      _card.cvv = creditCardModel.cvvCode;
      isCvvFocused = creditCardModel.isCvvFocused;
    });
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_kushki: ^0.0.5

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_kushki/kushki.dart';
import 'package:flutter_kushki/kushki_card.dart';
import 'package:flutter_kushki/kushki_environment.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
49
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]
72
Learn more about scoring.

We analyzed this package on Jul 10, 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 not compatible with SDK dart

Because:

  • flutter_kushki that is a package requiring null.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
http ^0.12.1 0.12.1
Transitive dependencies
charcode 1.1.3
collection 1.14.12 1.14.13
http_parser 3.1.4
meta 1.1.8 1.2.2
path 1.7.0
pedantic 1.9.0 1.9.2
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test