Positive Pay fixed, yojna accounts created
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/api/services/cheque_service.dart';
|
||||
import 'package:kmobile/data/models/user.dart';
|
||||
import 'package:kmobile/di/injection.dart';
|
||||
import 'package:kmobile/features/fund_transfer/screens/transaction_pin_screen.dart';
|
||||
import 'package:kmobile/l10n/app_localizations.dart';
|
||||
|
||||
class PositivePayScreen extends StatefulWidget {
|
||||
@@ -16,25 +22,41 @@ class PositivePayScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _PositivePayScreenState extends State<PositivePayScreen> {
|
||||
User? _selectedAccount;
|
||||
List<User> _filteredUsers = [];
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _accountNumberController = TextEditingController();
|
||||
final _chequeNumberController = TextEditingController();
|
||||
final _chequeDateController = TextEditingController();
|
||||
final _amountController = TextEditingController();
|
||||
final _payeeController = TextEditingController();
|
||||
final _chequeService = getIt<ChequeService>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_filteredUsers = widget.users
|
||||
.where((user) => ['SA', 'SB', 'CA', 'CC'].contains(user.accountType))
|
||||
.toList();
|
||||
// Pre-fill the account number if possible
|
||||
if (widget.users.isNotEmpty) {
|
||||
_accountNumberController.text = widget.users[widget.selectedIndex].accountNo!;
|
||||
if (widget.users.isNotEmpty && widget.selectedIndex < widget.users.length) {
|
||||
if (_filteredUsers.isNotEmpty) {
|
||||
if (_filteredUsers.contains(widget.users[widget.selectedIndex])) {
|
||||
_selectedAccount = widget.users[widget.selectedIndex];
|
||||
} else {
|
||||
_selectedAccount = _filteredUsers.first;
|
||||
}
|
||||
} else {
|
||||
_selectedAccount = widget.users[widget.selectedIndex];
|
||||
}
|
||||
} else {
|
||||
if (_filteredUsers.isNotEmpty) {
|
||||
_selectedAccount = _filteredUsers.first;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_accountNumberController.dispose();
|
||||
_chequeNumberController.dispose();
|
||||
_chequeDateController.dispose();
|
||||
_amountController.dispose();
|
||||
@@ -42,6 +64,33 @@ class _PositivePayScreenState extends State<PositivePayScreen> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _showResponseDialog(String title, String message) async {
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false, // user must tap button!
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(title),
|
||||
content: SingleChildScrollView(
|
||||
child: ListBody(
|
||||
children: <Widget>[
|
||||
Text(message),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: Text(AppLocalizations.of(context).closeButton),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -59,16 +108,26 @@ class _PositivePayScreenState extends State<PositivePayScreen> {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
const SizedBox(height: 16.0),
|
||||
TextFormField(
|
||||
controller: _accountNumberController,
|
||||
DropdownButtonFormField<User>(
|
||||
value: _selectedAccount,
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).accountNumber,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
items: _filteredUsers.map((user) {
|
||||
return DropdownMenuItem<User>(
|
||||
value: user,
|
||||
child: Text(user.accountNo.toString()),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (User? newUser) {
|
||||
setState(() {
|
||||
_selectedAccount = newUser;
|
||||
});
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter account number';
|
||||
if (value == null) {
|
||||
return AppLocalizations.of(context).accountNumberRequired;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
@@ -106,7 +165,7 @@ class _PositivePayScreenState extends State<PositivePayScreen> {
|
||||
);
|
||||
if (pickedDate != null) {
|
||||
// Format the date as you wish
|
||||
String formattedDate = "${pickedDate.day}-${pickedDate.month}-${pickedDate.year}";
|
||||
String formattedDate = "${pickedDate.year}-${pickedDate.month.toString().padLeft(2, '0')}-${pickedDate.day.toString().padLeft(2, '0')}";
|
||||
_chequeDateController.text = formattedDate;
|
||||
}
|
||||
},
|
||||
@@ -146,8 +205,58 @@ class _PositivePayScreenState extends State<PositivePayScreen> {
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
// Process data
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(AppLocalizations.of(context).processingData)),
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => TransactionPinScreen(
|
||||
onPinCompleted: (ctx, pin) async {
|
||||
Navigator.pop(context);
|
||||
try {
|
||||
final response = await _chequeService.registerPPS(
|
||||
cheque_no: _chequeNumberController.text,
|
||||
account_number:
|
||||
_selectedAccount!.accountNo!,
|
||||
issue_date:
|
||||
_chequeDateController.text,
|
||||
amount: _amountController.text,
|
||||
payee_name: _payeeController.text,
|
||||
tpin: pin,
|
||||
);
|
||||
if (!mounted) return;
|
||||
String responseString = response.toString();
|
||||
if(responseString == 'PPS Registered Successfully'){
|
||||
_showResponseDialog('REGISTRATION SUCCESFUL',
|
||||
'Your Positive Pay Request has been registered succesfully');
|
||||
}
|
||||
if(responseString.contains('Cheque already registered')){
|
||||
_showResponseDialog('ERROR',
|
||||
'Your Request for the selected cheque number has already been registered');
|
||||
}
|
||||
if(responseString.contains('INCORRECT_TPIN')){
|
||||
_showResponseDialog('Invalid TPIN',
|
||||
'The TPIN you entered is incorrect. Please try again.');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
try {
|
||||
final errorBodyString =
|
||||
e.toString().split('Exception: ')[1];
|
||||
final errorBody = jsonDecode(errorBodyString);
|
||||
if (errorBody.containsKey('error') &&
|
||||
errorBody['error'] == 'INCORRECT_TPIN') {
|
||||
_showResponseDialog('Invalid TPIN',
|
||||
'The TPIN you entered is incorrect. Please try again.');
|
||||
} else {
|
||||
_showResponseDialog(
|
||||
'Error', 'Internal Server Error');
|
||||
}
|
||||
} catch (_) {
|
||||
_showResponseDialog(
|
||||
'Error', 'Internal Server Error');
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user