Last updated:
0 purchases
flutter payfort sdk
flutter_payfort_sdk #
Please before use this package read PAYFORT documentation .
Platform Support #
This plugin currently works only on android.
If you are a developer and want to add iOS support or fixing bugs you are welcome you can visit my Github repository flutter_payfort_sdk.
Usage #
To use this plugin, add flutter_payfort_sdk as a dependency in your pubspec.yaml file
ScreenShots #
add custom colors: #
Example #
Import the library.
import 'package:flutter_payfort_sdk/flutter_payfort_sdk.dart';
copied to clipboard
1. getDeviceId #
String? deviceId = await FlutterPayfortSdk.getDeviceId();
copied to clipboard
2. create SDK token #
#####You can use our classes CreateTokenRequest and CreateTokenResponse to send data to server and return data from it
###(or you can use your own request and response but it is important to return sdkToken and merchantReference to use it in payfortsdk)
CreateTokenRequest createTokenRequest = CreateTokenRequest(
serviceCommand: "SDK_TOKEN",
accessCode: dotenv.get("AccessCode"),
merchantIdentifier: dotenv.get("MerchantIdentifier"),
language: languageCode,
deviceId: deviceId);
http.Response result = await http.post(
Uri.parse("${dotenv.get("BaseUrl")}/createSDKToken"),
body: createTokenRequest.toJson());
//3. return response with sdk_token and merchantReference
CreateTokenResponse tokenRes =
CreateTokenResponse.fromJson(jsonDecode(result.body));
copied to clipboard
3. goToPaymentActivity #
if (tokenRes.success != null && tokenRes.success == true) {
//create object paymentActivityArgs which holds all required arguments for payfort sdk and payment activity
PaymentActivityArgs paymentActivityArgs = PaymentActivityArgs(
environment: ENVIRONMENT.test,
command: COMMAND.purchase,
customerEmail: dotenv.get("CustomerEmail"),
languageCode: languageCode,
currency: "SAR",
amount: amount.toString(),
sdkToken: tokenRes.result!.sdkToken,
merchantReference: tokenRes.merchantReference,
loadingMessage:
languageCode == "ar" ? "جاري الدفع" : "Payment in Progress");
// open native activity and send paymentActivityArgs
PaymentActivityResult? paymentActivityResult =
await FlutterPayfortSdk.goToPaymentActivity(paymentActivityArgs);
//return result from native activity
if (paymentActivityResult != null &&
paymentActivityResult.success != null &&
paymentActivityResult.success == true) {
Fluttertoast.showToast(
msg: "${paymentActivityResult.responseMessage}");
} else {
Fluttertoast.showToast(msg: "payment process is failed");
}
} else {
Fluttertoast.showToast(msg: "payment process is failed");
}
copied to clipboard
4. customizePaymentActivityColors #
// you can add custom colors - (OPTIONAL)
// When you do not use this function the default colors will use
await FlutterPayfortSdk.customizePaymentActivityColors(
actionBarBackgroundColor:Colors.deepPurple,
actionBartTitleColor: Colors.white,
statusBarColor: Colors.deepPurpleAccent.shade100,
payButtonBackgroundColor: Colors.deepPurpleAccent,
payButtonTextColor: Colors.white
);
copied to clipboard
enum classes #
/// select command name to send it to payfort sdk
enum COMMAND{
purchase,
authorization
}
/// select environment to send it to payfort sdk
/// test for test environment
/// and prod for production environment
enum ENVIRONMENT{
test,
prod
}
copied to clipboard
See the main.dart in the example for a complete example.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.