easebuzz_flutter_sdk
Easebuzz Flutter SDK 简化了在 Android、iOS 和 Web 平台上安全支付的集成。
techienutz/easebuzz_flutter_sdk open-source repository details.
以下为英文项目原文快照,最新内容请访问 GitHub。
The Easebuzz Flutter SDK provides seamless integration with the Easebuzz payment gateway, enabling merchants to securely collect online payments through various payment modes such as credit cards, debit cards, UPI, and more. This SDK ensures robust encryption and security measures to safeguard customer data. Easebuzz is a fully API-integrated platform, simplifying payment processing for websites and mobile apps.
Before integrating the Easebuzz Flutter SDK, ensure the following:
Merchant Onboarding
Sandbox/Test Integration Credentials
Platform-Specific Configuration
Web:
Add the following two <script> tags in the <head> section of your web/index.html:
<script src="https://ebz-static.s3.ap-south-1.amazonaws.com/easecheckout/v2.0.0/easebuzz-checkout-v2.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
To integrate the SDK, follow these steps:
Add the Dependency
Add the following to your pubspec.yaml file:
dependencies:
easebuzz_flutter_sdk: ^0.0.1
Fetch the package by running:
flutter pub get
Import the Package
Import the SDK in your Dart file:
import 'package:easebuzz_flutter_sdk/easebuzz_flutter_sdk.dart';
Before using any functionality from the SDK, initialize the EasebuzzFlutterSdk instance:
final EasebuzzFlutterSdk _easebuzzFlutterPlugin = EasebuzzFlutterSdk();
Start by creating an instance of EasebuzzPaymentModel:
final paymentModel = EasebuzzPaymentModel(
txnid: "TEST${DateTime.now().millisecondsSinceEpoch}", // Unique transaction ID
amount: amount, // Payment amount
productinfo: productName, // Product/service name
firstname: "John", // Customer's first name
email: "john@example.com", // Customer's email
phone: "9999999999", // Customer's phone number
surl: "https://your-success-url.com", // Success URL
furl: "https://your-failure-url.com", // Failure URL
splitPayments: jsonEncode({"your_label": amount}), // Split payments if applicable
key: key, // Merchant key
);
Note: Replace
surlandfurlwith your actual success and failure handling URLs.
Generate a hash to ensure secure communication:
final hash = await _easebuzzFlutterPlugin.generateHash(
paymentModel: paymentModel,
key: key, // Merchant key
salt: salt, // Merchant salt
);
Use the initiateLink method:
final response = await _easebuzzFlutterPlugin.initiateLink(
isTestMode: true, // Set to `false` for production
hash: hash,
paymentModel: paymentModel,
);
The initiateLink method is not supported on web due to CORS issues. Instead, generate the access key on your backend or cloud function by calling the Easebuzz API:
Example for generating access key:
final response = await createAccessTokenForWeb(
hash: hash,
requestBody: paymentModel.toJson(),
);
After obtaining the access key from initiateLink or your backend, proceed with the payment:
final paymentResponse = await _easebuzzFlutterPlugin.payWithEasebuzz(
response, // Access key from initiateLink response
"test", // Payment mode: "test" for sandbox or "production" for live
);
Here’s an example of how to use the Easebuzz SDK in a Flutter app:
Future<void> initiatePayment({
required String productName,
required double amount,
required Function(String) onSuccess,
required Function(String) onError,
}) async {
final paymentModel = EasebuzzPaymentModel(
txnid: "TEST${DateTime.now().millisecondsSinceEpoch}",
amount: amount,
productinfo: productName,
firstname: "John",
email: "john@example.com",
phone: "9999999999",
surl: "https://your-success-url.com",
furl: "https://your-failure-url.com",
splitPayments: jsonEncode({"your_label": amount}),
key: key,
);
try {
// Generate hash
final hash = await _easebuzzFlutterPlugin.generateHash(
paymentModel: paymentModel,
key: EaseBuzzPaymentRepository.key,
salt: EaseBuzzPaymentRepository.salt,
);
if (hash == null) {
onError("Failed to generate hash.");
return;
}
// Initiate payment link
final response = kIsWeb
? await createAccessTokenForWeb(
hash: hash, requestBody: paymentModel.toJson()) //
: await _easebuzzFlutterPlugin.initiateLink(
isTestMode: true, // Set to false for production
hash: hash,
paymentModel: paymentModel,
);
if (response == null) {
onError("Failed to initiate payment link.");
return;
}
// Proceed to payment
final paymentResponse =
await _easebuzzFlutterPlugin.payWithEasebuzz(response, "test");
if (paymentResponse != null) {
// Handle successful payment
onSuccess("Payment successful: $paymentResponse");
} else {
// Handle failed payment
onError("Payment failed: Payment response is null.");
}
} on PlatformException catch (e) {
// Handle platform-specific errors
onError("Payment failed: ${e.message}");
} catch (e) {
// Handle general errors
onError("Payment failed: ${e.toString()}");
}
}
/// Call this above method on paybutton
Future<void> _processPayment(BuildContext context, Product product) async {
await paymentService.initiatePayment(
productName: product.title,
amount: product.price,
onSuccess: (response) {
_showFeedbackSnackBar(
context,
'Payment Successful: $response',
Colors.green,
);
},
onError: (error) {
_showFeedbackSnackBar(
context,
'Payment Failed: $error',
Colors.red,
);
},
);
}
Initiate Payment API must be called from your backend or cloud function.access key.Watch the example screen recordings for different platforms to see how to integrate the Easebuzz Flutter SDK:
依赖清单 8 项
^3.0.6^5.7.0{"sdk":"flutter"}{"sdk":"flutter"}^2.1.8^1.1.0^5.0.0{"sdk":"flutter"}先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗