IMPS implementation
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
// ignore_for_file: avoid_print
|
||||
// ignore_for_file: avoid_print, use_build_context_synchronously, duplicate_ignore
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/api/services/neft_service.dart';
|
||||
import 'package:kmobile/api/services/rtgs_service.dart';
|
||||
import 'package:kmobile/api/services/imps_service.dart';
|
||||
import 'package:kmobile/data/models/imps_transaction.dart';
|
||||
import 'package:kmobile/widgets/bank_logos.dart';
|
||||
import 'package:kmobile/data/models/beneficiary.dart';
|
||||
import 'package:kmobile/data/models/neft_transaction.dart';
|
||||
@@ -15,7 +17,7 @@ import 'package:kmobile/features/fund_transfer/screens/payment_animation.dart';
|
||||
import 'package:kmobile/features/fund_transfer/screens/transaction_pin_screen.dart';
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
|
||||
enum TransactionMode { neft, rtgs }
|
||||
enum TransactionMode { neft, rtgs, imps }
|
||||
|
||||
class FundTransferAmountScreen extends StatefulWidget {
|
||||
final String debitAccountNo;
|
||||
@@ -133,64 +135,66 @@ class _FundTransferAmountScreenState extends State<FundTransferAmountScreen> {
|
||||
completer.complete(paymentResponse);
|
||||
}
|
||||
}
|
||||
// else if (_selectedMode == TransactionMode.imps){
|
||||
// final rtgsTx = RtgsTransaction(
|
||||
// fromAccount: widget.debitAccountNo,
|
||||
// toAccount: widget.creditBeneficiary.accountNo,
|
||||
// amount: _amountController.text,
|
||||
// ifscCode: widget.creditBeneficiary.ifscCode,
|
||||
// remitterName: widget.remitterName,
|
||||
// beneficiaryName: widget.creditBeneficiary.name,
|
||||
// tpin: tpin,
|
||||
// );
|
||||
// final rtgsService = getIt<RtgsService>();
|
||||
// final completer = Completer<PaymentResponse>();
|
||||
|
||||
//IMPS transaction
|
||||
else if (_selectedMode == TransactionMode.imps){
|
||||
final impsTx = ImpsTransaction(
|
||||
fromAccount: widget.debitAccountNo,
|
||||
toAccount: widget.creditBeneficiary.accountNo,
|
||||
amount: _amountController.text,
|
||||
ifscCode: widget.creditBeneficiary.ifscCode,
|
||||
remitterName: widget.remitterName,
|
||||
beneficiaryName: widget.creditBeneficiary.name,
|
||||
tpin: tpin,
|
||||
);
|
||||
final impsService = getIt<ImpsService>();
|
||||
final completer = Completer<PaymentResponse>();
|
||||
|
||||
// Navigator.of(pinScreenContext).pushReplacement(
|
||||
// MaterialPageRoute(
|
||||
// builder: (_) => PaymentAnimationScreen(
|
||||
// paymentResponse: completer.future),
|
||||
// ),
|
||||
// );
|
||||
Navigator.of(pinScreenContext).pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => PaymentAnimationScreen(
|
||||
paymentResponse: completer.future),
|
||||
),
|
||||
);
|
||||
|
||||
// try {
|
||||
// final rtgsResponse =
|
||||
// await rtgsService.processRtgsTransaction(rtgsTx);
|
||||
// final paymentResponse = PaymentResponse(
|
||||
// isSuccess: rtgsResponse.message.toUpperCase() == 'SUCCESS',
|
||||
// date: DateTime.now(),
|
||||
// creditedAccount: rtgsTx.toAccount,
|
||||
// amount: rtgsTx.amount,
|
||||
// currency: 'INR',
|
||||
// utr: rtgsResponse.utr,
|
||||
// );
|
||||
// completer.complete(paymentResponse);
|
||||
// } on DioException catch(e) {
|
||||
// print('dio exception');
|
||||
// print(e.toString());
|
||||
try {
|
||||
final impsResponse =
|
||||
await impsService.processImpsTransaction(impsTx);
|
||||
final paymentResponse = PaymentResponse(
|
||||
isSuccess: impsResponse.message.toUpperCase() == 'SUCCESS',
|
||||
date: DateTime.now(),
|
||||
creditedAccount: impsTx.toAccount,
|
||||
amount: impsTx.amount,
|
||||
currency: 'INR',
|
||||
utr: impsResponse.utr,
|
||||
);
|
||||
completer.complete(paymentResponse);
|
||||
} on DioException catch(e) {
|
||||
print('dio exception');
|
||||
print(e.toString());
|
||||
|
||||
// final error = jsonDecode(e.response.toString())['error'];
|
||||
// var errorMessage =
|
||||
// {
|
||||
// "INCORRECT_TPIN" : "Please Enter the correct TPIN",
|
||||
// "INSUFFICIENT_FUNDS": "Your account does not have sufficient balance"
|
||||
// }[error] ?? "Something Went Wrong";
|
||||
final error = jsonDecode(e.response.toString())['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) {
|
||||
// print('generic exception');
|
||||
// print(e.toString());
|
||||
// final paymentResponse = PaymentResponse(
|
||||
// isSuccess: false,
|
||||
// errorMessage: "Something went Wrong",
|
||||
// );
|
||||
// completer.complete(paymentResponse);
|
||||
// }
|
||||
// }
|
||||
final paymentResponse = PaymentResponse(
|
||||
isSuccess: false,
|
||||
errorMessage: errorMessage,
|
||||
);
|
||||
completer.complete(paymentResponse);
|
||||
} catch (e) {
|
||||
print('generic exception');
|
||||
print(e.toString());
|
||||
final paymentResponse = PaymentResponse(
|
||||
isSuccess: false,
|
||||
errorMessage: "Something went Wrong",
|
||||
);
|
||||
completer.complete(paymentResponse);
|
||||
}
|
||||
}
|
||||
else {
|
||||
final rtgsTx = RtgsTransaction(
|
||||
fromAccount: widget.debitAccountNo,
|
||||
@@ -325,7 +329,9 @@ class _FundTransferAmountScreenState extends State<FundTransferAmountScreen> {
|
||||
child: ToggleButtons(
|
||||
isSelected: [
|
||||
_selectedMode == TransactionMode.neft,
|
||||
_selectedMode == TransactionMode.rtgs
|
||||
_selectedMode == TransactionMode.rtgs,
|
||||
_selectedMode == TransactionMode.imps,
|
||||
|
||||
],
|
||||
onPressed: (index) {
|
||||
setState(() {
|
||||
@@ -352,10 +358,10 @@ class _FundTransferAmountScreenState extends State<FundTransferAmountScreen> {
|
||||
horizontal: 24.0, vertical: 12.0),
|
||||
child: Text(AppLocalizations.of(context).rtgs),
|
||||
),
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
|
||||
// child: Text(AppLocalizations.of(context).imps),
|
||||
// ),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
|
||||
child: Text(AppLocalizations.of(context).imps),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
Reference in New Issue
Block a user