fawry_sdk 1.0.92 fawry_sdk: ^1.0.92 copied to clipboard
Fawry Plugin
Fawry SDK Integration Guide #
Welcome to the comprehensive Fawry SDK Integration Guide. This guide will walk you through the seamless integration of Fawry's native Android and iOS SDKs into your Flutter projects for effortless payment integration.
Table of Contents #
- Getting Started
- SDK Initialization
- Customizing UI Colors
- Troubleshooting Release Mode
- Sample Project
Getting Started #
Adding Fawry SDK Plugin #
To begin, add the Fawry SDK plugin to your Flutter project's dependencies. Open your pubspec.yaml
file and add the following line:
dependencies:
fawry_sdk: ^1.0.92
Android Setup #
To integrate with Android, follow these steps:
- Open your
AndroidManifest.xml
file and insert the following code snippet inside the<application>
tag:
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="Your App Label"
tools:replace="android:label">
<!-- Remove 'android:label' from tools:replace if not defining a label -->
</application>
- Update the minimum SDK version to 21 or higher in your
build.gradle
file:
android {
compileSdkVersion flutter.compileSdkVersion
minSdkVersion 21
// ...
}
iOS Setup #
For iOS integration, follow these steps:
-
Set the minimum iOS version under "Deployment info" to 12.1 or higher in your
Runner
project in Xcode. -
Enhance pod distribution by adding the following code at the end of the pod file (
Podfile
):
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
end
end
end
Streaming Result Data #
You can stream the result data that comes from the Fawry SDK to handle different response scenarios using Flutter's stream functionality. Here's how you can achieve this:
late StreamSubscription? _fawryCallbackResultStream;
@override
void initState() {
super.initState();
initSDKCallback();
}
@override
void dispose() {
_fawryCallbackResultStream?.cancel();
super.dispose();
}
Future<void> initSDKCallback() async {
try {
_fawryCallbackResultStream =
FawrySdk.instance.callbackResultStream().listen((event) {
setState(() {
ResponseStatus response = ResponseStatus.fromJson(jsonDecode(event));
handleResponse(response);
});
});
} catch (ex) {
debugPrint(ex.toString());
}
}
void handleResponse(ResponseStatus response) {
switch (response.status) {
case FawrySdk.RESPONSE_SUCCESS:
{
debugPrint('Message: ${response.message}');
debugPrint('Json Response: ${response.data}');
}
break;
case FawrySdk.RESPONSE_ERROR:
{
debugPrint('Error: ${response.message}');
}
break;
case FawrySdk.RESPONSE_PAYMENT_COMPLETED:
{
debugPrint(
'Payment Completed: ${response.message}, ${response.data}');
}
break;
}
}
This will enable you to handle different responses and outcomes from the Fawry SDK in a more dynamic way. The handleResponse
method is where you can customize your actions based on the response status.
SDK Initialization #
To start using the Fawry SDK, follow these steps:
Building FawryLaunchModel #
The FawryLaunchModel
is essential to initialize the Fawry SDK. It contains both mandatory and optional parameters needed for the payment process.
LaunchCustomerModel (Optional) Parameters:
customerName
(optional)customerEmail
(optional - Receives an email with the receipt after payment completion)customerMobile
(optional - Receives an SMS with the reference number and payment details)
ChargeItem Parameters:
Price
(mandatory)Quantity
(mandatory)itemId
(mandatory)Description
(optional)
LaunchMerchantModel Parameters:
merchantCode
(provided by support – mandatory)merchantRefNum
(random 10 alphanumeric digits – mandatory)secureKey
(provided by support – mandatory)
Other Parameters:
allow3DPayment
(to allow 3D Secure payment)secretCode
(provided by support)signature
(generated by you)skipLogin
(can skip login screen that takes email and mobile, default value is true)skipReceipt
(to skip the receipt screen, default value is false)payWithCardToken
(Enables/disables user card tokenization; if enabled, definecustomerProfileId
in LaunchCustomerModel)paymentMethods
(optional; controls payment methods displayed to the user, e.g.,PaymentMethods.CREDIT_CARD
,PaymentMethods.ALL
)
Example #
Future<void> initiateSDK() async {
final item =
BillItem(itemId: 'ITEM_ID', description: 'Book', quantity: 5, price: 20);
//sorted list
final chargeItems = [item];
final customerModel = LaunchCustomerModel(
customerProfileId: '533518',
customerName: 'John Doe',
customerEmail: 'john.doe@xyz.com',
customerMobile: '+201000000000',
);
final merchantModel = LaunchMerchantModel(
merchantCode: "MERCHANT_CODE",
merchantRefNum: FawryUtils.randomAlphaNumeric(10),
secureKey: 'SECURE KEY OR SECRET CODE',
);
final model = FawryLaunchModel(
allow3DPayment: true,
chargeItems: chargeItems,
launchCustomerModel: customerModel,
launchMerchantModel: merchantModel,
skipLogin: true,
skipReceipt: true,
payWithCardToken: false,
paymentMethods: PaymentMethods.CREDIT_CARD,
);
await FawrySdk.instance.init(
launchModel: model,
baseURL: "https://atfawry.fawrystaging.com/",
lang: FawrySdk.LANGUAGE_ENGLISH,
// lang: FawrySdk.LANGUAGE_ARBIC, // FOR ARABIC VERSION
);
}
Customizing UI Colors #
Android #
-
Navigate to
android > app > src > main > res > values
. -
Create a new file named
colors.xml
. -
Add color values to
colors.xml
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="fawry_blue">#6F61C0</color> <!-- Set your primary color hex code -->
<color name="fawry_yellow">#A084E8</color> <!-- Set your secondary color hex code -->
</resources>
iOS #
-
In your project, navigate to
ios > Runner
. -
Create a new file named
Style.plist
. -
Add color values to
Style.plist
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>primaryColorHex</key>
<string>#6F61C0</string> <!-- Set your primary color hex code -->
<key>secondaryColorHex</key>
<string>#A084E8</string> <!-- Set your secondary color hex code -->
<key>tertiaryColorHex</key>
<string>#8BE8E5</string> <!-- Set your tertiary color hex code -->
<key>headerColorHex</key>
<string>#6F61C0</string> <!-- Set your header color hex code -->
</dict>
</plist>
- In Xcode, right-click on the
Runner
, select "Add Files to 'Runner'", and add theStyle.plist
file.
Troubleshooting Release Mode #
If you experience an issue in release mode not present in debug mode, you can address it by adding these rules to your Android app's build.gradle
:
// ... (previous code)
buildTypes {
release {
minifyEnabled false
shrinkResources false
// ...
}
}
Sample Project #
For a practical demonstration of Fawry SDK integration in a Flutter app, explore our sample project on GitHub:
Flutter Fawrypay Anonymous Sample
This project showcases the usage and seamless integration of the Fawry SDK for secure payment processing in your Flutter applications.
Feel free to dive into the sample project and leverage the guide to effortlessly integrate the Fawry SDK into your Flutter app.