myfatoorah_flutter 1.0.0 copy "myfatoorah_flutter: ^1.0.0" to clipboard
myfatoorah_flutter: ^1.0.0 copied to clipboard

outdated

myfatoorah_flutter plugin.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter_test/flutter_test.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 BASE_URL = "https://apitest.myfatoorah.com";

// Token for regular payment
final String REGULAR_PAYMENT_TOKEN = "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 DIRECT_PAYMENT_TOKEN = "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...";

  _MyHomePageState() {
    // TODO, don't forget to init the MyFatoorah Plugin with the following line
    MFSDK.init(BASE_URL, REGULAR_PAYMENT_TOKEN);

    // (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(() {
          _response = result.response.toJson().toString();
        })
      }
      else {
        setState(() {
          _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(() {
          _response = result.response.toJson().toString();
        })
      }
      else {
        setState(() {
          _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);
              _response = result.response.toJson().toString();
            })
          }
          else {
            setState(() {
              print(invoiceId);
              _response = result.error.message;
            })
          }
        });

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

  /*
    Execute Direct Payment
   */
  Future<void> executeDirectPayment() async {

    // 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("2223000000000007", "05", "21", "100",
        bypass3DS: true, saveToken: true);

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

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

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

  /*
    Execute Direct Payment with Recurring
   */
  Future<void> executeDirectPaymentWithRecurring() async {

    // 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("2223000000000007", "05", "21", "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);
              _response = result.response.toJson().toString();
            })
          }
          else {
            setState(() {
              print(invoiceId);
              _response = result.error.message;
            })
          }
        });

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

  @override
  Widget build(BuildContext context) {

    return Material(
      child: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            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,
            ),

            Container(
              padding: EdgeInsets.all(20.0),
              child:  Text(_response),
            ),

          ],
        ),
      ),
    );
  }
}