mid_flutter 0.0.1

Payment Plugin connected to MidTrans #

Note: This plugin is still under development, and some Components might not be available yet or still has so many bugs.

  • This Interface is supported by one of Indonesia's Payment Gateway vendor [Midtrans](midtrans github)

Installation #

First, add mid_flutter as a dependency in your pubspec.yaml file.

mid_flutter: ^0.0.1

Example #

class MidFlutterDemo extends StatefulWidget {
  @override
  _MidFlutterDemoState createState() => _MidFlutterDemoState();
}

class _MidFlutterDemoState extends State<MidFlutterDemo> {
  TextEditingController _creditCardCtrl = TextEditingController();
  TextEditingController _expiryMonthCtrl = TextEditingController();
  TextEditingController _expiryYearCtrl = TextEditingController();
  TextEditingController _cvvCtrl = TextEditingController();
  TextEditingController _amountCtrl = TextEditingController();
  String _error = "";
  String _result = "";

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: SingleChildScrollView(child: Padding(
          padding: EdgeInsets.all(16.0),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              TextField(
                controller: _creditCardCtrl,
                decoration: InputDecoration(hintText: "16 digits only", labelText: "Credit Card"),
                keyboardType: TextInputType.number,
                maxLength: 16,
              ),
              Row(children: [
                Expanded(
                  child: TextField(
                    controller: _expiryMonthCtrl,
                    decoration:
                    InputDecoration(hintText: "2 digits only", labelText: "Expiry Month"),
                    keyboardType: TextInputType.number,
                    maxLength: 2,
                  ),
                ),
                Container(width: 16.0),
                Expanded(
                  child: TextField(
                    controller: _expiryYearCtrl,
                    decoration:
                    InputDecoration(hintText: "4 digits only", labelText: "Expiry Year"),
                    keyboardType: TextInputType.number,
                    maxLength: 4,
                  ),
                )
              ]),
              TextField(
                controller: _cvvCtrl,
                decoration: InputDecoration(hintText: "3 digits only", labelText: "CVV"),
                keyboardType: TextInputType.number,
                maxLength: 3,
              ),
              TextField(
                controller: _amountCtrl,
                decoration: InputDecoration(hintText: "Amount of charge", labelText: "Amount"),
                keyboardType: TextInputType.number,
              ),
              Padding(
                padding: EdgeInsets.symmetric(vertical: 16.0),
                child: _error != ""
                    ? Text(
                  _error,
                  style: TextStyle(color: Colors.red),
                )
                    : Text(_result),
              ),
              FlatButton(
                child: Text("Submit"),
                onPressed: () async {
                  _error = "";
                  _result = "";

                  if ((_creditCardCtrl.text ?? "").isEmpty) {
                    _error = "Credit Card must be filled!";
                  } else if ((_expiryMonthCtrl.text ?? "").isEmpty) {
                    _error = "Expiry Month must be filled!";
                  } else if ((_expiryYearCtrl.text ?? "").isEmpty) {
                    _error = "Expiry Year must be filled!";
                  } else if ((_cvvCtrl.text ?? "").isEmpty) {
                    _error = "CVV must be filled!";
                  } else if ((_amountCtrl.text ?? "").isEmpty) {
                    _error = "Amount must be filled!";
                  }

                  if (_error == "") {
                    bool configured = await MidFlutter.configure(clientKey: "your_midtrans_client_key");

                    if (configured) {
                      try {
                        _result = await MidFlutter.generateCreditCardToken(
                            creditCardNumber: _creditCardCtrl.text,
                            expiryMonth: int.tryParse(_expiryMonthCtrl.text),
                            expiryYear: int.tryParse(_expiryYearCtrl.text),
                            cvv: int.tryParse(_cvvCtrl.text),
                            amount: double.tryParse(_amountCtrl.text));
                      } on Exception catch (e) {
                        _error = "$e";
                      }
                    }
                  }

                  setState(() {});
                },
                color: Theme.of(context).primaryColor,
                textColor: Colors.white,
              )
            ],
          ),
        ),),
      ),
    );
  }
}

0.0.1 #

  • Initial release, with only Credit Card support

example/README.md

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

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

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

class MidFlutterDemo extends StatefulWidget {
  @override
  _MidFlutterDemoState createState() => _MidFlutterDemoState();
}

class _MidFlutterDemoState extends State<MidFlutterDemo> {
  TextEditingController _creditCardCtrl = TextEditingController();
  TextEditingController _expiryMonthCtrl = TextEditingController();
  TextEditingController _expiryYearCtrl = TextEditingController();
  TextEditingController _cvvCtrl = TextEditingController();
  TextEditingController _amountCtrl = TextEditingController();
  String _error = "";
  String _result = "";

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: SingleChildScrollView(child: Padding(
          padding: EdgeInsets.all(16.0),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              TextField(
                controller: _creditCardCtrl,
                decoration: InputDecoration(hintText: "16 digits only", labelText: "Credit Card"),
                keyboardType: TextInputType.number,
                maxLength: 16,
              ),
              Row(children: [
                Expanded(
                  child: TextField(
                    controller: _expiryMonthCtrl,
                    decoration:
                    InputDecoration(hintText: "2 digits only", labelText: "Expiry Month"),
                    keyboardType: TextInputType.number,
                    maxLength: 2,
                  ),
                ),
                Container(width: 16.0),
                Expanded(
                  child: TextField(
                    controller: _expiryYearCtrl,
                    decoration:
                    InputDecoration(hintText: "4 digits only", labelText: "Expiry Year"),
                    keyboardType: TextInputType.number,
                    maxLength: 4,
                  ),
                )
              ]),
              TextField(
                controller: _cvvCtrl,
                decoration: InputDecoration(hintText: "3 digits only", labelText: "CVV"),
                keyboardType: TextInputType.number,
                maxLength: 3,
              ),
              TextField(
                controller: _amountCtrl,
                decoration: InputDecoration(hintText: "Amount of charge", labelText: "Amount"),
                keyboardType: TextInputType.number,
              ),
              Padding(
                padding: EdgeInsets.symmetric(vertical: 16.0),
                child: _error != ""
                    ? Text(
                  _error,
                  style: TextStyle(color: Colors.red),
                )
                    : Text(_result),
              ),
              FlatButton(
                child: Text("Submit"),
                onPressed: () async {
                  _error = "";
                  _result = "";

                  if ((_creditCardCtrl.text ?? "").isEmpty) {
                    _error = "Credit Card must be filled!";
                  } else if ((_expiryMonthCtrl.text ?? "").isEmpty) {
                    _error = "Expiry Month must be filled!";
                  } else if ((_expiryYearCtrl.text ?? "").isEmpty) {
                    _error = "Expiry Year must be filled!";
                  } else if ((_cvvCtrl.text ?? "").isEmpty) {
                    _error = "CVV must be filled!";
                  } else if ((_amountCtrl.text ?? "").isEmpty) {
                    _error = "Amount must be filled!";
                  }

                  if (_error == "") {
                    bool configured = await MidFlutter.configure(clientKey: "your_midtrans_client_key");

                    if (configured) {
                      try {
                        _result = await MidFlutter.generateCreditCardToken(
                            creditCardNumber: _creditCardCtrl.text,
                            expiryMonth: int.tryParse(_expiryMonthCtrl.text),
                            expiryYear: int.tryParse(_expiryYearCtrl.text),
                            cvv: int.tryParse(_cvvCtrl.text),
                            amount: double.tryParse(_amountCtrl.text));
                      } on Exception catch (e) {
                        _error = "$e";
                      }
                    }
                  }

                  setState(() {});
                },
                color: Theme.of(context).primaryColor,
                textColor: Colors.white,
              )
            ],
          ),
        ),),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


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

We analyzed this package on Jul 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

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

Format lib/mid_flutter.dart.

Run flutter format to format lib/mid_flutter.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

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.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8

Admin