fawry_sdk 0.0.4+1 copy "fawry_sdk: ^0.0.4+1" to clipboard
fawry_sdk: ^0.0.4+1 copied to clipboard

outdated

Fawry Plugin

Fawry SDK #

fawry_sdk is a cross-platform plugin that helps your app to integrate with Fawry native Android/IOS SDKs.

Getting Started #

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

dependencies:
  fawry_sdk: ^0.0.4+1

Android Setup #

Manifest

You have to edit AndroidManifest.xml file with following.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" />
        <application
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="flutter_fawry_sdk"
        tools:replace="android:allowBackup,android:label"> -->if you're not defining a label remove 'android:label' from tools:replace
    </appliaction>
</manifest>

build.gradle

Download this file, and put it in app/libs directory, in android module.

Then add flatDir { dirs 'libs' } to 'app' build.gradle as following

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

Finally, Update minimum SDK version to be 21 or hieghr, to meet the specs of our native android SDK

In build.gradle modify 'minSdkVersion'

android {
    compileSdkVersion flutter.compileSdkVersion
    minSdkVersion 21
    ...
}

iOS Setup #

Just Need XCode 13.2.x and SWIFT 5.5.x.

Usage #

You just have to import the package with

import 'package:fawry_sdk/fawry_sdk.dart';

Then, you need to initialize the SDK. To initialize the SDK you need to pass the follwoing variables to the plugin

  • launchModel: where you can define all data needed by FawrySDK for payment to be done.
  • lang: the language that the SDK will displayed with, We currently support English & Arabic
  • baseURL: a URL provided by our support team
Example
await FawrySdk.instance.init(
      launchModel: fawryLaunchModel,
      baseURL: "BASE_URL",
      lang: FawrySdk.LANGUAGE_ENGLISH or FawrySdk.LANGUAGE_ARABIC);

Building FawryLaunchModel #

As mentioned before, FawryLaunchModel is mandatory to initialize FawrySDK, in this model you can define all the attributes needed for the payment process, some of these attributes are mandatory and some are optional.

FawryLaunchModel – mandatory/optional parameters: -

i. LaunchCustomerModel (optional) – parameters

  1. customerName (optional)
  2. customerEmail (optional - Receives an email with the receipt after the payment is complete)
  3. customerMobile (optional - Receives an SMS with the reference number and payment details)

ii. ChargeItem -> parameters

  1. Price (mandatory)
  2. Quantity (mandatory)
  3. itemId (mandatory)
  4. Description (optional)

iii. LaunchMerchantModel – parameters

  1. merchantCode (provided by support – mandatory)
  2. merchantRefNum (random 10 alphanumeric digits – mandatory)

iv. allow3DPayment (to allow 3dsecure payment) v. secretCode (provided by support) vi. signature (generated by you) vii. skipLogin (you can skip login screen that takes email and mobile) and default value true viii. skipReceipt (to skip the receipt screen) and default value false

Example #

 BillItem item = BillItem(
        itemId: "ITEM_ID",
        description: "",
        quantity: 4,
        price: 15);
List<BillItem>? chargeItems = [item];

LaunchCustomerModel customerModel = LaunchCustomerModel(
        customerName: "John Doe",
        customerEmail: "john.doe@xyz.com",
        customerMobile: "+201000000000");

LaunchMerchantModel merchantModel = LaunchMerchantModel(
      merchantCode: "MERCHANT_CODE",
      merchantRefNum: "MERCHANT_REF_NUM",
      secureKey: "SECURE_KEY or SECRET_CODE");

FawryLaunchModel model = FawryLaunchModel(
      allow3DPayment: true,
      chargeItems: chargeItems,
      launchCustomerModel: customerModel,
      launchMerchantModel: merchantModel,
      skipLogin: true,
      skipReceipt: false);

Now, you can stream the result data that came from SDK.

  FawrySdk.instance.callbackResultStream().listen((event) {
    setState(() {
          ResponseStatus response = ResponseStatus.fromJson(jsonDecode(event));
          switch (response.status) {
            case FawrySdk.RESPONSE_SUCCESS:
              {
                //Success status
                debugPrint('Message : ${response.message}');
                //Success json response
                debugPrint('Json Response : ${response.data}');
              }
              break;
            case FawrySdk.RESPONSE_ERROR:
              {
                debugPrint('Error : ${response.message}');
              }
              break;
          }
        });
     });