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

The PayU UPI SDK Flutter provides a complete Solution for the Flutter App. This will support both iOS and Android.

example/lib/main.dart

// ignore_for_file: use_build_context_synchronously

import 'dart:convert';

import 'package:crypto/crypto.dart';
import 'package:flutter/material.dart';
import 'package:payu_upi_bolt_ui_flutter/PayUUPIConstantKeys.dart';
import 'package:payu_upi_bolt_ui_flutter/payu_upi_bolt_ui_flutter.dart';

void main() {
  runApp(const MaterialApp(home: MyApp()));
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> implements PayUUPIBoltUIProtocol {
  late PayUUPIBoltUIFlutter payUUpiFlutter;
  TextEditingController amountTextField = TextEditingController(text: "1");
  TextEditingController mobileTextField =
      TextEditingController(text: PayUTestCredentials.mobile);
  TextEditingController merchantNameTextField =
      TextEditingController(text: "PayU");
  TextEditingController keyTextField =
      TextEditingController(text: PayUTestCredentials.merchantKey);
  TextEditingController saltTextField =
      TextEditingController(text: PayUTestCredentials.merchantSalt);
  //TextEditingController saltTextField = TextEditingController(text: "admin");
  TextEditingController emailTextField =
      TextEditingController(text: "upi@email.com");

  @override
  void initState() {
    super.initState();
    payUUpiFlutter = PayUUPIBoltUIFlutter(this);
    PayUTestCredentials.merchantKey = keyTextField.text;
    PayUTestCredentials.merchantSalt = saltTextField.text;
    PayUTestCredentials.amount = amountTextField.text;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('iOS UPI Bolt example app'),
        ),
        body: Center(
            child: Container(
                margin: const EdgeInsets.only(left: 20.0, right: 20.0),
                child: ListView(children: <Widget>[
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Flexible(
                        child: Container(
                          margin:
                              const EdgeInsets.only(top: 10.0, bottom: 10.0),
                          height: 50,
                          child: TextField(
                            controller: amountTextField,
                            decoration: const InputDecoration(
                              labelText: 'Amount',
                              contentPadding: EdgeInsets.all(8),
                              border: OutlineInputBorder(),
                            ),
                            style: Theme.of(context).textTheme.bodyLarge,
                            onChanged: (content) {
                              PayUTestCredentials.amount = amountTextField.text;
                              print("PayU flutterhash " +
                                  PayUTestCredentials.merchantKey);
                            },
                          ),
                        ),
                      ),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Flexible(
                        child: Container(
                          margin:
                              const EdgeInsets.only(top: 10.0, bottom: 10.0),
                          height: 50,
                          child: TextField(
                            controller: mobileTextField,
                            decoration: const InputDecoration(
                              labelText: 'mobile number ',
                              contentPadding: EdgeInsets.all(8),
                              border: OutlineInputBorder(),
                            ),
                            style: Theme.of(context).textTheme.bodyLarge,
                            onChanged: (content) {
                              PayUTestCredentials.mobile = mobileTextField.text;
                              print("PayU flutterhash " +
                                  PayUTestCredentials.mobile);
                            },
                          ),
                        ),
                      ),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Flexible(
                        child: Container(
                          margin:
                              const EdgeInsets.only(top: 10.0, bottom: 10.0),
                          height: 50,
                          child: TextField(
                            controller: keyTextField,
                            decoration: const InputDecoration(
                              labelText: 'Key ',
                              contentPadding: EdgeInsets.all(8),
                              border: OutlineInputBorder(),
                            ),
                            style: Theme.of(context).textTheme.bodyLarge,
                            onChanged: (content) {
                              PayUTestCredentials.merchantKey =
                                  keyTextField.text;
                              print("PayU flutterhash " +
                                  PayUTestCredentials.merchantKey);
                            },
                          ),
                        ),
                      ),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Flexible(
                        child: Container(
                          margin:
                              const EdgeInsets.only(top: 10.0, bottom: 10.0),
                          height: 50,
                          child: TextField(
                            controller: saltTextField,
                            decoration: const InputDecoration(
                              labelText: 'Salt ',
                              contentPadding: EdgeInsets.all(8),
                              border: OutlineInputBorder(),
                            ),
                            style: Theme.of(context).textTheme.bodyLarge,
                            onChanged: (content) {
                              PayUTestCredentials.merchantSalt =
                                  saltTextField.text;
                            },
                          ),
                        ),
                      ),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Checkbox(
                          value: PayUTestCredentials.isCCTxnEnabled,
                          onChanged: (newValue) {
                            setState(() {
                              PayUTestCredentials.isCCTxnEnabled = newValue!;
                            });
                          }),
                      Text("Enable credit card transaction"),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Text("Screen Type"),
                      SizedBox(width: 50),
                      DropdownButton(
                          items: <String>[
                            'ALL',
                            'TRANSACTIONHISTORY',
                            'MANAGEUPIACCOUNTS',
                            'DISPUTE',
                            'DEREGISTERUPI'
                          ].map((String screen) {
                            return DropdownMenuItem<String>(
                              value: screen,
                              child: Text(screen),
                            );
                          }).toList(),
                          value: PayUTestCredentials.screenType,
                          onChanged: (newValue) {
                            setState(() {
                              PayUTestCredentials.screenType = newValue!;
                            });
                          })
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      ElevatedButton(
                        child: const Text("Init SDK"),
                        onPressed: () {
                          initSDK();
                        },
                      ),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      ElevatedButton(
                        child: const Text("Register & Pay"),
                        onPressed: () {
                          registerAndPay();
                        },
                      ),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      ElevatedButton(
                        child: const Text("UPI Management"),
                        onPressed: () {
                          openUPIManagement();
                        },
                      ),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      ElevatedButton(
                        child: const Text("isUPIBoltSDKAvailable"),
                        onPressed: () {
                          isUPIBoltSDKAvailable();
                        },
                      ),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      ElevatedButton(
                        child: const Text("Reset"),
                        onPressed: () {
                          reset();
                        },
                      ),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      ElevatedButton(
                        child: const Text("isRegistered"),
                        onPressed: () {
                          isRegistered();
                        },
                      ),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      ElevatedButton(
                        child: const Text("Clear Cache"),
                        onPressed: () {
                          clearCache();
                        },
                      ),
                    ],
                  )
                ]))),
      ),
    );
  }

  showAlertDialog(BuildContext context, String title, String content) {
    Widget okButton = TextButton(
      child: const Text("OK"),
      onPressed: () {
        Navigator.pop(context);
      },
    );

    showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text(title),
            content: SingleChildScrollView(
              scrollDirection: Axis.vertical,
              child: new Text(content),
            ),
            actions: [okButton],
          );
        });
  }

  initSDK() async {
    var config = PayUParams.createPayUParamsToInitSDK();
    payUUpiFlutter.initSDK(params: config);
  }

  registerAndPay() async {
    var params = PayUParams.createPayUParamsToRegisterAndPay();
    payUUpiFlutter.registerAndPay(params: params);
  }

  openUPIManagement() async {
    var params = PayUParams.createPayUParamsForLinkedAccounts();
    payUUpiFlutter.openUPIManagement(params: params);
  }

  isUPIBoltSDKAvailable() async {
    var params = PayUParams.createPayUParamsForLinkedAccounts();
    payUUpiFlutter.isUPIBoltEnabled(params: params);
  }

  reset() async {
    payUUpiFlutter.reset();
  }

  isRegistered() async {
    var params = PayUParams.createPayUParamsForPG();
    payUUpiFlutter.isRegistered(params: params);
  }

  clearCache() async {
    var params = PayUParams.createPayUParamsForPG();
    payUUpiFlutter.clearCache(params: params);
  }

  @override
  onPayUSuccess(Map response) {
    showAlertDialog(
        context, PayUEventType.onPaymentSuccess, response.toString());
  }

  @override
  onPayUCancel(Map response) {
    showAlertDialog(context, PayUEventType.onCancel, response.toString());
  }

  @override
  onPayUFailure(Map response) {
    showAlertDialog(
        context, PayUEventType.onPaymentFailure, response.toString());
  }

  @override
  onErrorReceived(Map response) {
    showAlertDialog(
        context, PayUEventType.onErrorReceived, response.toString());
  }

  @override
  onUPIBoltEnabled(Map response) {
    showAlertDialog(context, "isUPIBoltEnabled", response.toString());
  }

  @override
  onReset(Map response) {
    showAlertDialog(context, "Reset", response.toString());
  }

  @override
  onIsRegistered(Map response) {
    showAlertDialog(context, "IsRegistered", response.toString());
  }

  @override
  onClearCache(Map response) {
    showAlertDialog(context, "ClearCache", response.toString());
  }

  @override
  onInitSDK(Map response) {
    showAlertDialog(context, "onInitSDK", response.toString());
  }

  @override
  generateHash(Map response) {
    var params = HashService.initHash(response);
    payUUpiFlutter.hashGenerated(params: params);
  }
}

//Pass these values from your app to SDK, this data is only for test purpose
class PayUParams {
  static Map createPayUParamsToInitSDK() {
    var initSDKParams = {
      PayUUPIBoltSDKInitParamKeys.merchantName:
          PayUTestCredentials.merchantName,
      PayUUPIBoltSDKInitParamKeys.merchantKey: PayUTestCredentials.merchantKey,
      PayUUPIBoltPaymentParamsKeys.refId: PayUTestCredentials.requestId,
      PayUUPIBoltSDKInitParamKeys.phone: PayUTestCredentials.mobile,
      PayUUPIBoltSDKInitParamKeys.email: PayUTestCredentials.email,
      PayUUPIBoltSDKInitParamKeys.requestId: PayUTestCredentials.requestId,
      PayUUPIBoltSDKInitParamKeys.clientId: "Myntra",
      PayUUPIBoltSDKInitParamKeys.pluginTypes: [PayUTestCredentials.pluginType],
      PayUUPIBoltSDKInitParamKeys.isProduction:
          PayUTestCredentials.isProduction,
      PayUUPIBoltSDKInitParamKeys.issuingBanks: [
        PayUTestCredentials.issuingBank
      ],
      PayUUPIBoltSDKInitParamKeys.excludedBanksIINs: [
        PayUTestCredentials.excludedBanksIINs
      ]
    };
    return initSDKParams;
  }

  static Map createPayUParamsToRegisterAndPay() {
    var registerAndPayParams = {
      PayUUPIBoltPaymentParamsKeys.amount: PayUTestCredentials.amount,
      PayUUPIBoltPaymentParamsKeys.productInfo: PayUTestCredentials.productInfo,
      PayUUPIBoltPaymentParamsKeys.firstName: PayUTestCredentials.firstName,
      PayUUPIBoltPaymentParamsKeys.surl: PayUTestCredentials.sUrl,
      PayUUPIBoltPaymentParamsKeys.furl: PayUTestCredentials.fUrl,
      PayUUPIBoltPaymentParamsKeys.udf1: PayUTestCredentials.udf1,
      PayUUPIBoltPaymentParamsKeys.udf2: PayUTestCredentials.udf2,
      PayUUPIBoltPaymentParamsKeys.udf3: PayUTestCredentials.udf3,
      PayUUPIBoltPaymentParamsKeys.udf4: PayUTestCredentials.udf4,
      PayUUPIBoltPaymentParamsKeys.udf5: PayUTestCredentials.udf5,
      PayUUPIBoltPaymentParamsKeys.txnId:
          "payu_" + DateTime.now().millisecondsSinceEpoch.toString(),
      PayUUPIBoltPaymentParamsKeys.isCCTxnEnabled:
          PayUTestCredentials.isCCTxnEnabled,
      PayUUPIBoltPaymentParamsKeys.iosSurl: PayUTestCredentials.sUrl,
      PayUUPIBoltPaymentParamsKeys.iosFurl: PayUTestCredentials.sUrl,
      PayUUPIBoltPaymentParamsKeys.initiationMode: "10",
      PayUUPIBoltPaymentParamsKeys.purpose: "00"
    };
    return registerAndPayParams;
  }

  static Map createPayUParamsForLinkedAccounts() {
    var linkedAccountsParams = {
      PayUUpiBoltLinkedAccountsParamsKeys.screenType:
          PayUTestCredentials.screenType
    };
    return linkedAccountsParams;
  }

  static Map createPayUParamsForPG() {
    var params = {
      PayUUPIBoltSDKInitParamKeys.pg: PayUTestCredentials.pluginType
    };
    return params;
  }
}

class PayUTestCredentials {
  // static String merchantKey = "smsplus"; //TODO: Add Merchant Key
  // static String merchantSalt = "admin";
  static String merchantKey = "YQeVdc"; //TODO: Add Merchant Key
  static String merchantSalt = "8VFRusJ3";

  //static String merchantSalt = "admin";
  static const sUrl =
      "https://payuresponse.firebaseapp.com/success"; //TODO: Add Success URL.
  static const fUrl =
      "https://payuresponse.firebaseapp.com/success"; //TODO Add Fail URL.

  static String merchantName = "PayU";

  static String requestId =
      "payu_" + DateTime.now().millisecondsSinceEpoch.toString();
  static String pluginType = "BHIM";
  static String issuingBank = "AXIS";
  static bool isProduction = true;

  static String excludedBanksIINs = "";

  static const udf1 = "udf1";
  static const udf2 = "udf2";
  static const udf3 = "udf3";
  static const udf4 = "udf4";
  static const udf5 = "udf5";

  static String amount = "1";
  static const productInfo = "PayU Product Info";
  static const firstName = "User";
  static String email = "upi@email.com";
  static String mobile = "918437123405";

  static bool isCCTxnEnabled = false;
  static String screenType = "ALL";
}

class HashService {
  static Map initHash(Map response) {
    var finalHashString = response['hashString'];
    var paymentHash = HashService.calculateHash(
        finalHashString + PayUTestCredentials.merchantSalt);
    var hash = {
      response['hashName']: paymentHash,
      "hashName": response['hashName']
    };
    return hash;
  }

  static String getSHA512Hash(String hashData) {
    var bytes = utf8.encode(hashData); // data being hashed
    var hash = sha512.convert(bytes);
    return hash.toString();
  }

  static String calculateHash(String data) {
    print("PayU flutter hash Stirng $data");
    var hash = getSHA512Hash(data);
    print("PayU flutter hashData $hash");
    //Don't use this method, get the hash from your backend.
    return hash;
  }
}
0
likes
115
points
4
downloads

Publisher

unverified uploader

Weekly Downloads

The PayU UPI SDK Flutter provides a complete Solution for the Flutter App. This will support both iOS and Android.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on payu_upi_bolt_ui_flutter

Packages that implement payu_upi_bolt_ui_flutter