fawry_nfc_sdk 0.0.1
fawry_nfc_sdk: ^0.0.1 copied to clipboard
The Fawry NFC SDK enables NFC functionality in Flutter apps for utility bill payments.
Fawry NFC SDK Documentation #
Overview #
The Fawry NFC SDK allows developers to integrate Fawry's NFC capabilities into their Flutter applications seamlessly. This SDK facilitates tasks such as reading and writing to NFC cards, with a focus on utility bill payments like electricity, gas, and water.
Features #
- Read NFC Card: Enables scanning NFC cards to retrieve relevant information.
- Write to NFC Card: Allows encoding data onto NFC cards for various purposes.
Prerequisites #
Before using the Fawry NFC SDK, ensure the following prerequisites are met:
- Flutter development environment is set up.
- Fawry NFC SDK is successfully integrated into your project.
To integrate the SDK, add the following dependency to your pubspec.yaml file:
dependencies:
fawry_nfc_sdk: ^version_number
Replace ^version_number with the latest version of the Fawry NFC SDK.
Android Setup #
To integrate with Android, update the minimum SDK version to 21 or higher in your build.gradle file:
android {
compileSdkVersion flutter.compileSdkVersion
minSdkVersion 21
// ...
}
In your build.gradle, add the following code to the buildscript and allprojects blocks:
repositories {
google()
mavenCentral()
maven { url 'YOU WILL RECEIVE THIS FROM FAWWRY SUPPORT ALONG WITH CREDENTIALS' }
}
iOS Setup #
As of the current version, the Fawry NFC SDK does not support iOS. However, the development team is actively working on extending compatibility to iOS devices in future updates.
Usage #
-
Initialize SDK Callback
Create an
initSDKCallback()function to initialize the callback mechanism to receive responses from the Fawry NFC SDK. It sets up a stream listener to handle callback results.Future<void> initSDKCallback() async { try { _fawryCallbackResultStream = FawryNfcSdk.instance.callbackResultStream().listen((event) { setState(() { ResponseStatus response = ResponseStatus.fromJson(jsonDecode(event)); handleResponse(response); }); }); } catch (ex) { debugPrint(ex.toString()); } } -
Handle Responses
Create a
handleResponse()function to process responses received from the Fawry NFC SDK. It can -for example -log the response details and updates the UI with the response message.void handleResponse(ResponseStatus response) { debugPrint( '======== Response ========\n$response\n==========================='); setState(() { printedMessage += '\n===========================\n======== Response ========\n$response'; }); }Access any response properties as needed. The
ResponseStatusclass contains the status of a response from the Fawry NFC SDK, including:status: Indicates the response status.message: Provides additional information about the response.data: Includes the data returned from the card.
-
Select Card Type
Choose a card type for scanning or writing. For example:
CardType selectedCardType = CardType.ELECT;Available card types are:
enum CardType { WSC, ELECT, GAS, } -
Read from NFC Card
Use the
_readNFC()function to start scanning an NFC card. This function prompts the Fawry NFC SDK to retrieve data from the NFC card when the "Scan Card" action is triggered.Future<void> _readNFC() async { try { setState(() { printedMessage = "Please Put The Card To Scan"; }); await FawryNfcSdk.instance.readNFC(cardType: selectedCardType); } catch (e) { debugPrint('Error reading from NFC: $e'); } } -
Write to NFC Card
Utilize the
_writeNFC()function to encode data onto an NFC card. This function is triggered by pressing the "Write on Card" action, and it encodes the provided information onto the NFC card.Future<void> _writeNFC() async { try { setState(() { printedMessage = "Please Put The Card To Write"; }); await FawryNfcSdk.instance.writeNFC( cardType: selectedCardType, billEncryptInfoECMC: "<billEncryptInfoECMC>", cardMetaData: "<cardMetaData>", originalBillingAccount: "<originalBillingAccount>", ); } catch (e) { debugPrint('Error writing to NFC: $e'); } }