PayU BharatKosh Encryption Wrapper - Flutter Plugin

pub package

A Flutter plugin that wraps the native PayU BharatKosh encryption wrapper SDKs for Android and iOS, providing a unified Dart API for Flutter apps.

Overview

This plugin provides seamless integration between BharatKosh payment gateway and PayU CheckoutPro SDK on both Android and iOS platforms. It handles all encryption/decryption operations, hash generation, and payment flow orchestration through a unified Dart API.

  • Android: Uses payu-cp-encryption-wrapper (via Maven)
  • iOS: Uses PayUIndia-CP-Encryption-SDK (via CocoaPods)

Features

  • Cross-Platform: Single Dart API for both Android and iOS
  • Request Decryption: Decrypts encrypted payloads from BharatKosh
  • Response Encryption: Encrypts CheckoutPro responses before sending back to BharatKosh
  • Hash Generation: Handles hash generation for CheckoutPro SDK
  • Cancel & Error Handling: Proper handling of user cancellation and error scenarios
  • Dual API Support: Both callback-based and async/await approaches

Installation

Add the package to your pubspec.yaml:

dependencies:
  payu_bharatkosh_encryption_wrapper: ^1.0.0-alpha

Or run:

flutter pub add payu_bharatkosh_encryption_wrapper

Android Setup

Add the Maven repositories to your android/settings.gradle:

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven { url "https://maven.payu.in" }
        maven { url "https://central.sonatype.com/repository/maven-snapshots/" }
    }
}

Ensure minimum SDK is 24 in android/app/build.gradle:

android {
    defaultConfig {
        minSdk 24
    }
}

iOS Setup

Ensure your ios/Podfile has the correct platform:

platform :ios, '13.0'

target 'Runner' do
  use_frameworks!
  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

Run pod install:

cd ios && pod install

Usage

Import the package

import 'package:payu_bharatkosh_encryption_wrapper/payu_bharatkosh_encryption_wrapper.dart';

Method 1: Using Callback (Traditional)

final wrapper = BharatkoshWrapper();

wrapper.startPayment(
  encRequestParameter: 'encrypted_payload_from_bharatkosh',
  reqDigitalSignature: 'digital_signature_from_bharatkosh',
  merchIdVal: 'merchant_id',
  isProduction: false, // true for production
  callback: MyPaymentCallback(),
);

class MyPaymentCallback implements BharatkoshWrapperCallback {
  @override
  void onSuccess(String encryptedResponse) {
    // Payment successful - send encryptedResponse to BharatKosh
    print('Payment Success: $encryptedResponse');
  }

  @override
  void onFailure(String encryptedResponse) {
    // Payment failed - send encryptedResponse to BharatKosh
    print('Payment Failed: $encryptedResponse');
  }

  @override
  void onCancel(String encryptedResponse) {
    // User cancelled - send encryptedResponse to BharatKosh
    print('Payment Cancelled: $encryptedResponse');
  }

  @override
  void onError(String encryptedResponse) {
    // Error occurred - send encryptedResponse to BharatKosh
    print('Payment Error: $encryptedResponse');
  }
}

Method 2: Using async/await (Modern)

final wrapper = BharatkoshWrapper();

try {
  final result = await wrapper.startPaymentAsync(
    encRequestParameter: 'encrypted_payload_from_bharatkosh',
    reqDigitalSignature: 'digital_signature_from_bharatkosh',
    merchIdVal: 'merchant_id',
    isProduction: false, // true for production
  );

  switch (result.type) {
    case BharatkoshResultType.success:
      print('Payment successful: ${result.encryptedResponse}');
      break;
    case BharatkoshResultType.failure:
      print('Payment failed: ${result.encryptedResponse}');
      break;
    case BharatkoshResultType.cancel:
      print('Payment cancelled: ${result.encryptedResponse}');
      break;
    case BharatkoshResultType.error:
      print('Payment error: ${result.encryptedResponse}');
      break;
  }

  // Send result.encryptedResponse back to BharatKosh
} catch (e) {
  print('Exception: $e');
}

API Reference

BharatkoshWrapper

startPayment()

Starts the payment flow using a callback.

Future<void> startPayment({
  required String encRequestParameter,
  required String reqDigitalSignature,
  required String merchIdVal,
  required bool isProduction,
  required BharatkoshWrapperCallback callback,
})

startPaymentAsync()

Starts the payment flow and returns a Future with the result.

Future<BharatkoshPaymentResult> startPaymentAsync({
  required String encRequestParameter,
  required String reqDigitalSignature,
  required String merchIdVal,
  required bool isProduction,
})

Parameters

Parameter Type Description
encRequestParameter String Encrypted request from BharatKosh
reqDigitalSignature String Digital signature from BharatKosh
merchIdVal String Merchant ID value
isProduction bool true for production, false for UAT

BharatkoshResultType

Value Description
success Payment completed successfully
failure Payment failed
cancel User cancelled the payment
error An error occurred

Environment Configuration

  • UAT (Test): isProduction: false → https://compulsiveuat.payu.in/
  • Production: isProduction: true → https://compulsive.payu.in/

Requirements

  • Flutter: 3.0.0 or later
  • Dart: 3.0.0 or later
  • Android: API 24 (Android 7.0) or later
  • iOS: 13.0 or later

Documentation

For comprehensive integration guide, see:

Support

For issues and questions:

  • Create an issue in the repository
  • Contact PayU support team

License

MIT License

Libraries

payu_bharatkosh_encryption_wrapper
Flutter wrapper for BharatKosh encryption SDK.