myfatoorah_flutter 1.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • new62

myfatoorah_flutter #

In order to simplify the integration of your application with MyFatoorah payment platforms, we have developed a cutting-edge plugin that works smoothly with your application and provide you with a simple way to embed our payment functions within your application.

The plugin will save your efforts and time instead of integrating with our API using normal API calls, and will allow you to have the setup ready in a quick, modern and secured way.

Prerequisites #

In order to have the plugin integration working on live environment, please refer to the section Prerequisites and read it for more details

Integration #

Installation #

1. Add MyFatoorah plugin to your pubspec.yaml file.
dependencies:
    myfatoorah_flutter: ^1.0.3	    
  
2. Install the plugin by running the following command.
$ flutter pub get

Usage #

Inside your Dart code do the following:

1. To start using MyFatoorah plugin, import it into your Flutter app.
import 'package:myfatoorah_flutter/myfatoorah_flutter.dart';
2. Initiate MyFatoorah Plugin inside initState().
MFSDK.init(<Put Base url here>, <Put your token here>);

  • You can get the BaseUrl and Token for testing from here
  • Once your testing is finished, simply replace the demo BaseUrl / Token with the live information, click here for more information.
3. (Optional).
  • Use the following lines if you want to set up the properties of AppBar.

      MFSDK.setUpAppBar(
          title: "MyFatoorah Payment",
          titleColor: Colors.white,  // Color(0xFFFFFFFF)
          backgroundColor: Colors.black, // Color(0xFF000000)
          isShowAppBar: true); // For Android platform only
    
  • And use this line, if you want to hide the AppBar. Note, if the platform is iOS, this line will not affected

      MFSDK.setUpAppBar(isShowAppBar: false);
    

Initiate / Execute Payment #

  • Initiate Payment: this step will simply return you all available Payment Methods for the account with the actual charge that the customer will pay on the gateway.

      var request = new MFInitiatePaymentRequest(0.100, MFCurrencyISO.KUWAIT_KWD);
    
      MFSDK.initiatePayment(request, MFAPILanguage.EN,
              (MFResult<MFInitiatePaymentResponse> result) => {
    
            if(result.isSuccess()) {
              print(result.response.toJson().toString())
            }
            else {
              print(result.error.message)
            }
          });
    
  • Execute Payment: once the payment has been initiated, this step will do execute the actual transaction creation at MyFatoorah platform and will return to your application the URL to redirect your customer to make the payment.

      // The value "1" is the paymentMethodId of KNET payment method.
      // You should call the "initiatePayment" API to can get this id and the ids of all other payment methods
      String paymentMethod = "1";
    
      var request = new MFExecutePaymentRequest(paymentMethod, "0.100");
    
      MFSDK.executePayment(context, request, MFAPILanguage.EN,
              (String invoiceId, MFResult<MFPaymentStatusResponse> result) => {
    
            if(result.isSuccess()) {
              print(result.response.toJson().toString())
            }
            else {
              print(result.error.message)
            }
          });
    
  • As a good practice, you don't have to call the Initiate Payment function every time you need to execute payment, but you have to call it at least once to save the PaymentMethodId that you will need to call Execute Payment

Direct Payment / Tokenization #

You have to know the following steps to understand how it works:

  • Get the payment method that allows Direct Payment by calling initiatePayment to get paymentMethodId

  • Collect card info from user MFCardInfo(cardNumber: "51234500000000081", cardExpiryMonth: "05", cardExpiryYear: "21", cardSecurityCode: "100", saveToken: false)

  • If you want to save your credit card info and get a token for next payment you have to set saveToken: true and you will get the token in the response read more in Tokenization

  • If you want to execute a payment through a saved token you have use

    MFCardInfo(cardToken: "put your token here")
    
  • Now you are ready to execute the payment, please check the following sample code.

// The value "2" is the paymentMethodId of Visa/Master payment method.
// You should call the "initiatePayment" API to can get this id and the ids of all other payment methods
String paymentMethod = "2";

var request = new MFExecutePaymentRequest(paymentMethod, "0.100");

// var mfCardInfo = new MFCardInfo(cardToken: "Put your token here");

var mfCardInfo = new MFCardInfo("2223000000000007", "05", "21", "100",
    bypass3DS: true, saveToken: true);

MFSDK.executeDirectPayment(context, request, mfCardInfo, MFAPILanguage.EN,
        (String invoiceId, MFResult<MFDirectPaymentResponse> result) => {

      if(result.isSuccess()) {
        print(result.response.toJson().toString())
      }
      else {
        print(result.error.message)
      }
    });
	
	
	

Send Payment (Offline) #

This will allow you to generate a payment link that can be sent by any channel we support and collect it once it's paid by your customer

var request = MFSendPaymentRequest(invoiceValue: 0.100, customerName: "Customer name",
	notificationOption: MFNotificationOption.LINK);

MFSDK.sendPayment(MFAPILanguage.EN, request, 
        (MFResult<MFSendPaymentResponse> result) => {
  
  if(result.isSuccess()) {
    print(result.response.toJson().toString())
  }
  else {
    print(result.error.message)
  }
});



Payment Enquiry #

This will enable your application to get the full details about a certain invoice / payment

var request = MFPaymentStatusRequest(invoiceId: "12345");

MFSDK.getPaymentStatus(MFAPILanguage.EN, request,
        (MFResult<MFPaymentStatusResponse> result) => {

      if(result.isSuccess()) {
        print(result.response.toJson().toString())
      }
      else {
        print(result.error.message)
      }
    });

1.0.3 - 26/3/2020 #

  • Fix some bugs and make overall enhancement.

1.0.2 - 25/3/2020 #

  • Add cancelRecurringPayment feature.
  • Add cancelToken feature.
  • Updating ReadMe and fix some bugs and enhancement.

1.0.1 - 24/3/2020 #

  • Adds getPaymentStatus feature.
  • Fux bugs and enhancement.

1.0.0 - 24/3/2020 #

  • Adds sendPayment feature.
  • Adds initiatePayment feature.
  • Adds executeRegularPayment feature.
  • Adds executeDirectPayment feature.
  • Adds executeDirectPaymentWithRecurring feature.

0.0.1 - 22/3/2020 #

  • First Beta version of MyFatoorah Flutter Plugin.

example/lib/main.dart

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

/*
TODO: The following data are using for testing only, so that when you go live
      don't forget to replace the following test credentials with the live
      credentials provided by MyFatoorah Company.
*/

// Base Url
final String baseUrl = "https://apitest.myfatoorah.com";

// Token for regular payment
final String regularPaymentToken =
    "7Fs7eBv21F5xAocdPvvJ-sCqEyNHq4cygJrQUFvFiWEexBUPs4AkeLQxH4pzsUrY3Rays7GVA6SojFCz2DMLXSJVqk8NG-plK-cZJetwWjgwLPub_9tQQohWLgJ0q2invJ5C5Imt2ket_-JAlBYLLcnqp_WmOfZkBEWuURsBVirpNQecvpedgeCx4VaFae4qWDI_uKRV1829KCBEH84u6LYUxh8W_BYqkzXJYt99OlHTXHegd91PLT-tawBwuIly46nwbAs5Nt7HFOozxkyPp8BW9URlQW1fE4R_40BXzEuVkzK3WAOdpR92IkV94K_rDZCPltGSvWXtqJbnCpUB6iUIn1V-Ki15FAwh_nsfSmt_NQZ3rQuvyQ9B3yLCQ1ZO_MGSYDYVO26dyXbElspKxQwuNRot9hi3FIbXylV3iN40-nCPH4YQzKjo5p_fuaKhvRh7H8oFjRXtPtLQQUIDxk-jMbOp7gXIsdz02DrCfQIihT4evZuWA6YShl6g8fnAqCy8qRBf_eLDnA9w-nBh4Bq53b1kdhnExz0CMyUjQ43UO3uhMkBomJTXbmfAAHP8dZZao6W8a34OktNQmPTbOHXrtxf6DS-oKOu3l79uX_ihbL8ELT40VjIW3MJeZ_-auCPOjpE3Ax4dzUkSDLCljitmzMagH2X8jN8-AYLl46KcfkBV";

// Token for direct payment and recurring
final String directPaymentToken =
    "fVysyHHk25iQP4clu6_wb9qjV3kEq_DTc1LBVvIwL9kXo9ncZhB8iuAMqUHsw-vRyxr3_jcq5-bFy8IN-C1YlEVCe5TR2iCju75AeO-aSm1ymhs3NQPSQuh6gweBUlm0nhiACCBZT09XIXi1rX30No0T4eHWPMLo8gDfCwhwkbLlqxBHtS26Yb-9sx2WxHH-2imFsVHKXO0axxCNjTbo4xAHNyScC9GyroSnoz9Jm9iueC16ecWPjs4XrEoVROfk335mS33PJh7ZteJv9OXYvHnsGDL58NXM8lT7fqyGpQ8KKnfDIGx-R_t9Q9285_A4yL0J9lWKj_7x3NAhXvBvmrOclWvKaiI0_scPtISDuZLjLGls7x9WWtnpyQPNJSoN7lmQuouqa2uCrZRlveChQYTJmOr0OP4JNd58dtS8ar_8rSqEPChQtukEZGO3urUfMVughCd9kcwx5CtUg2EpeP878SWIUdXPEYDL1eaRDw-xF5yPUz-G0IaLH5oVCTpfC0HKxW-nGhp3XudBf3Tc7FFq4gOeiHDDfS_I8q2vUEqHI1NviZY_ts7M97tN2rdt1yhxwMSQiXRmSQterwZWiICuQ64PQjj3z40uQF-VHZC38QG0BVtl-bkn0P3IjPTsTsl7WBaaOSilp4Qhe12T0SRnv8abXcRwW3_HyVnuxQly_OsZzZry4ElxuXCSfFP2b4D2-Q";

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

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

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  String _response = '';
  String _loading = "Loading...";

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

    // TODO, don't forget to init the MyFatoorah Plugin with the following line
    MFSDK.init(baseUrl, regularPaymentToken);

    // (Optional) un comment the following lines if you want to set up properties of AppBar.

//    MFSDK.setUpAppBar(
//      title: "MyFatoorah Payment",
//      titleColor: Colors.white,  // Color(0xFFFFFFFF)
//      backgroundColor: Colors.black, // Color(0xFF000000)
//      isShowAppBar: true); // For Android platform only

    // (Optional) un comment this line, if you want to hide the AppBar.
    // Note, if the platform is iOS, this line will not affected

//    MFSDK.setUpAppBar(isShowAppBar: false);
  }

  /*
    Send Payment
   */
  void sendPayment() {
    var request = MFSendPaymentRequest(
        invoiceValue: 0.100,
        customerName: "Customer name",
        notificationOption: MFNotificationOption.LINK);

    MFSDK.sendPayment(
        MFAPILanguage.EN,
        request,
        (MFResult<MFSendPaymentResponse> result) => {
              if (result.isSuccess())
                {
                  setState(() {
                    print(result.response.toJson());
                    _response = result.response.toJson().toString();
                  })
                }
              else
                {
                  setState(() {
                    print(result.error.toJson());
                    _response = result.error.message;
                  })
                }
            });

    setState(() {
      _response = _loading;
    });
  }

  /*
    Initiate Payment
   */
  void initiatePayment() {
    var request = new MFInitiatePaymentRequest(5.5, MFCurrencyISO.KUWAIT_KWD);

    MFSDK.initiatePayment(
        request,
        MFAPILanguage.EN,
        (MFResult<MFInitiatePaymentResponse> result) => {
              if (result.isSuccess())
                {
                  setState(() {
                    print(result.response.toJson());
                    _response = result.response.toJson().toString();
                  })
                }
              else
                {
                  setState(() {
                    print(result.error.toJson());
                    _response = result.error.message;
                  })
                }
            });

    setState(() {
      _response = _loading;
    });
  }

  /*
    Execute Regular Payment
   */
  void executeRegularPayment() {
    // The value "1" is the paymentMethodId of KNET payment method.
    // You should call the "initiatePayment" API to can get this id and the ids of all other payment methods
    String paymentMethod = "1";

    var request = new MFExecutePaymentRequest(paymentMethod, "100");

    MFSDK.executePayment(
        context,
        request,
        MFAPILanguage.EN,
        (String invoiceId, MFResult<MFPaymentStatusResponse> result) => {
              if (result.isSuccess())
                {
                  setState(() {
                    print(invoiceId);
                    print(result.response.toJson());
                    _response = result.response.toJson().toString();
                  })
                }
              else
                {
                  setState(() {
                    print(invoiceId);
                    print(result.error.toJson());
                    _response = result.error.message;
                  })
                }
            });

    setState(() {
      _response = _loading;
    });
  }

  /*
    Execute Direct Payment
   */
  void executeDirectPayment() {
    // The value "2" is the paymentMethodId of Visa/Master payment method.
    // You should call the "initiatePayment" API to can get this id and the ids of all other payment methods
    String paymentMethod = "2";

    var request = new MFExecutePaymentRequest(paymentMethod, "100");

//    var mfCardInfo = new MFCardInfo(cardToken: "Put your token here");

    var mfCardInfo = new MFCardInfo(
        cardNumber: "2223000000000007",
        expiryMonth: "05",
        expiryYear: "21",
        securityCode: "100",
        bypass3DS: true,
        saveToken: true);

    MFSDK.executeDirectPayment(
        context,
        request,
        mfCardInfo,
        MFAPILanguage.EN,
        (String invoiceId, MFResult<MFDirectPaymentResponse> result) => {
              if (result.isSuccess())
                {
                  setState(() {
                    print(invoiceId);
                    print(result.response.toJson());
                    _response = result.response.toJson().toString();
                  })
                }
              else
                {
                  setState(() {
                    print(invoiceId);
                    print(result.error.toJson());
                    _response = result.error.message;
                  })
                }
            });

    setState(() {
      _response = _loading;
    });
  }

  /*
    Execute Direct Payment with Recurring
   */
  void executeDirectPaymentWithRecurring() {
    // The value "2" is the paymentMethodId of Visa/Master payment method.
    // You should call the "initiatePayment" API to can get this id and the ids of all other payment methods
    String paymentMethod = "2";

    var request = new MFExecutePaymentRequest(paymentMethod, "100");

    var mfCardInfo = new MFCardInfo(
        cardNumber: "2223000000000007",
        expiryMonth: "05",
        expiryYear: "21",
        securityCode: "100",
        bypass3DS: true,
        saveToken: true);

    int intervalDays = 5;

    MFSDK.executeDirectPaymentWithRecurring(
        context,
        request,
        mfCardInfo,
        intervalDays,
        MFAPILanguage.EN,
        (String invoiceId, MFResult<MFDirectPaymentResponse> result) => {
              if (result.isSuccess())
                {
                  setState(() {
                    print(invoiceId);
                    print(result.response.toJson());
                    _response = result.response.toJson().toString();
                  })
                }
              else
                {
                  setState(() {
                    print(invoiceId);
                    print(result.error.toJson());
                    _response = result.error.message;
                  })
                }
            });

    setState(() {
      _response = _loading;
    });
  }

  /*
    Payment Enquiry
   */
  void getPaymentStatus() {
    var request = MFPaymentStatusRequest(invoiceId: "12345");

    MFSDK.getPaymentStatus(
        MFAPILanguage.EN,
        request,
        (MFResult<MFPaymentStatusResponse> result) => {
              if (result.isSuccess())
                {
                  setState(() {
                    print(result.response.toJson());
                    _response = result.response.toJson().toString();
                  })
                }
              else
                {
                  setState(() {
                    print(result.error.toJson());
                    _response = result.error.message;
                  })
                }
            });

    setState(() {
      _response = _loading;
    });
  }

  /*
    Cancel Token
   */
  void cancelToken() {
    MFSDK.cancelToken(
        "Put your token here",
        MFAPILanguage.EN,
        (MFResult<bool> result) => {
              if (result.isSuccess())
                {
                  setState(() {
                    print(result.response.toString());
                    _response = result.response.toString();
                  })
                }
              else
                {
                  setState(() {
                    print(result.error.toJson());
                    _response = result.error.message;
                  })
                }
            });

    setState(() {
      _response = _loading;
    });
  }

  /*
    Cancel Recurring Payment
   */
  void cancelRecurringPayment() {
    MFSDK.cancelRecurringPayment(
        "Put RecurringId here",
        MFAPILanguage.EN,
        (MFResult<bool> result) => {
              if (result.isSuccess())
                {
                  setState(() {
                    print(result.response.toString());
                    _response = result.response.toString();
                  })
                }
              else
                {
                  setState(() {
                    print(result.error.toJson());
                    _response = result.error.message;
                  })
                }
            });

    setState(() {
      _response = _loading;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Center(
          child: Column(children: [
            IntrinsicWidth(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: [
                  Padding(
                    padding: EdgeInsets.all(5.0),
                  ),
                  RaisedButton(
                    child: Text('Send Payment'),
                    onPressed: sendPayment,
                  ),
                  RaisedButton(
                    child: Text('Initiate Payment'),
                    onPressed: initiatePayment,
                  ),
                  RaisedButton(
                    child: Text('Execute Regular Payment'),
                    onPressed: executeRegularPayment,
                  ),
                  RaisedButton(
                    child: Text('Execute Direct Payment'),
                    onPressed: executeDirectPayment,
                  ),
                  RaisedButton(
                    child: Text('Execute Direct Payment with Recurring'),
                    onPressed: executeDirectPaymentWithRecurring,
                  ),
                  RaisedButton(
                    child: Text('Cancel Recurring Payment'),
                    onPressed: cancelRecurringPayment,
                  ),
                  RaisedButton(
                    child: Text('Cancel Token'),
                    onPressed: cancelToken,
                  ),
                  RaisedButton(
                    child: Text('Get Payment Status'),
                    onPressed: getPaymentStatus,
                  ),
                  Padding(
                    padding: EdgeInsets.all(8.0),
                  ),
                ],
              ),
            ),
            Container(
              child: Expanded(
                flex: 1,
                child: SingleChildScrollView(
                  child: Text(_response),
                ),
              ),
            ),
          ]),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  myfatoorah_flutter: ^1.0.3

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

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-0.96 points)

676 out of 677 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/model/MFError.dart.

Run flutter format to format lib/model/MFError.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
back_button_interceptor ^4.2.3 4.2.3
flutter 0.0.0
flutter_webview_plugin ^0.3.10+1 0.3.10+2
http ^0.12.0+4 0.12.0+4
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.11 1.14.12
http_parser 3.1.4
meta 1.1.8
path 1.6.4
pedantic 1.9.0
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
vector_math 2.0.8
Dev dependencies
flutter_test