The AmwalPay Flutter SDK provides a convenient way to integrate AmwalPay payment functionality into your Flutter applications. This documentation will guide you through the process of setting up and using the AmwalPay
class.
Before using the AmwalPay Flutter SDK, make sure you have the following:
- Flutter SDK installed on your development machine
- A Flutter project set up and configured
To use the AmwalPay Flutter SDK, add the following dependency to your project's pubspec.yaml
file:
dependencies:
amwal_pay: ^0.6.1
Follow these steps to install the necessary dependencies for iOS:
1 Open the ios directory in your Flutter project.
2 Open a terminal and navigate to the ios directory of your Flutter project:
cd ios
3 Run the following command to deintegrate any existing CocoaPods dependencies:
pod deintegrate
4 Once the deintegration is complete, run the following command to install the dependencies:
pod install
This command will download and install the necessary CocoaPods dependencies for your iOS project.
Follow these steps to install the necessary dependencies for Android:
-
Associate your app with Amwal's Digital Asset Links.
-
Lastly, update the MainActivity class in your Android project for the Flutter plugin
In the file app/src/main/kotlin/../MainActivity
, update the import statement & class declaration :
// Before:
import io.flutter.embedding.android.FlutterActivity
// After:
import io.flutter.embedding.android.FlutterFragmentActivity
Update the class declaration to extend FlutterFragmentActivity: kotlin
// Before:
class MainActivity: FlutterActivity() {
}
// After:
class MainActivity: FlutterFragmentActivity() {
}
import necessary package.
import 'package:amwal_pay/amwal_pay.dart';
You can use our widget or use the plugin directly.
body: Center(
child: AmwalPayWidget(
merchantId: 'your_merchant_id',
amount: 10.0,
phoneNumber: "your_phone_number", // has to be full phone number with country code ex +201234567890
refId: 'your_ref_id', // optional can be null
orderId: 'your_order_id', // optional can be null
language: AmwalPayLanguage.Arabic,// optional can be null
onPaymentFinished: (TransactionStatus status) {
switch (status.type) {
case TransactionStatusType.success:
// Cast to specific class to access the transaction ID or other relevant info.
print('Transaction Success with ID: ${(status as TransactionSuccess).transactionId}');
break;
case TransactionStatusType.failure:
// Cast and access specific failure details.
print('Transaction Failed. ${(status as TransactionFailure)}, Message: ${status.message}');
break;
case TransactionStatusType.cancel:
print('Transaction Cancelled');
break;
}
},
),
)
Create an instance of the AmwalPay class, providing the required parameters:
AmwalPay amwalPay = AmwalPayBuilder('your_merchant_id')
.phoneNumber('your_phone_number')
.refId('your_ref_id') // optional can be null
.orderId('your_order_id') // optional can be null
.language(AmwalPayLanguage.Arabic) // optional can be null
.build();
Start a payment transaction by calling the startPayment method with the desired amount:
TransactionStatus status = await amwal.startPayment(amount);
switch (status.type) {
case TransactionStatusType.success:
// Cast to specific class to access the transaction ID or other relevant info.
print('Transaction Success with ID: ${(status as TransactionSuccess).transactionId}');
break;
case TransactionStatusType.failure:
// Cast and access specific failure details.
print('Transaction Failed. ${(status as TransactionFailure)}, Message: ${status.message}');
break;
case TransactionStatusType.cancel:
print('Transaction Cancelled');
break;
}
The startPayment method returns a Future that resolves to a String representing the payment result. You can handle the result according to your application's needs.
Congratulations! You have successfully integrated the AmwalPay Flutter SDK into your Flutter application. You can now accept payments using AmwalPay in your app. For more information and advanced usage, refer to the AmwalPay SDK documentation.
If you encounter any issues or have further questions, please refer to the official AmwalPay support for assistance.