Khalti in Flutter

Flutter Junction
CodeX
Published in
2 min readOct 11, 2022

Khalti is one of the digital payments in Nepal. In this story, we shall learn how to integrate Khalti into Flutter.

Getting Started

Integrating Khalti Payment Gateway requires three things.

  1. Khalti Account: For integrating the Khalti in Flutter, you need to have the Merchant Account which can only be created only if you have a Khalti account. You can easily create the Khalti account for free by visiting this link and clicking on Register.
  2. Merchant Account: After creating the Khalti account, you can now easily create the merchant account by visiting this link. After the verification process, you are redirected to the admin dashboard, where you can find the Keys in the Settings menu.
  3. Flutter Installed in the computer

Setup

For integrating Khalti in Flutter, we shall be using the package khalti_flutter. Add the khalti_flutter package in the dependencies of pubsec.yaml file.

dependencies:
....
khalti_flutter: ^2.1.0

Android

In your app’s AndroidManifest.xml, add these lines inside <activity>...</activity> tag:

<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="kpg" android:host="{your package name}" />
</intent-filter>

iOS

In your app’s Info.plist, add these properties:

<key>FlutterDeepLinkingEnabled</key>
<true/>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>kpg</string>
</array>
<key>CFBundleURLName</key>
<string>{your package name}</string>
</dict>
</array>

Web

No configuration is required for the web.

Desktop

No configuration is required for the desktop.

After all setup, we need to initialize the KhaltiScope in MaterialApp.

If you haven't created the merchant account, Use the public key

test_public_key_d5d9f63743584dc38753056b0cc737d5

After initializing the Khalti, now we move forward to pay with Khalti when clicking the button.

After success of the transaction, Khalti provides the referenceId which is the unique id of the transaction.

onFailure

onFailure

Let’s get connected

We can be friends. Find on Facebook, Linkedin, Github, Youtube, and Instagram.

Visit: Flutter Junction

Contribute: BuyMeACoffee

Conclusion

I hope this article is helpful to you and you learned new things. I have used various things in this article that might be new to some of you.

If you learned something new or want to suggest something, please let me know in the comment.

If you loved the article click on the 👏 icon which provides motivation on delivering to you all the new things.

Also, follow to get updated on exciting articles and projects.

Learning by sharing gives a great impact on the learning process and makes the community bigger and bigger.

Sharing is a magnet that attracts other enthusiasts toward you.

Hence, let’s take a small step toward making our learning community bigger.

Share this article with your friends or tweet about the article if you loved it.

Get full at:

--

--

Flutter Junction
CodeX
Writer for

Flutter Junction is a comprehensive learning platform offering a wealth of resources for developers of all experience levels.