implemented TPIN and quick pay within bank
This commit is contained in:
19
lib/data/models/payment_response.dart
Normal file
19
lib/data/models/payment_response.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
class PaymentResponse {
|
||||
final bool isSuccess;
|
||||
final DateTime? date;
|
||||
final String? creditedAccount;
|
||||
final String? amount;
|
||||
final String? currency;
|
||||
final String? errorMessage;
|
||||
final String? errorCode;
|
||||
|
||||
PaymentResponse({
|
||||
required this.isSuccess,
|
||||
this.date,
|
||||
this.creditedAccount,
|
||||
this.amount,
|
||||
this.currency,
|
||||
this.errorMessage,
|
||||
this.errorCode,
|
||||
});
|
||||
}
|
@@ -2,7 +2,7 @@ class Transaction {
|
||||
final String? id;
|
||||
final String? name;
|
||||
final String? date;
|
||||
final int? amount;
|
||||
final String? amount;
|
||||
final String? type;
|
||||
|
||||
Transaction({this.id, this.name, this.date, this.amount, this.type});
|
||||
@@ -21,7 +21,7 @@ class Transaction {
|
||||
id: json['id'] as String?,
|
||||
name: json['name'] as String?,
|
||||
date: json['date'] as String?,
|
||||
amount: json['amount'] as int?,
|
||||
amount: json['amount'] as String?,
|
||||
type: json['type'] as String?,
|
||||
);
|
||||
}
|
||||
|
45
lib/data/models/transfer.dart
Normal file
45
lib/data/models/transfer.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
class Transfer {
|
||||
final String fromAccount;
|
||||
final String toAccount;
|
||||
final String toAccountType;
|
||||
final String amount;
|
||||
String? tpin;
|
||||
|
||||
Transfer({
|
||||
required this.fromAccount,
|
||||
required this.toAccount,
|
||||
required this.toAccountType,
|
||||
required this.amount,
|
||||
this.tpin,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'fromAccount': fromAccount,
|
||||
'toAccount': toAccount,
|
||||
'toAccountType': toAccountType,
|
||||
'amount': amount,
|
||||
'tpin': tpin,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class TransferResponse {
|
||||
final String? status;
|
||||
final String? message;
|
||||
final String? error;
|
||||
|
||||
TransferResponse({
|
||||
required this.status,
|
||||
required this.message,
|
||||
required this.error,
|
||||
});
|
||||
|
||||
factory TransferResponse.fromJson(Map<String, dynamic> json) {
|
||||
return TransferResponse(
|
||||
status: json['status'] as String?,
|
||||
message: json['message'] as String?,
|
||||
error: json['error'] as String?,
|
||||
);
|
||||
}
|
||||
}
|
28
lib/data/repositories/transaction_repository.dart
Normal file
28
lib/data/repositories/transaction_repository.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:kmobile/data/models/transaction.dart';
|
||||
|
||||
abstract class TransactionRepository {
|
||||
Future<List<Transaction>> fetchTransactions(String accountNo);
|
||||
}
|
||||
|
||||
class TransactionRepositoryImpl implements TransactionRepository {
|
||||
final Dio _dio;
|
||||
TransactionRepositoryImpl(this._dio);
|
||||
|
||||
@override
|
||||
Future<List<Transaction>> fetchTransactions(String accountNo) async {
|
||||
|
||||
final resp = await _dio.get('/api/transactions/account/$accountNo');
|
||||
|
||||
if (resp.statusCode != 200) {
|
||||
throw Exception(
|
||||
'Error fetching transactions: ${resp.statusCode} ${resp.statusMessage}',
|
||||
);
|
||||
}
|
||||
|
||||
final List<dynamic> data = resp.data as List<dynamic>;
|
||||
return data
|
||||
.map((e) => Transaction.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
}
|
28
lib/data/repositories/transfer_repository.dart
Normal file
28
lib/data/repositories/transfer_repository.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:kmobile/data/models/transfer.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
|
||||
abstract class TransferRepository {
|
||||
Future<TransferResponse> transfer(Transfer transfer);
|
||||
}
|
||||
|
||||
class TransferRepositoryImpl implements TransferRepository {
|
||||
final Dio _dio;
|
||||
TransferRepositoryImpl(this._dio);
|
||||
|
||||
@override
|
||||
Future<TransferResponse> transfer(Transfer transfer) async {
|
||||
final resp = await _dio.post(
|
||||
'/api/payment/transfer',
|
||||
data: transfer.toJson(),
|
||||
);
|
||||
|
||||
if (resp.statusCode != 200) {
|
||||
throw Exception(
|
||||
'Error transferring funds: ${resp.statusCode} ${resp.statusMessage}',
|
||||
);
|
||||
}
|
||||
|
||||
return TransferResponse.fromJson(resp.data as Map<String, dynamic>);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user