khalti 2.0.0 khalti: ^2.0.0 copied to clipboard
An official Flutter plugin for Khalti Payment Gateway, to accept payments using Khalti Wallet, E-banking, Mobile Banking, Connect IPS and SCT cards.
Khalti Payment Gateway
Khalti is a payment gateway, digital wallet and API provider system for various online services for Nepal.
With this package, you can accepts payments from:
- Khalti users.
- eBanking users of our partner banks.
- Mobile banking users of our mobile banking partner banks.
- SCT/VISA card holders.
- connectIPS users.
Using Khalti Payment Gateway, you do not need to integrate with individual banks.
Want easier integration? #
This package only provides set of methods for client integration of Khalti Payment Gateway.
If custom UI is not required then prefer using khalti_flutter instead.
Setup #
Set up public key #
The first step is to grab public key from merchant dashboard. Read the getting started to learn about the integration process and grabbing public key.
KhaltiService.publicKey = <your-public-key-here>;
Note: During integration, use test keys instead of live one.
Initiating payment using Wallet #
final service = KhaltiService(client: KhaltiHttpClient());
final initiationModel = await service.initiatePayment(
request: PaymentInitiationRequestModel(
amount: 1000, // in paisa
mobile: <khalti-mobile-number>,
productIdentity: 'mac-mini',
productName: 'Apple Mac Mini',
transactionPin: <khalti-mpin>,
productUrl: 'https://khalti.com/bazaar/mac-mini-16-512-m1',
additionalData: {
'vendor': 'Oliz Store',
'manufacturer': 'Apple Inc.',
},
),
);
After successful call to the method, an OTP is sent to the mobile number provided.
Confirming Transaction #
final confirmationModel = await service.confirmPayment(
request: PaymentConfirmationRequestModel(
confirmationCode: <otp-code>, // the OTP code received through previous step
token: initiationModel.token,
transactionPin: <khalti-mpin>,
),
);
Building URL for bank payment #
final bankPaymentUrl = service.buildBankUrl(
bankId: '1234567890',
amount: 1000,
mobile: mobile,
productIdentity: 'macbook-pro-21',
productName: 'Macbook Pro 2021',
paymentType: BankPaymentType.eBanking,
);
The URL obtained can be launched using url_launcher and the Khalti server will redirect your client to bank portal where user can access e-banking, finally redirecting back to original/parent page with the response.
Fetching available banks for receiving payment #
final banks = await service.getBanks(paymentType: BankPaymentType.eBanking);
Khalti Docs #
Visit https://docs.khalti.com/.
License #
Copyright (c) 2021 The Khalti Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Sparrow Pay Pvt. Ltd. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.