payu_bharatkosh_encryption_wrapper 1.0.0-alpha.1
payu_bharatkosh_encryption_wrapper: ^1.0.0-alpha.1 copied to clipboard
Flutter wrapper for BharatKosh encryption SDK that internally uses PayU CheckoutPro native SDKs for Android and iOS.
PayU BharatKosh Encryption Wrapper - Flutter Plugin #
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 is a thin wrapper that uses the existing native SDKs:
- Android:
payu-cp-encryption-wrapper(via Maven) - iOS:
PayUIndia-CP-Encryption-SDK(via CocoaPods)
The plugin only contains the Flutter platform channel bridge code - all encryption/decryption logic remains in the native SDKs.
Features #
- 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 #
Step 1: Add Flutter Plugin Dependency #
Add this to your pubspec.yaml:
dependencies:
payu_bharatkosh_encryption_wrapper:
path: path/to/payu_bharatkosh_encryption_wrapper
Step 2: 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
}
}
Step 3: 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 #
The main class for interacting with the BharatKosh encryption wrapper.
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 |
BharatkoshWrapperCallback #
Abstract class for receiving payment callbacks.
| Method | Description |
|---|---|
onSuccess(String) |
Called when payment succeeds |
onFailure(String) |
Called when payment fails |
onCancel(String) |
Called when user cancels |
onError(String) |
Called when an error occurs |
BharatkoshPaymentResult #
Result object returned by startPaymentAsync().
| Property | Type | Description |
|---|---|---|
type |
BharatkoshResultType |
Type of result |
encryptedResponse |
String |
Encrypted response to send to BharatKosh |
BharatkoshResultType #
Enum representing the result type.
| Value | Description |
|---|---|
success |
Payment completed successfully |
failure |
Payment failed |
cancel |
User cancelled the payment |
error |
An error occurred |
Environment Configuration #
The plugin supports two environments:
-
UAT (Test):
isProduction: false- Base URL:
https://compulsiveuat.payu.in/
- Base URL:
-
Production:
isProduction: true- Base URL:
https://compulsive.payu.in/
- Base URL:
Project Structure #
CPWrapperFlutter/payu_bharatkosh_encryption_wrapper/
├── lib/ # Dart API
│ ├── payu_bharatkosh_encryption_wrapper.dart
│ └── src/
│ ├── bharatkosh_wrapper.dart
│ ├── bharatkosh_wrapper_callback.dart
│ └── bharatkosh_payment_result.dart
│
├── android/ # Android Plugin (thin bridge)
│ └── src/main/kotlin/.../PayuBharatkoshEncryptionWrapperPlugin.kt
│
├── ios/ # iOS Plugin (thin bridge)
│ └── Classes/PayuBharatkoshEncryptionWrapperPlugin.swift
│
└── example/ # Example Flutter App
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
Native SDK Dependencies #
| Platform | SDK | Source |
|---|---|---|
| Android | payu-cp-encryption-wrapper |
Maven |
| iOS | PayUIndia-CP-Encryption-SDK |
CocoaPods |
Documentation #
For comprehensive integration guide, see:
- Flutter Integration Guide
- PayU Developer Documentation
Support #
For issues and questions:
- Create an issue in the repository
- Contact PayU support team
License #
MIT License