payu_upi_bolt_flutter 1.0.0-alpha.1
payu_upi_bolt_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_flutter_example/screens/device_binding_screen.dart';
import 'package:payu_upi_bolt_flutter_example/screens/management_screen.dart';
import '../screens/util.dart';
import '../screens/linked_accounts_screen.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> {
final payUUpiFlutter = PayUSDK().instance;
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: "[email protected]");
@override
void initState() {
super.initState();
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>[
ElevatedButton(
child: const Text("Init SDK"),
onPressed: () {
initSDK();
},
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
child: const Text("is Bolt Enabled"),
onPressed: () {
isUPIBoltSDKAvailable();
},
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
child: const Text("is Bolt SDK Registered"),
onPressed: () {
isRegistered();
},
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
child: const Text("Clear Bolt SDK Cache"),
onPressed: () {
clearCache();
},
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
child: const Text("Get Registered Number"),
onPressed: () {
getRegisteredMobile();
},
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
child: const Text("Register"),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => DeviceBindingScreen()),
);
},
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
child: const Text("Pay"),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => LinkedAccountsScreen()),
);
},
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
child: const Text("Management UPI"),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => ManagementScreen()),
);
},
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
child: const Text("Reset"),
onPressed: () {
reset();
},
),
],
),
]))),
),
);
}
void 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: Text(content),
),
actions: [okButton],
);
});
}
Future<void> initSDK() async {
var config = PayUParams.createPayUParamsToInitSDK();
payUUpiFlutter.initSDK(params: config);
}
Future<void> isUPIBoltSDKAvailable() async {
final result = await payUUpiFlutter.isUPIBoltEnabled();
if (result['code'] == 0) {
// success
showAlertDialog(context, "Success", result.toString());
} else {
showAlertDialog(context, "Error", result.toString());
}
}
Future<void> reset() async {
final result = await payUUpiFlutter.reset();
showAlertDialog(context, "Success", result.toString());
}
Future<void> isRegistered() async {
final result = await payUUpiFlutter.isRegistered(params: {"pg": "BHIM"});
if (result['code'] == 0) {
// success
showAlertDialog(context, "Success", result.toString());
} else {
showAlertDialog(context, "Error", result.toString());
}
}
Future<void> clearCache() async {
final result = await payUUpiFlutter.clearCache(params: {"pg": "BHIM"});
showAlertDialog(context, "Success", result.toString());
}
Future<void> getRegisteredMobile() async {
final result =
await payUUpiFlutter.getRegisteredMobile(params: {"pg": "BHIM"});
showAlertDialog(context, "Success", result.toString());
}
@override
generateHash(Map response) {
var params = HashService.initHash(response);
payUUpiFlutter.hashGenerated(params: params);
}
}