搜索插件、代码仓与 APP 分类

插件详情v1.0.1

easebuzz_flutter_sdk

Easebuzz Flutter SDK 简化了在 Android、iOS 和 Web 平台上安全支付的集成。

近 30 天下载
95
喜欢数
10
Pub 分数
70

安装插件

flutter pub add easebuzz_flutter_sdk

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Easebuzz Flutter SDK 可为 Android、iOS 和 Web 平台上的 Flutter 应用实现无缝且安全的支付集成。它通过最少的设置简化了添加支付功能的过程,确保符合安全标准。开发者可以利用其一致的 API 来处理交易、管理支付流程,并在单一跨平台解决方案中支持多种支付方式。该 SDK 专为生产环境中的可靠性、性能和易用性而设计。

适合场景

  • 应用内购买
  • 电子商务结账
  • 订阅计费
  • 数字服务付款
  • 在线票务预订
  • 捐赠收集

主要特点

  • 跨平台兼容性
  • 安全支付处理
  • 通过 Flutter Pub 的简单集成
  • 支持多种支付方式
  • 实时交易状态更新
  • 内置错误处理

适合对象

  • 移动电子商务应用
  • 基于Web的支付门户
  • 基于订阅的服务
  • 活动票务平台
  • 非营利捐赠系统

使用建议

  • 需要有效的 Easebuzz 账户凭据
  • 限于支持的区域
  • 依赖网络连接
  • 生产环境需要正确配置
  • 可能需要额外的后端验证

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Easebuzz Flutter SDK

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.


Features

  • Multiple payment modes: Credit/Debit Cards, UPI, Net Banking, and more.
  • Secure and encrypted transactions.
  • Easy integration with Flutter apps.
  • Fully API-integrated payment gateway.
  • Sandbox environment for testing.

Prerequisites

Before integrating the Easebuzz Flutter SDK, ensure the following:

  1. Merchant Onboarding

  2. Sandbox/Test Integration Credentials

    • Test credentials will be sent to your registered email address. Use these credentials to test payment functionality in a secure sandbox environment.
    • Once testing is complete, replace the test keys with live keys to enable real transactions in the production environment.
  3. 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>
        

Installation

To integrate the SDK, follow these steps:

  1. 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
    
  2. Import the Package

    Import the SDK in your Dart file:

    import 'package:easebuzz_flutter_sdk/easebuzz_flutter_sdk.dart';
    

How to Use

Step 1: Initialize the SDK

Before using any functionality from the SDK, initialize the EasebuzzFlutterSdk instance:

final EasebuzzFlutterSdk _easebuzzFlutterPlugin = EasebuzzFlutterSdk();

Step 2: Create the Payment Model

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 surl and furl with your actual success and failure handling URLs.

Step 3: Generate Hash

Generate a hash to ensure secure communication:

final hash = await _easebuzzFlutterPlugin.generateHash(
  paymentModel: paymentModel,
  key: key, // Merchant key
  salt: salt, // Merchant salt
);
Step 4: Initiate Payment Link
For Mobile Platforms (Android/iOS):

Use the initiateLink method:

final response = await _easebuzzFlutterPlugin.initiateLink(
  isTestMode: true, // Set to `false` for production
  hash: hash,
  paymentModel: paymentModel,
);
For Web:

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(),
);

Step 4: Proceed to Payment

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
);

Full Example for Payment Integration

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,
        );
      },
    );
  }


Why Use Backend for Web Integration?

  • Due to CORS restrictions, the Initiate Payment API must be called from your backend or cloud function.
  • Backend integration ensures secure handling of the access key.

Example Screen Recording

Watch the example screen recordings for different platforms to see how to integrate the Easebuzz Flutter SDK:


Resources


所属分类

依赖

依赖清单 4 项

  • crypto^3.0.6
  • dio^5.7.0
  • plugin_platform_interface^2.1.8
  • web^1.1.0

源码仓库

使用此插件的项目

暂无相关数据。