Skip to content

EPS-PG/EPS_Flutter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EPS Payment Gateway Flutter

A Flutter plugin to integrate EPS (Electronic Payment Systems) Bangladesh Payment Gateway into your Flutter application. This package simplifies the process of generating payment tokens, verifying transactions, and handling payment callbacks via a built-in WebView.

Features

  • 🔐 Secure Token Generation: Easily generate tokens for EPS transactions.
  • 💳 Seamless Checkout: Integrated WebView for a smooth payment experience.
  • Transaction Verification: Verify payment status with a single method call.
  • 🔄 Callback Handling: Automatically handles Success, Failure, and Cancelled states.
  • 🧪 Sandbox Support: Switch between Test (Sandbox) and Live environments effortlessly.

Installation

Add eps_pg_flutter to your pubspec.yaml file:

dependencies:
  eps_pg_flutter: ^0.0.1

Or install it via terminal:

flutter pub add eps_pg_flutter

Getting Started

1. Initialize the Settings

Create an instance of EpsPGInitialization with your merchant credentials. You can get these credentials from the EPS Merchant Panel.

final epsInit = EpsPGInitialization(
  userName: 'YOUR_USERNAME',
  password: 'YOUR_PASSWORD',
  hashKey: 'YOUR_HASH_KEY',
  merchantId: 'YOUR_MERCHANT_ID',
  storeId: 'YOUR_STORE_ID',
  environment: EpsPGEnvironment.testbox, // Use live for production
);

2. Create the Controller

Pass the initialization object to the EpsPGController.

final controller = EpsPGController(initializer: epsInit);

3. Initialize Payment

Create a EpsPGPaymentRequest object with customer and order details, then call initializePayment.

final paymentRequest = EpsPGPaymentRequest(
  merchantId: epsInit.merchantId,
  storeId: epsInit.storeId,
  customerOrderId: 'ORDER_123456',
  merchantTransactionId: 'TRX_123456',
  totalAmount: 100.0,
  successUrl: 'https://example.com/success',
  failUrl: 'https://example.com/fail',
  cancelUrl: 'https://example.com/cancel',
  customerName: 'John Doe',
  customerEmail: 'john@example.com',
  customerAddress: '123 Dhaka',
  customerCity: 'Dhaka',
  customerPostcode: '1212',
  customerCountry: 'Bangladesh',
  customerPhone: '01700000000',
  productName: 'T-Shirt',
);

try {
  final response = await controller.initializePayment(paymentRequest);
  
  if (response.status == 'Successful' && response.paymentUrl != null) {
    // Navigate to WebView
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => EpsPGWebView(
          url: response.paymentUrl!,
          onPaymentFinished: (status) {
            print('Payment Status: $status'); // SUCCESS, FAILED, CANCELLED
          },
        ),
      ),
    );
  } else {
    print('Error: ${response.message}');
  }
} catch (e) {
  print('Initialization Failed: $e');
}

4. Verify Transaction

After the payment is completed, you should verify the transaction status using the merchantTransactionId.

final status = await controller.verifyTransaction('TRX_123456');

if (status.status == 'Successful') {
  print('Payment Verified: ${status.amount} BDT');
} else {
  print('Payment Failed: ${status.message}');
}

Models for Type Safety

The package uses strongly typed models for responses:

  • EpsPaymentResponse: Contains status, sessionToken, paymentUrl, and message.
  • EpsStatusResponse: Contains transactionStatus, merchantTransactionId, bankTransactionId, amount, etc.

Contributing

Contributions are welcome! If you find a bug or want to add a feature, please open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A complete and elegant Flutter SDK for the Easy Payment System (EPS) gateway. Supports Sandbox/Live modes and integrated WebView.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors