HamroPay Flutter SDK
HamroPay Flutter SDK allows you to integrate HamroPay checkout in your Flutter apps with a single method call. It supports showing the checkout either as a full page or a bottom sheet and provides a simple API to configure payment parameters and receive the transaction result.
Installation
Add the package to your pubspec.yaml
and run flutter pub get
.
dependencies:
hamropay_flutter: ^0.0.1
If you are consuming this from pub.dev, use the published version instead of path
.
Features
- Easy integration and simple API
- Supports full-page or bottom-sheet checkout
- Pure Dart interface powered by
flutter_inappwebview
- Works with product lists and optional phone number
Requirements
- Android: minSdkVersion 19+ and AndroidX
- iOS: Xcode 11+, Swift iOS project
This SDK uses flutter_inappwebview
. See its platform notes for any additional steps.
Quick Start
- Import the SDK
import 'package:hamropay_flutter/hamropay_flutter.dart';
- Create a config
final config = HamroPayConfig.dev(
clientId: 'YOUR_CLIENT_ID',
clientApiKey: 'YOUR_CLIENT_API_KEY',
merchantId: 'YOUR_MERCHANT_ID',
merchantTransactionId: 'UNIQUE_TXN_ID_123',
transactionAmount: 5000, // in paisa/cents as required by your backend
products: [
Product(
name: 'Sample Item',
imageUrl: 'https://example.com/item.png',
description: 'Item description',
price: 50.0,
quantity: 1,
),
],
phoneNumber: '98XXXXXXXX',
);
- Start payment
final result = await HamroPayService.i.pay(
context: context,
hamroPayConfig: config,
);
if (result.hasData) {
// Handle success/terminal state using result.data
} else if (result.hasError) {
// Handle failure/cancel state using result.error
}
To show checkout in a bottom sheet:
final result = await HamroPayService.i.pay(
context: context,
hamroPayConfig: config,
displayMode: HamroPayDisplayMode.bottomSheet,
bottomSheetConfig: BottomSheetConfig(
initialChildSize: 0.95,
isDismissible: false,
enableDrag: false,
),
);
Screenshots
![]() |
![]() |
API Overview
HamroPayService.i.pay(...)
starts the payment flow and returnsFuture<HmaroPayPaymentResult>
.HamroPayConfig.dev(...)
andHamroPayConfig.live(...)
construct configs for UAT/Production.HamroPayButton
is a ready-made button widget you can place in your UI.
HamroPayConfig
HamroPayConfig.dev({
required String clientId,
required String clientApiKey,
required int transactionAmount,
required String merchantId,
required String merchantTransactionId,
String serverUrl, // defaults to UAT base URL
List<Product>? products,
String? phoneNumber,
String successRedirectionUrl = 'https://hamropay_config/success',
String failedRedirectionUrl = 'https://hamropay_config/failed',
});
Use .live(...)
for production. Supply your own IDs/keys and ensure your backend is configured with the same credentials.
Display modes
HamroPayDisplayMode.page
(default): navigates to a new page.HamroPayDisplayMode.bottomSheet
: shows the checkout in a modal bottom sheet.
Result type
class HmaroPayPaymentResult {
final TransactionStatusResponse? data; // present on success/terminal states
final String? error; // present on failure/cancel
bool get hasData;
bool get hasError;
}
Platform setup
This SDK uses flutter_inappwebview
. Ensure your project meets its platform requirements:
- Android: Minimum Android SDK and WebView support per the plugin docs.
- iOS: Add required WebView permissions if applicable.
Also make sure the asset assets/png/hamro-pay.png
is available if you customize the app bar logo in the checkout screen.
Notes and Security
- Demo constants in
utils/constants/api-constants.dart
are placeholders. Replace them with your own secure values and never ship secrets in client apps. Generate signatures on a trusted server when possible. - Ensure
serverUrl
points to your backend gateway for creating session IDs and checking transaction status.
Example
See the example/
app for a runnable integration example.
Run the example app
- Navigate to the example folder:
cd example
- Install dependencies:
flutter pub get
- Configure your IDs/keys in your example (use
HamroPayConfig.dev()
for UAT) - Run:
flutter run
License
This project is available under the terms of the LICENSE file in this repo.
Contributions
Contributions are welcome! Please open an issue or submit a pull request.
Contact
Questions or suggestions? Reach out via issues or your preferred channel.
Libraries
- hamropay_flutter
- hamropay_service
- model/hamropay_config
- model/hamropay_payment_result
- model/product_model
- model/transaction_status_response_model
- presentation/hamro_pay_checkout_screen
- repository/api_call_repository
- utils/constants/api-constants
- utils/constants/app-constants
- utils/service/dio_service
- utils/service/generator
- utils/widget/dialog