ngenius_flutter_sdk 1.0.4 copy "ngenius_flutter_sdk: ^1.0.4" to clipboard
ngenius_flutter_sdk: ^1.0.4 copied to clipboard

N-Genius Flutter SDK provides an easy-to-use integration for handling payments using N-Genius APIs in Flutter applications.

N-Genius Flutter SDK #

N-Genius Flutter SDK provides an easy-to-use integration for handling payments using N-Genius APIs in Flutter applications.

📱 Platform Compatibility #

  • Android
android_ngenius_gif
  • iOS ✅ (Minimum deployment target: iOS 12.0)
ios_ngenius_gif

⚙️ Android Configuration #

Tested Environment #

This plugin has been tested with:

The example no longer applies the kotlin-android plugin directly. Its gradle.properties currently retains Flutter's AGP 9 compatibility flags, so this branch should not yet be described as a complete built-in Kotlin migration.

Project-Level build.gradle Changes #

Since N-Genius SDK is a JitPack dependency, add the following line inside the allprojects repositories block in your project-level android/build.gradle file:

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' } // Add this line
    }
}

The example app already includes this repository and the android.permission.INTERNET permission.

🍏 iOS Configuration #

No additional configuration is required for iOS.

🔄 N-Genius Response Model #

The plugin returns a response object containing a message and a code. Below are the possible response scenarios:

🛑 Transaction Cancellation & Errors #

Condition Message Code
User cancels the transaction CANCELLED_BY_USER 401
Order expired or generic error STATUS_GENERIC_ERROR -1
Payment failed STATUS_PAYMENT_FAILED 0

✅ Successful Payment Responses #

🟢 Android

Payment Status Message Code
Payment authorized PAYMENT_SUCCESSFUL 1
Payment captured PAYMENT_SUCCESSFUL 2
Payment purchased PAYMENT_SUCCESSFUL 3
Post authorization review PAYMENT_SUCCESSFUL 4

🍏 iOS

The native iOS N-Genius SDK does not provide specific statuses like authorized, captured, or purchased. Instead, it returns a generic success response:

Condition Message Code
Transaction successful PAYMENT_SUCCESSFUL 200

🚀 Get Started with N-Genius Flutter SDK #

  1. Install the plugin in your Flutter project.
  2. Configure Android settings as mentioned above.
  3. Create an order using the N-Genius APIs on your backend.
  4. Pass the complete order response to the plugin to launch the payment flow.

Run the Example App #

The example app can create sandbox orders directly for easier SDK testing. Open its Config tab and enter the API key value without the Basic prefix, the outlet reference, and optionally a different base URL. You can also launch it with:

cd example
flutter pub get
flutter run \
  --dart-define=NGENIUS_API_KEY=your_api_key \
  --dart-define=NGENIUS_OUTLET_REF=your_outlet_reference

The default base URL is https://api-gateway.sandbox.ngenius-payments.com. Override it with --dart-define=NGENIUS_BASE_URL=... when required.

Security: Direct access-token and order requests are included only to make the example easy to test. Never ship an N-Genius API key in a production mobile app. Create tokens and orders on a trusted backend and return the order object to the app.


Example Implementation (Normal Payment)

class NgeniusExample extends StatelessWidget {
  const NgeniusExample({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('N-Genius Example'),
      ),
      body: Center(
        child: ElevatedButton(
            onPressed: () async {
              final ngeniusFlutterSdk = NgeniusFlutterSdk();
              NGeniusResponseModel ngeniusResponse = await ngeniusFlutterSdk.launchCardPayment(orderJsonObject: {});
              if (context.mounted) {
                if (ngeniusResponse.message == "PAYMENT_SUCCESSFUL") {
                  ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Transaction Successful")));
                } else {
                  ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                      content: Text(
                          "Transaction Failed :: code :: ${ngeniusResponse.code} :: message :: ${ngeniusResponse.message}")));
                }
              }
            },
            child: Text("Launch Card Payment")),
      ),
    );
  }
}

Example Implementation (for using Saved Cards)

Note: The key difference when using a saved card is in the order creation step. You must pass a savedCard object (NGeniusSavedCardModel) in your createOrder request body. If recaptureCsc is set to true, the user will be prompted to enter their CVV — you can skip this by passing the cvv directly to launchSavedCardPayment.

class NgeniusSavedCardExample extends StatelessWidget {
  const NgeniusSavedCardExample({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('N-Genius Saved Card Example'),
      ),
      body: Center(
        child: ElevatedButton(
            onPressed: () async {
              // 1. Build your saved card model from your stored card data
              final savedCard = NGeniusSavedCardModel(
                maskedPan: "400555******0001",
                expiry: "2025-12",
                cardholderName: "John Doe",
                scheme: "VISA",
                cardToken: "your-card-token",
                recaptureCsc: true, // true = user will be prompted for CVV
              );

              // 2. Call YOUR backend/API to create the order.
              // This is not part of the plugin — you are responsible for
              // implementing this API call following the N-Genius documentation:
              // https://docs.ngenius-payments.com/reference/two-stage-payments-orders
              // The savedCard object must be included in the request body.
              final Map<String, dynamic> orderJsonObject = await yourApiService.createOrder(
                amountValue: 10.50,
                currency: "AED",
                savedCard: savedCard,
              );

              // 3. Launch saved card payment
              // Pass cvv to skip the CVV page, or omit it to let the user enter it
              final ngeniusFlutterSdk = NgeniusFlutterSdk();
              NGeniusResponseModel ngeniusResponse = await ngeniusFlutterSdk.launchSavedCardPayment(
                orderJsonObject: orderJsonObject, 
                //cvv: "123" //If you want your UI to handle CVV
              );

              if (context.mounted) {
                if (ngeniusResponse.message == "PAYMENT_SUCCESSFUL") {
                  ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Transaction Successful")));
                } else {
                  ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                      content: Text(
                          "Transaction Failed :: code :: ${ngeniusResponse.code} :: message :: ${ngeniusResponse.message}")));
                }
              }
            },
            child: Text("Launch Saved Card Payment")),
      ),
    );
  }
}

🔄 N-Genius SavedCard Model #

Parameter Example DataType
maskedPan 400555******0001 String
expiry "2025-12" String
cardholderName "John Doe" String
scheme "VISA" String
cardToken "your-card-token" String
recaptureCsc true = user will be prompted for CVV boolean

Passing the Order JSON Object to launchCardPayment Method #

To pass the orderJsonObject to the launchCardPayment method, you need to provide it against the orderJsonObject key. To get the orderJsonObject, you must first call two APIs. It is recommended to call these APIs on the server-side, not on the mobile side, for security and performance reasons.

Steps to Get the Order JSON Object

1- Get the Access Token
First, you need to obtain the access token by following the official N-Genius documentation:
Request an Access Token

2- Get the Order Object
Once you have the access token, use it to call the API to get the order object. For more information, refer to the N-Genius documentation:
Two-Stage Payments Orders

Sample Order JSON Object

After calling the APIs, you will receive the N-Genius order object. You can check the structure of the order object by referring to the official sample here:
Order Object in Full


Getting the Saved-Card Token #

1- Ensure that Tokenization is enabled for your merchant account.

2- After a successful payment, retrieve the order details using the following endpoint: GET /transactions/outlets/{{outletId}}/orders/{{orderId}}

3- The saved card token is returned in the response at: _embedded.payment.savedCard.cardToken

You can use this token to perform future saved card payments without requiring the customer to re-enter their card details.


Test Payment Using N-Genius Test Cards #

You can test payment using test cards for N-Genius from the following link:
Sandbox Test Environment

For detailed documentation, refer to the official N-Genius API documentation.

Contributors #

Thanks to the people who have contributed to this package:

Ziad Hassan
Ziad Hassan

License #

This project is licensed under the MIT License.


📌 Note: If you encounter any issues, ensure all dependencies and configurations match the tested environment.

Happy coding! 🎉

7
likes
140
points
149
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

N-Genius Flutter SDK provides an easy-to-use integration for handling payments using N-Genius APIs in Flutter applications.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on ngenius_flutter_sdk

Packages that implement ngenius_flutter_sdk