flutter_midtrans_cc 1.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

flutter_midtrans_cc #

Midtrans Credit Card With 3DS handler for Flutter

Initialize midtrans #

FlutterMidtransCC midtransCC;

@override
initState(){
    midtransCC = FlutterMidtransCC(
        'midtrans_production_url',
        'midtrans_staging_url', 
        'server_key', 
        'client_key',
        isProduction: false,
    );
    super.initState();
}

Get CC Token #

midtransCC.getCreditCardToken("Credit card number", "Expiry Date", "Expiry year", "cvv");

Charge payment and redirect to 3DS #

 midtransCC.midtransCharge("token id", 'custom item id', 'item price', item_details, customer_details).then((response) {
                      var extractedData = json.decode(response.body);
                      print(response.statusCode);

                      if (response.statusCode == 201 ||
                          response.statusCode == 200) {
                        print(response.body);
                        if (extractedData['status_code'] == "201") {
                          Navigator.push(
                            context,
                            MaterialPageRoute(
                              builder: (context) => midtransCC.webview3DS(
                                  transactionId:
                                      extractedData['transaction_id'],
                                  url: extractedData['redirect_url'],
                                  onClosePressed: () {
                                    Navigator.pop(context);
                                  },
                                  onCompleteRedirect: () {
                                    Navigator.pushReplacement(
                                      context,
                                      MaterialPageRoute(
                                        builder: (context) => SuccessPage(),
                                      ),
                                    );
                                  }),
                            ),
                          ).then((result) {
                            print(result);
                          });
                        }
                      } else {
                        print(response.body);
                      },
                    ),
                };

see example for more detailed usage

Notes: you need to activate Midtrans Web SDK before using this package #

[1.0.4] - 23/05/2020. #

  • fix packages health issues

[1.0.3] - 23/05/2020. #

  • Edit more detailed readme.md

[1.0.2] - 23/05/2020. #

  • Edit more detailed readme.md

[1.0.1] - 23/05/2020. #

  • Fix pub.dev warnings

[0.0.1] - 23/05/2020. #

  • Initial Release

example/lib/main.dart

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_midtrans_cc/flutter_midtrans_cc.dart';
import 'SuccessPage.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Midtrans CC',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: FlutterMidtransCCExample(),
    );
  }
}

class FlutterMidtransCCExample extends StatefulWidget {
  @override
  _FlutterMidtransCCExampleState createState() =>
      _FlutterMidtransCCExampleState();
}

class _FlutterMidtransCCExampleState extends State<FlutterMidtransCCExample> {
  TextEditingController ccNumberController;
  TextEditingController expiryDateController;
  TextEditingController expiryYearController;
  TextEditingController cvvController;
  FlutterMidtransCC midtransCC;

  List<Map> item_details = [
    {'id': 'item1', 'price': 15000, 'quantity': 1, 'name': 'roti bakar'}
  ];

  Map customer_details = {
    'first_name': 'John',
    'last_name': 'Doe',
    'email': 'johndoe@example.com',
    'phone': '08881112233344'
  };

  @override
  void initState() {
    midtransCC = FlutterMidtransCC('midtrans_production_url',
        'midtrans_staging_url', 'server_key', 'client_key',
        isProduction: false);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 13, vertical: 13),
      child: ListView(
        children: <Widget>[
          TextFormField(
            controller: ccNumberController,
            autocorrect: false,
            autofocus: false,
            keyboardType: TextInputType.number,
            decoration: InputDecoration(
                hintText: 'credit card number', labelText: 'cc number'),
          ),
          TextFormField(
            controller: expiryDateController,
            autocorrect: false,
            autofocus: false,
            keyboardType: TextInputType.number,
            decoration:
                InputDecoration(hintText: 'expiry date', labelText: 'exp date'),
          ),
          TextFormField(
            controller: expiryYearController,
            autocorrect: false,
            autofocus: false,
            keyboardType: TextInputType.number,
            decoration:
                InputDecoration(hintText: 'expiry year', labelText: 'exp year'),
          ),
          TextFormField(
            controller: cvvController,
            autocorrect: false,
            autofocus: false,
            keyboardType: TextInputType.number,
            decoration: InputDecoration(hintText: 'cvv', labelText: 'cvv'),
          ),
          RaisedButton(
            child: Text(
              'Submit',
              style: TextStyle(color: Colors.white),
            ),
            color: Colors.blue,
            onPressed: () {
              midtransCC
                  .getCreditCardToken(
                      ccNumberController.text,
                      expiryDateController.text,
                      expiryYearController.text,
                      cvvController.text)
                  .then((response) {
                print(response.statusCode);
                print(response.body);

                var extractedData = json.decode(response.body);

                if (response.statusCode == 200) {
                  if (extractedData['status_code'] == '200') {
                    midtransCC
                        .midtransCharge(extractedData['token_id'], '0x224s',
                            '15000', item_details, customer_details)
                        .then((response) {
                      var extractedData = json.decode(response.body);
                      print(response.statusCode);

                      if (response.statusCode == 201 ||
                          response.statusCode == 200) {
                        print(response.body);
                        if (extractedData['status_code'] == "201") {
                          Navigator.push(
                            context,
                            MaterialPageRoute(
                              builder: (context) => midtransCC.webview3DS(
                                  transactionId:
                                      extractedData['transaction_id'],
                                  url: extractedData['redirect_url'],
                                  onClosePressed: () {
                                    Navigator.pop(context);
                                  },
                                  onCompleteRedirect: () {
                                    Navigator.pushReplacement(
                                      context,
                                      MaterialPageRoute(
                                        builder: (context) => SuccessPage(),
                                      ),
                                    );
                                  }),
                            ),
                          ).then((result) {
                            print(result);
                          });
                        }
                      } else {
                        print(response.body);
                      }
                    });
                  } else {
                    for (int i = 0;
                        i < extractedData['validation_messages'].length;
                        i++) {
                      var err = extractedData['validation_messages'].toString();

                      print(err);
                    }
                  }
                }
              });
            },
          )
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_midtrans_cc: ^1.0.4

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_midtrans_cc/flutter_midtrans_cc.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
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]
50
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:flutter_midtrans_cc/flutter_midtrans_cc.dart, package:flutter_midtrans_cc/src/Webview3DS.dart, package:webview_flutter/webview_flutter.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:flutter_midtrans_cc/flutter_midtrans_cc.dart, package:flutter_midtrans_cc/src/Webview3DS.dart, package:webview_flutter/webview_flutter.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:flutter_midtrans_cc/flutter_midtrans_cc.dart, package:flutter_midtrans_cc/src/Webview3DS.dart, package:webview_flutter/webview_flutter.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:flutter_midtrans_cc/flutter_midtrans_cc.dart, package:flutter_midtrans_cc/src/Webview3DS.dart, package:webview_flutter/webview_flutter.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [flutter_midtrans_cc] that is in a package requiring null.

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
webview_flutter ^0.3.22+1 0.3.22+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