updated the look and feel of the home page
This commit is contained in:
@@ -7,9 +7,10 @@ import 'package:qpay/models/api_response.dart';
|
||||
import 'package:qpay/screens/pay/pay_controller.dart' as pc;
|
||||
import 'package:qpay/screens/transaction_controller.dart' as tc;
|
||||
import 'package:qpay/screens/home/home_controller.dart' as hc;
|
||||
import 'package:qpay/screens/transactions/transaction_model.dart';
|
||||
|
||||
class ReceiptModel {
|
||||
Map<String, dynamic>? receiptData;
|
||||
TransactionModel? transaction;
|
||||
bool isLoading = false;
|
||||
String? errorMessage;
|
||||
String status = '';
|
||||
@@ -35,7 +36,7 @@ class ReceiptController extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<ApiResponse<Map<String, dynamic>>> doIntegration(String id) async {
|
||||
Future<ApiResponse<TransactionModel>> doIntegration(String id) async {
|
||||
try {
|
||||
model.isLoading = true;
|
||||
model.status = '';
|
||||
@@ -51,9 +52,13 @@ class ReceiptController extends ChangeNotifier {
|
||||
|
||||
if (response['status'] == 'SUCCESS') {
|
||||
model.status = response['status'];
|
||||
transactionController.updateReceiptData(response);
|
||||
transactionController.updateReceiptData(
|
||||
Map<String, dynamic>.from(response),
|
||||
);
|
||||
notifyListeners();
|
||||
return ApiResponse.success(Map<String, dynamic>.from(response));
|
||||
return ApiResponse.success(
|
||||
TransactionModel.fromJson(Map<String, dynamic>.from(response)),
|
||||
);
|
||||
} else {
|
||||
model.status = response['status'];
|
||||
model.errorMessage = response['errorMessage'];
|
||||
@@ -70,10 +75,10 @@ class ReceiptController extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> repeatTransaction(BuildContext context) async {
|
||||
Future<void> repeatTransaction(TransactionModel transaction) async {
|
||||
setLoading(true);
|
||||
// fetch provider & update tran controller
|
||||
String providerId = model.receiptData?['billClientId'] ?? '';
|
||||
String providerId = transaction.billClientId ?? '';
|
||||
Map<String, dynamic> provider = await http.get(
|
||||
'/public/providers/client/$providerId',
|
||||
);
|
||||
@@ -84,16 +89,16 @@ class ReceiptController extends ChangeNotifier {
|
||||
// update tran controller formdata with credit account, email, name, phone & providerLabel
|
||||
transactionController.model.formData = transactionController.model.formData
|
||||
.copyWith(
|
||||
creditAccount: model.receiptData?['creditAccount'] ?? '',
|
||||
creditPhone: model.receiptData?['creditPhone'] ?? '',
|
||||
creditName: model.receiptData?['creditName'] ?? '',
|
||||
creditEmail: model.receiptData?['creditEmail'] ?? '',
|
||||
creditAccount: transaction.creditAccount ?? '',
|
||||
creditPhone: transaction.creditPhone ?? '',
|
||||
creditName: transaction.creditName ?? '',
|
||||
creditEmail: transaction.creditEmail ?? '',
|
||||
);
|
||||
|
||||
// fetch product and update tran controller formdata
|
||||
String providerUid =
|
||||
transactionController.model.selectedProvider?.uid ?? '';
|
||||
String productUid = model.receiptData?['productUid'] ?? '';
|
||||
String productUid = transaction.productUid ?? '';
|
||||
|
||||
if (productUid.isNotEmpty) {
|
||||
Map<String, dynamic> product = await http.get(
|
||||
@@ -105,27 +110,26 @@ class ReceiptController extends ChangeNotifier {
|
||||
}
|
||||
|
||||
// update credit amount, notification phone number, payment processor
|
||||
transactionController
|
||||
.model
|
||||
.formData = transactionController.model.formData.copyWith(
|
||||
amount: model.receiptData?['amount'].toStringAsFixed(2) ?? '',
|
||||
debitPhone: model.receiptData?['debitPhone'] ?? '',
|
||||
paymentProcessorLabel: model.receiptData?['paymentProcessorLabel'] ?? '',
|
||||
paymentProcessorName: model.receiptData?['paymentProcessorName'] ?? '',
|
||||
id: null,
|
||||
);
|
||||
transactionController.model.formData = transactionController.model.formData
|
||||
.copyWith(
|
||||
amount: transaction.amount.toStringAsFixed(2),
|
||||
debitPhone: transaction.debitPhone,
|
||||
paymentProcessorLabel: transaction.paymentProcessorLabel,
|
||||
paymentProcessorName: transaction.paymentProcessorName,
|
||||
id: null,
|
||||
);
|
||||
|
||||
setLoading(false);
|
||||
context.push('/make-payment');
|
||||
}
|
||||
|
||||
Future<ApiResponse<Map<String, dynamic>>> getReceiptData(String id) async {
|
||||
Future<ApiResponse<TransactionModel>> getReceiptData(String id) async {
|
||||
setLoading(true);
|
||||
try {
|
||||
Map<String, dynamic> response = await http.get('/public/transaction/$id');
|
||||
model.receiptData = response;
|
||||
final transaction = TransactionModel.fromJson(response);
|
||||
model.transaction = transaction;
|
||||
setLoading(false);
|
||||
return ApiResponse.success(response);
|
||||
return ApiResponse.success(transaction);
|
||||
} catch (e) {
|
||||
setLoading(false);
|
||||
return ApiResponse.failure(
|
||||
@@ -134,8 +138,8 @@ class ReceiptController extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
void updateReceiptData(Map<String, dynamic> data) {
|
||||
model.receiptData = data;
|
||||
void updateReceiptTransaction(TransactionModel data) {
|
||||
model.transaction = data;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user