Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

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: ^2.1.0	    
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 api url here>, <put your api token key here>);
  • you can get the api url and api token key for testing from here
  • once your testing is finished, simply replace the testing api url / api token key 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: false, savetoken: true);

    mfsdk.executedirectpayment(context, request, mfcardinfo, mfapilanguage.en,
    (string invoiceid, mfresult 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(context, 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)
      }
    });

embedded payment (new)

introduction

if you would like your customer to complete the payment on your checkout page without being redirected to another page (except for the 3d secure page) and the pci dss compliance is a blocker, myfatoorah embedded payment feature is your optimum solution.

usage

step 1:

create instance of mfpaymentcardview and add it to your build() function like the following:

  @override
  widget build(buildcontext context) {
    return createpaymentcardview();
  }

  createpaymentcardview() {
    mfpaymentcardview = mfpaymentcardview();
    return mfpaymentcardview;
  }
note: you could custom a lot of properties of the payment card view like the following:
mfpaymentcardview = mfpaymentcardview(
      inputcolor: colors.red,
      labelcolor: colors.yellow,
      errorcolor: colors.blue,
      bordercolor: colors.green,
      fontsize: 14,
      borderwidth: 1,
      borderradius: 10,
      cardheight: 220,
      cardholdernamehint: "card holder name hint",
      cardnumberhint: "card number hint",
      expirydatehint: "expiry date hint",
      cvvhint: "cvv hint",
      showlabels: true,
      cardholdernamelabel: "card holder name label",
      cardnumberlabel: "card number label",
      expirydatelabel: "expiry date label",
      cvvlabel: "securtity code label",
    );
step 2:

you need to call initiatesession() function to create session. you need to do this for each payment separately. session is valid for only one payment. and inside it’s success state, call load() function and pass it the session response, to load the payment card view on the screen, like the following:

void initiatesession() {
    mfsdk.initiatesession((mfresult<mfinitiatesessionresponse> result) => {
      if(result.issuccess()) 
        mfpaymentcardview.load(result.response!)
      else
        print("response: " + result.error!.tojson().tostring().tostring());
    });
  }
note: the initiatesession() function should called after mfsdk.init() function (that we mentioned above).
step 3:

after that, you need to handle your pay button to call the pay() function, copy the below code to your pay event handler section:

var request = mfexecutepaymentrequest.constructor(0.100);

mfpaymentcardview.pay(
    request,
    mfapilanguage.en,
        (string invoiceid, mfresult<mfpaymentstatusresponse> result) =>
    {
      if (result.issuccess())
        {
          setstate(() {
            print("response: " + result.response!.tojson().tostring());
            _response = result.response!.tojson().tostring();
          })
        }
      else
        {
          setstate(() {
            print("error: " + result.error!.tojson().tostring());
            _response = result.error!.message!;
          })
        }
    });

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.