From 0bab68a2e6bdc883558ef1627366e09690c3fec1 Mon Sep 17 00:00:00 2001 From: Nilanjan Chakrabarti Date: Tue, 26 Aug 2025 15:58:31 +0530 Subject: [PATCH] NEFT and RTGS transaction error resolved --- lib/api/interceptors/auth_interceptor.dart | 2 + lib/api/services/imps_service.dart | 2 - lib/api/services/neft_service.dart | 1 + lib/api/services/rtgs_service.dart | 3 - lib/config/themes.dart | 62 +++++++-------- lib/di/injection.dart | 2 +- .../screens/account_statement_screen.dart | 34 ++++----- .../dashboard/screens/dashboard_screen.dart | 2 +- .../dashboard/widgets/account_card.dart | 2 +- .../screens/fund_transfer_amount_screen.dart | 59 +++++++++------ .../quick_pay_outside_bank_screen.dart | 75 ++++++++++++++++++- 11 files changed, 163 insertions(+), 81 deletions(-) diff --git a/lib/api/interceptors/auth_interceptor.dart b/lib/api/interceptors/auth_interceptor.dart index d4925dc..9099be4 100644 --- a/lib/api/interceptors/auth_interceptor.dart +++ b/lib/api/interceptors/auth_interceptor.dart @@ -1,3 +1,5 @@ +// ignore_for_file: unused_local_variable + import 'package:dio/dio.dart'; import '../../data/repositories/auth_repository.dart'; diff --git a/lib/api/services/imps_service.dart b/lib/api/services/imps_service.dart index a2c2c2c..937696b 100644 --- a/lib/api/services/imps_service.dart +++ b/lib/api/services/imps_service.dart @@ -29,5 +29,3 @@ class ImpsService { } } } - - diff --git a/lib/api/services/neft_service.dart b/lib/api/services/neft_service.dart index 267352c..42bd6a7 100644 --- a/lib/api/services/neft_service.dart +++ b/lib/api/services/neft_service.dart @@ -23,6 +23,7 @@ class NeftService { 'NEFT transaction failed with status code: ${response.statusCode}'); } } on DioException { + print('DioException Occured'); rethrow; } catch (e) { throw Exception('An unexpected error occurred: ${e.toString()}'); diff --git a/lib/api/services/rtgs_service.dart b/lib/api/services/rtgs_service.dart index 6c9177d..9e67dc9 100644 --- a/lib/api/services/rtgs_service.dart +++ b/lib/api/services/rtgs_service.dart @@ -1,5 +1,4 @@ import 'package:dio/dio.dart'; -import 'package:kmobile/data/models/imps_transaction.dart'; import 'package:kmobile/data/models/rtgs_response.dart'; import 'package:kmobile/data/models/rtgs_transaction.dart'; @@ -29,6 +28,4 @@ class RtgsService { throw Exception('An unexpected error occurred: ${e.toString()}'); } } - - processImpsTransaction(ImpsTransaction impsTx) {} } diff --git a/lib/config/themes.dart b/lib/config/themes.dart index 15d1557..7b0f1f5 100644 --- a/lib/config/themes.dart +++ b/lib/config/themes.dart @@ -2,40 +2,40 @@ import 'package:flutter/material.dart'; import 'theme_type.dart'; class AppThemes { -static ThemeData getLightTheme(ThemeType type) { + static ThemeData getLightTheme(ThemeType type) { // Define a seed color based on the theme type -final Color seedColor; -switch (type) { -case ThemeType.green: -seedColor = Colors.green; -break; -case ThemeType.orange: -seedColor = Colors.orange; -break; -case ThemeType.blue: -seedColor = Colors.blue; -break; -case ThemeType.violet: -default: -seedColor = Colors.deepPurple; -break; -} + final Color seedColor; + switch (type) { + case ThemeType.green: + seedColor = Colors.green; + break; + case ThemeType.orange: + seedColor = Colors.orange; + break; + case ThemeType.blue: + seedColor = Colors.blue; + break; + case ThemeType.violet: + default: + seedColor = Colors.deepPurple; + break; + } // Create a ColorScheme from the seed color -final colorScheme = ColorScheme.fromSeed( -seedColor: seedColor, -brightness: Brightness.light, // Explicitly set for a light theme -); + final colorScheme = ColorScheme.fromSeed( + seedColor: seedColor, + brightness: Brightness.light, // Explicitly set for a light theme + ); // Create the ThemeData from the ColorScheme -return ThemeData.from( -colorScheme: colorScheme, -useMaterial3: true, // Recommended for modern Flutter apps -).copyWith( -scaffoldBackgroundColor: Colors.white, -bottomNavigationBarTheme: BottomNavigationBarThemeData( -backgroundColor: colorScheme.surface, -), -); + return ThemeData.from( + colorScheme: colorScheme, + useMaterial3: true, // Recommended for modern Flutter apps + ).copyWith( + scaffoldBackgroundColor: Colors.white, + bottomNavigationBarTheme: BottomNavigationBarThemeData( + backgroundColor: colorScheme.surface, + ), + ); + } } -} \ No newline at end of file diff --git a/lib/di/injection.dart b/lib/di/injection.dart index 7196bbd..84810f0 100644 --- a/lib/di/injection.dart +++ b/lib/di/injection.dart @@ -62,7 +62,7 @@ Dio _createDioClient() { BaseOptions( baseUrl: 'http://lb-test-mobile-banking-app-192209417.ap-south-1.elb.amazonaws.com:8080', - // 'http://localhost:8081', + //'http://localhost:8081', connectTimeout: const Duration(seconds: 5), receiveTimeout: const Duration(seconds: 10), headers: { diff --git a/lib/features/accounts/screens/account_statement_screen.dart b/lib/features/accounts/screens/account_statement_screen.dart index 7917e5d..9c8cc68 100644 --- a/lib/features/accounts/screens/account_statement_screen.dart +++ b/lib/features/accounts/screens/account_statement_screen.dart @@ -281,21 +281,21 @@ class _AccountStatementScreen extends State { tx.type == 'CR' ? Colors.green : Colors.red, ), title: Text( - tx.date ?? '', - style: const TextStyle(fontSize: 15), - ), - subtitle: Text( - tx.name != null - ? (tx.name!.length > 18 - ? tx.name!.substring(0, 22) - : tx.name!) - : '', - style: const TextStyle(fontSize: 12), - ), - trailing: Text( - "₹${tx.amount}", - style: const TextStyle(fontSize: 17), - ), + tx.date ?? '', + style: const TextStyle(fontSize: 15), + ), + subtitle: Text( + tx.name != null + ? (tx.name!.length > 18 + ? tx.name!.substring(0, 22) + : tx.name!) + : '', + style: const TextStyle(fontSize: 12), + ), + trailing: Text( + "₹${tx.amount}", + style: const TextStyle(fontSize: 17), + ), onTap: () { Navigator.push( context, @@ -308,8 +308,8 @@ class _AccountStatementScreen extends State { ); }, separatorBuilder: (context, index) { - return const Divider(); - }, + return const Divider(); + }, ), ), ], diff --git a/lib/features/dashboard/screens/dashboard_screen.dart b/lib/features/dashboard/screens/dashboard_screen.dart index 4704ffb..1eb68a2 100644 --- a/lib/features/dashboard/screens/dashboard_screen.dart +++ b/lib/features/dashboard/screens/dashboard_screen.dart @@ -576,7 +576,7 @@ class _DashboardScreenState extends State { style: const TextStyle(fontSize: 15), ), subtitle: Text( - tx.name != null + tx.name != null ? (tx.name!.length > 18 ? tx.name!.substring(0, 22) : tx.name!) diff --git a/lib/features/dashboard/widgets/account_card.dart b/lib/features/dashboard/widgets/account_card.dart index 0669481..4a66715 100644 --- a/lib/features/dashboard/widgets/account_card.dart +++ b/lib/features/dashboard/widgets/account_card.dart @@ -50,7 +50,7 @@ class AccountCard extends StatelessWidget { Text( account.accountNumber, style: TextStyle( - color:Theme.of(context).scaffoldBackgroundColor, fontSize: 16), + color: Theme.of(context).scaffoldBackgroundColor, fontSize: 16), ), const SizedBox(height: 30), Text( diff --git a/lib/features/fund_transfer/screens/fund_transfer_amount_screen.dart b/lib/features/fund_transfer/screens/fund_transfer_amount_screen.dart index 84b41f0..3f8a664 100644 --- a/lib/features/fund_transfer/screens/fund_transfer_amount_screen.dart +++ b/lib/features/fund_transfer/screens/fund_transfer_amount_screen.dart @@ -107,35 +107,50 @@ class _FundTransferAmountScreenState extends State { ); completer.complete(paymentResponse); } on DioException catch (e) { - print('dio exception'); - print(e.toString()); - - final error = jsonDecode(e.response.toString())['error']; - var errorMessage = { - "INCORRECT_TPIN": - AppLocalizations.of(context).correctTpin, - "INSUFFICIENT_FUNDS": - AppLocalizations.of(context).insufficientFund - }[error] ?? - AppLocalizations.of(context).somethingWentWrong; - + print(e); + String errorMessage; + if (e.response != null && e.response!.data != null) { + print('error has data'); + try { + // final error = jsonDecode(e.response!.toString())['error']; + final error = e.response?.data['error']; + print('actual error message $error'); + errorMessage = { + "INCORRECT_TPIN": "Please Enter the correct TPIN", + "INSUFFICIENT_FUNDS": + "Your account does not have sufficient balance" + }[error] ?? + "Something Went Wrong"; + } catch (_) { + print('error extracting errorMessage'); + errorMessage = "Something Went Wrong"; + } + } else { + print('has has no data'); + errorMessage = "Something Went Wrong"; + } + print('PaymentResponse generating'); final paymentResponse = PaymentResponse( isSuccess: false, errorMessage: errorMessage, ); + print('PaymentResponse generated'); + print(paymentResponse); completer.complete(paymentResponse); + print("NEFT transaction failed with DioException."); // Add } catch (e) { print('generic exception'); print(e.toString()); final paymentResponse = PaymentResponse( isSuccess: false, - errorMessage: - AppLocalizations.of(context).somethingWentWrong, + errorMessage: AppLocalizations.of(pinScreenContext) + .somethingWentWrong, ); completer.complete(paymentResponse); + print( + "NEFT transaction failed with generic exception."); // Add } } - //IMPS transaction else if (_selectedMode == TransactionMode.imps) { final impsTx = ImpsTransaction( @@ -195,7 +210,9 @@ class _FundTransferAmountScreenState extends State { ); completer.complete(paymentResponse); } - } else { + } + //RTGS + else { final rtgsTx = RtgsTransaction( fromAccount: widget.debitAccountNo, toAccount: widget.creditBeneficiary.accountNo, @@ -233,13 +250,12 @@ class _FundTransferAmountScreenState extends State { final error = jsonDecode(e.response.toString())['error']; var errorMessage = { - "INCORRECT_TPIN": - AppLocalizations.of(context).correctTpin, + "INCORRECT_TPIN": "Please Enter the correct TPIN", "INSUFFICIENT_FUNDS": - AppLocalizations.of(context).insufficientFund + "Your account does not have sufficient balance" // ignore: use_build_context_synchronously }[error] ?? - AppLocalizations.of(context).somethingWentWrong; + "Something Went Wrong"; final paymentResponse = PaymentResponse( isSuccess: false, @@ -251,8 +267,7 @@ class _FundTransferAmountScreenState extends State { print(e.toString()); final paymentResponse = PaymentResponse( isSuccess: false, - errorMessage: - AppLocalizations.of(context).somethingWentWrong, + errorMessage: "Something Went Wrong", ); completer.complete(paymentResponse); } diff --git a/lib/features/quick_pay/screens/quick_pay_outside_bank_screen.dart b/lib/features/quick_pay/screens/quick_pay_outside_bank_screen.dart index 0b564e1..e8faeb4 100644 --- a/lib/features/quick_pay/screens/quick_pay_outside_bank_screen.dart +++ b/lib/features/quick_pay/screens/quick_pay_outside_bank_screen.dart @@ -1,6 +1,7 @@ // ignore_for_file: use_build_context_synchronously import 'dart:async'; +import 'package:dio/dio.dart'; import 'package:flutter/services.dart'; import 'package:kmobile/api/services/imps_service.dart'; import 'package:kmobile/api/services/neft_service.dart'; @@ -214,6 +215,38 @@ class _QuickPayOutsideBankScreen extends State { utr: neftResponse.utr, ); completer.complete(paymentResponse); + } on DioException catch (e) { + print(e); + String errorMessage; + if (e.response != null && e.response!.data != null) { + print('error has data'); + try { + // final error = jsonDecode(e.response!.toString())['error']; + final error = e.response?.data['error']; + print('actual error message $error'); + errorMessage = { + "INCORRECT_TPIN": "Please Enter the correct TPIN", + "INSUFFICIENT_FUNDS": + "Your account does not have sufficient balance" + }[error] ?? + "Something Went Wrong"; + } catch (_) { + print('error extracting errorMessage'); + errorMessage = "Something Went Wrong"; + } + } else { + print('has has no data'); + errorMessage = "Something Went Wrong"; + } + print('PaymentResponse generating'); + final paymentResponse = PaymentResponse( + isSuccess: false, + errorMessage: errorMessage, + ); + print('PaymentResponse generated'); + print(paymentResponse); + completer.complete(paymentResponse); + print("NEFT transaction failed with DioException."); // Add } catch (e) { final paymentResponse = PaymentResponse( isSuccess: false, @@ -245,15 +278,32 @@ class _QuickPayOutsideBankScreen extends State { ); try { - final neftResponse = + final impsResponse = await impsService.processImpsTransaction(impsTx); final paymentResponse = PaymentResponse( - isSuccess: neftResponse.message.toUpperCase() == 'SUCCESS', + isSuccess: impsResponse.message.toUpperCase() == 'SUCCESS', date: DateTime.now(), creditedAccount: impsTx.toAccount, amount: impsTx.amount, currency: 'INR', - utr: neftResponse.utr, + utr: impsResponse.utr, + ); + completer.complete(paymentResponse); + } on DioException catch (e) { + print('dio exception'); + print(e.toString()); + + final error = e.response?.data['error']; + var errorMessage = { + "INCORRECT_TPIN": "Please Enter the correct TPIN", + "INSUFFICIENT_FUNDS": + "Your account does not have sufficient balance" + }[error] ?? + "Something Went Wrong"; + + final paymentResponse = PaymentResponse( + isSuccess: false, + errorMessage: errorMessage, ); completer.complete(paymentResponse); } catch (e) { @@ -298,6 +348,25 @@ class _QuickPayOutsideBankScreen extends State { utr: rtgsResponse.utr, ); completer.complete(paymentResponse); + } on DioException catch (e) { + print('dio exception'); + print(e.toString()); + + final error = e.response?.data['error']; + var errorMessage = { + "INCORRECT_TPIN": "Please Enter the correct TPIN", + "INSUFFICIENT_FUNDS": + "Your account does not have sufficient balance" + // ignore: duplicate_ignore + // ignore: use_build_context_synchronously + }[error] ?? + "Something Went Wrong"; + + final paymentResponse = PaymentResponse( + isSuccess: false, + errorMessage: errorMessage, + ); + completer.complete(paymentResponse); } catch (e) { final paymentResponse = PaymentResponse( isSuccess: false,