Language Changes
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,
|
||||
});
|
||||
}
|
28
lib/data/models/transaction.dart
Normal file
28
lib/data/models/transaction.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
class Transaction {
|
||||
final String? id;
|
||||
final String? name;
|
||||
final String? date;
|
||||
final String? amount;
|
||||
final String? type;
|
||||
|
||||
Transaction({this.id, this.name, this.date, this.amount, this.type});
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'date': date,
|
||||
'amount': amount,
|
||||
'type': type,
|
||||
};
|
||||
}
|
||||
|
||||
factory Transaction.fromJson(Map<String, dynamic> json) {
|
||||
return Transaction(
|
||||
id: json['id'] as String?,
|
||||
name: json['name'] as String?,
|
||||
date: json['date'] as String?,
|
||||
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?,
|
||||
);
|
||||
}
|
||||
}
|
113
lib/data/models/user.dart
Normal file
113
lib/data/models/user.dart
Normal file
@@ -0,0 +1,113 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:kmobile/data/models/transaction.dart';
|
||||
|
||||
class User extends Equatable {
|
||||
final String? accountNo;
|
||||
final String? accountType;
|
||||
final String? bookingNumber;
|
||||
final String? branchId;
|
||||
final String? currency;
|
||||
final String? productType;
|
||||
final String? approvedAmount;
|
||||
final String? availableBalance;
|
||||
final String? currentBalance;
|
||||
final String? name;
|
||||
final String? mobileNo;
|
||||
final String? address;
|
||||
final String? picode;
|
||||
final int? activeAccounts;
|
||||
final String? cifNumber;
|
||||
final String? primaryId;
|
||||
final String? dateOfBirth;
|
||||
final List<Transaction>? transactions;
|
||||
|
||||
const User({
|
||||
required this.accountNo,
|
||||
required this.accountType,
|
||||
this.bookingNumber,
|
||||
required this.branchId,
|
||||
required this.currency,
|
||||
this.productType,
|
||||
this.approvedAmount,
|
||||
required this.availableBalance,
|
||||
required this.currentBalance,
|
||||
required this.name,
|
||||
required this.mobileNo,
|
||||
required this.address,
|
||||
required this.picode,
|
||||
this.transactions,
|
||||
this.activeAccounts,
|
||||
this.cifNumber,
|
||||
this.primaryId,
|
||||
this.dateOfBirth,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'stAccountNo': accountNo,
|
||||
'stAccountType': accountType,
|
||||
'stBookingNumber': bookingNumber,
|
||||
'stBranchId': branchId,
|
||||
'stCurrency': currency,
|
||||
'stProductType': productType,
|
||||
'stApprovedAmount': approvedAmount,
|
||||
'stAvailableBalance': availableBalance,
|
||||
'stCurrentBalance': currentBalance,
|
||||
'custname': name,
|
||||
'mobileno': mobileNo,
|
||||
'custaddress': address,
|
||||
'picode': picode,
|
||||
'transactions': transactions?.map((tx) => tx.toJson()).toList(),
|
||||
'activeAccounts': activeAccounts,
|
||||
'cifNumber': cifNumber,
|
||||
'primaryId': primaryId,
|
||||
'dateOfBirth': dateOfBirth,
|
||||
};
|
||||
}
|
||||
|
||||
factory User.fromJson(Map<String, dynamic> json) {
|
||||
return User(
|
||||
accountNo: json['stAccountNo'],
|
||||
accountType: json['stAccountType'],
|
||||
bookingNumber: json['stBookingNumber'],
|
||||
branchId: json['stBranchNo'],
|
||||
currency: json['stCurrency'],
|
||||
productType: json['stProductType'],
|
||||
approvedAmount: json['stApprovedAmount'],
|
||||
availableBalance: json['stAvailableBalance'],
|
||||
currentBalance: json['stCurrentBalance'],
|
||||
name: json['custname'],
|
||||
mobileNo: json['mobileno'],
|
||||
address: json['custaddress'],
|
||||
picode: json['picode'],
|
||||
cifNumber: json['cifNumber'],
|
||||
primaryId: json['id'],
|
||||
activeAccounts: json['activeAccounts'] as int?,
|
||||
dateOfBirth: json['custdob'],
|
||||
transactions: (json['transactions'] as List<dynamic>?)
|
||||
?.map((tx) => Transaction.fromJson(tx))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
accountNo,
|
||||
accountType,
|
||||
bookingNumber,
|
||||
branchId,
|
||||
currency,
|
||||
productType,
|
||||
approvedAmount,
|
||||
availableBalance,
|
||||
currentBalance,
|
||||
name,
|
||||
mobileNo,
|
||||
address,
|
||||
picode,
|
||||
transactions,
|
||||
activeAccounts,
|
||||
cifNumber,
|
||||
primaryId,
|
||||
];
|
||||
}
|
62
lib/data/repositories/auth_repository.dart
Normal file
62
lib/data/repositories/auth_repository.dart
Normal file
@@ -0,0 +1,62 @@
|
||||
import 'package:kmobile/api/services/user_service.dart';
|
||||
|
||||
import '../../api/services/auth_service.dart';
|
||||
import '../../features/auth/models/auth_token.dart';
|
||||
import '../../features/auth/models/auth_credentials.dart';
|
||||
import '../../data/models/user.dart';
|
||||
import '../../security/secure_storage.dart';
|
||||
|
||||
class AuthRepository {
|
||||
final AuthService _authService;
|
||||
final UserService _userService;
|
||||
final SecureStorage _secureStorage;
|
||||
|
||||
static const _accessTokenKey = 'access_token';
|
||||
static const _tokenExpiryKey = 'token_expiry';
|
||||
|
||||
AuthRepository(this._authService, this._userService, this._secureStorage);
|
||||
|
||||
Future<List<User>> login(String customerNo, String password) async {
|
||||
// Create credentials and call service
|
||||
final credentials = AuthCredentials(customerNo: customerNo, password: password);
|
||||
final authToken = await _authService.login(credentials);
|
||||
|
||||
// Save token securely
|
||||
await _saveAuthToken(authToken);
|
||||
|
||||
// Get and save user profile
|
||||
final users = await _userService.getUserDetails();
|
||||
return users;
|
||||
}
|
||||
|
||||
Future<bool> isLoggedIn() async {
|
||||
final token = await _getAuthToken();
|
||||
return token != null && !token.isExpired;
|
||||
}
|
||||
|
||||
Future<String?> getAccessToken() async {
|
||||
final token = await _getAuthToken();
|
||||
if (token == null) return null;
|
||||
|
||||
return token.accessToken;
|
||||
}
|
||||
|
||||
// Private helper methods
|
||||
Future<void> _saveAuthToken(AuthToken token) async {
|
||||
await _secureStorage.write(_accessTokenKey, token.accessToken);
|
||||
await _secureStorage.write(_tokenExpiryKey, token.expiresAt.toIso8601String());
|
||||
}
|
||||
|
||||
Future<AuthToken?> _getAuthToken() async {
|
||||
final accessToken = await _secureStorage.read(_accessTokenKey);
|
||||
final expiryString = await _secureStorage.read(_tokenExpiryKey);
|
||||
|
||||
if (accessToken != null && expiryString != null) {
|
||||
return AuthToken(
|
||||
accessToken: accessToken,
|
||||
expiresAt: DateTime.parse(expiryString),
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
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