khalti_sdk 1.0.1 copy "khalti_sdk: ^1.0.1" to clipboard
khalti_sdk: ^1.0.1 copied to clipboard

An official Flutter plugin for Khalti Payment Gateway, combining core functionalities and Flutter UI into a single unified package.

Khalti Logo

Khalti Payment Gateway for Flutter

An official-grade SDK for seamless payment integration in Nepal.

Pub Khalti Docs BSD-3 License GitHub issues


🌟 Introduction #

Khalti is the leading payment gateway, digital wallet, and API provider in Nepal. This SDK simplifies the integration process, allowing your Flutter app to accept payments through:

  • Khalti Wallet
  • eBanking (Partner Banks)
  • Mobile Banking
  • SCT/VISA Cards
  • connectIPS

Note

This package is a cloned and enhanced version of the original khalti_checkout_flutter and khalti_checkout_core packages, unified into a single, easy-to-use SDK.

Developed with ❤️ by Ayush Timalsina.


📱 Supported Platforms #

Android iOS
✔️ ✔️

🚀 Getting Started #

1. Installation #

Add khalti_sdk to your pubspec.yaml:

dependencies:
  khalti_sdk: ^1.0.1

2. Platform Setup #

No additional configuration is required for Android or iOS.


🛠️ Usage #

Initialize Khalti #

It is recommended to initialize the Khalti object within your initState.

late final Future<Khalti> khalti;

@override
void initState() {
  super.initState();
  
  final payConfig = KhaltiPayConfig(
    publicKey: '__your_public_key__', 
    pidx: '__generated_pidx__', // Generate via server-side POST
    environment: Environment.prod,
  );

  khalti = Khalti.init(
    payConfig: payConfig,
    onPaymentResult: (result, khalti) {
      if (result.isSuccess) {
        log('Payment Success: ${result.payload?.transactionId}');
      } else {
        log('Payment Status: ${result.status}');
      }
      khalti.close(context);
    },
    onMessage: (khalti, {description, statusCode, event, needsPaymentConfirmation}) {
      log('Message: $description (Event: $event)');
      if (needsPaymentConfirmation == true) {
        khalti.verify();
      }
    },
    onReturn: () => log('Successfully redirected to return_url.'),
  );
}

Launching the UI #

ElevatedButton(
  onPressed: () async {
    final instance = await khalti;
    instance.open(context);
  },
  child: const Text('Pay with Khalti'),
)

⚙️ Configuration Details #

KhaltiPayConfig #

  • publicKey: Your live/test public key from the Khalti dashboard.
  • pidx: Unique product identifier (generate this server-side).
  • environment: Environment.prod or Environment.dev.

KhaltiEvent #

The onMessage callback provides events to help you handle different scenarios:

  • kpgDisposed: User closed the payment page.
  • returnUrlLoadFailure: Failed to load the return URL.
  • networkFailure: General network issues.
  • paymentLookupFailure: Error during status verification.

👨‍💻 Developed By #

This SDK is maintained by Ayush Timalsina.


📄 License #

This project is licensed under the BSD 3-Clause License. See the LICENSE file for the full text.

4
likes
160
points
68
downloads

Documentation

Documentation
API reference

Publisher

verified publisherayushtimalsina.com.np

Weekly Downloads

An official Flutter plugin for Khalti Payment Gateway, combining core functionalities and Flutter UI into a single unified package.

Homepage
Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

Dependencies

device_info_plus, equatable, flutter, flutter_inappwebview, http, internet_connection_checker_plus, meta, package_info_plus, url_launcher

More

Packages that depend on khalti_sdk