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

Libraries

flutter_midtrans_cc