olw_sdk_flutter 1.0.0-alpha.1 copy "olw_sdk_flutter: ^1.0.0-alpha.1" to clipboard
olw_sdk_flutter: ^1.0.0-alpha.1 copied to clipboard

PayU OLW (One Link Wallet) Flutter SDK - native bridge for PayU OLW on Android and iOS.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:olw_sdk_flutter/olw_sdk_flutter.dart';

import 'HashService.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: WalletPage(),
    );
  }
}

class WalletPage extends StatefulWidget {
  const WalletPage({super.key});

  @override
  _WalletPageState createState() => _WalletPageState();
}

class _WalletPageState extends State<WalletPage>
    implements PayUOLWProtocol {
  late PayUOLWFlutter _payUOLW;

  /// Controllers for all SDK params
  final merchantKeyController =
  TextEditingController(text: "QYhPd1");
  final merchantSaltController =
  TextEditingController(text: "EsjSjL0flB5rDBOB39x85cej4aFq3lao");
  final customerMobileController =
  TextEditingController(text: "8570003391");
  final supportEmailController =
  TextEditingController(text: "support@merchant.com");
  final primaryColorController =
  TextEditingController(text: "#3E1C64");
  final termsUrlController =
  TextEditingController(text: "https://payu.in");
  final merchantLogoController =
  TextEditingController(text: "merchant_logo");
 final redirectionUrl =
  TextEditingController(text: "https://payu.in");
final payuReferenceId =
  TextEditingController(text: "1234567890");


  bool isProduction = false;

  @override
  void initState() {
    super.initState();
    _payUOLW = PayUOLWFlutter(this);
  }

  /// Launch OLW SDK
  void launchOLWSDK() {
    try {
      final params = PayUOLWParamsBuilder()
          .setPayUReferenceId(payuReferenceId.text)
          .setMerchantKey(merchantKeyController.text)
          .setIsProduction(isProduction)
          .setCustomerMobile(customerMobileController.text)
          .setMerchantSupportEmail(supportEmailController.text)
          .setTermsAndConditionsURL(termsUrlController.text)
          .setPrimaryColor(primaryColorController.text)
          .setKycRedirectionUrl(redirectionUrl.text)
          .setMerchantLogoName(merchantLogoController.text)
          .build();

      print("paramObject$params");
      _payUOLW.openPayUOLWSDK(payUOLWParams: params);

    } on ArgumentError catch (e) {
      onError({
        PayUOLWConstants.errorCode: PayUOLWErrorCodes.merchantKeyError.toString(),
        PayUOLWConstants.errorMessage: e.message.toString(),
      });
    }
  }

  /// Hash generation callback
  @override
  generateHash(Map response) {
    /// ⚠️ IMPORTANT
    /// Hash must be generated on your backend
    /// Below is only for demonstration purposes
    var generatedHashMap = HashService.generateHash(response, merchantSaltController.text);

    // Extract the hashName from the response
    final String hashName = response["hashName"] ?? "";

    // Extract the actual hash string from the map
    // HashService returns {hashName: hashValue}, so we need to get the value
    final String hashValue = generatedHashMap[hashName] ?? "";


    // Unified hash result format for both iOS and Android
    // Both platforms now use hashName for callback routing
    final Map<String, dynamic> hashResult = {
      PayUOLWHashKeys.hashString: hashValue,
      "hashName": hashName,  // Required for callback lookup on both platforms
    };

    // Send the hash back to the SDK
    _payUOLW.hashGenerated(hashResult: hashResult);
  }

  @override
  onClose() {
    debugPrint("OLW SDK closed");
  }

  @override
  onError(Map? response) {
    final errorMessage = response?[PayUOLWConstants.errorMessage] ?? "Unknown error";
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        content: Text(errorMessage.toString()),
        backgroundColor: Colors.red,
      ),
    );
  }

  Widget _buildTextField(
      {required String label,
        required TextEditingController controller}) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 8),
      child: TextField(
        controller: controller,
        decoration: InputDecoration(
          labelText: label,
          border: const OutlineInputBorder(),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("PayU OLW SDK Demo"),
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(16),
        child: Column(
          children: [
            _buildTextField(
                label: "Merchant Key",
                controller: merchantKeyController),

            _buildTextField(
                label: "Merchant Salt",
                controller: merchantSaltController),
                
            _buildTextField(
                label: "Customer Mobile",
                controller: customerMobileController),

              _buildTextField(
                label: "Logo Name",
                controller: merchantLogoController),

            _buildTextField(
                label: "Support Email",
                controller: supportEmailController),
            _buildTextField(
                label: "Primary Color (Hex)",
                controller: primaryColorController),
            _buildTextField(
                label: "Terms & Conditions URL",
                controller: termsUrlController),
            _buildTextField(
                label: "Kyc Redirection Url",
                controller: redirectionUrl),
           _buildTextField(
                label: "PayU ReferenceId",
                controller: payuReferenceId),
            const SizedBox(height: 16),
            SwitchListTile(
              title: const Text("Production Mode"),
              value: isProduction,
              onChanged: (value) {
                setState(() => isProduction = value);
              },
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: launchOLWSDK,
              child: const Text("Launch OLW SDK"),
            ),
            const SizedBox(height: 12),
          ],
        ),
      ),
    );
  }
}
0
likes
130
points
43
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

PayU OLW (One Link Wallet) Flutter SDK - native bridge for PayU OLW on Android and iOS.

Homepage
Repository (GitHub)

License

MIT (license)

Dependencies

flutter

More

Packages that depend on olw_sdk_flutter

Packages that implement olw_sdk_flutter