completed velocity integration
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:qpay/models/api_response.dart';
|
||||
import 'package:qpay/screens/transaction_controller.dart';
|
||||
|
||||
import '../../http/http.dart';
|
||||
@@ -53,7 +53,7 @@ class ConfirmController extends ChangeNotifier {
|
||||
});
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>?> doTransaction() async {
|
||||
Future<ApiResponse<Map<String, dynamic>>> doTransaction() async {
|
||||
try {
|
||||
model.isLoading = true;
|
||||
notifyListeners();
|
||||
@@ -77,33 +77,30 @@ class ConfirmController extends ChangeNotifier {
|
||||
|
||||
dynamic response = workflowResponse['body'];
|
||||
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
|
||||
if (response['status'] != 'FAILED') {
|
||||
model.status = response['status'];
|
||||
|
||||
transactionController.updateReceiptData(response);
|
||||
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
return response;
|
||||
return ApiResponse.success(Map<String, dynamic>.from(response));
|
||||
} else {
|
||||
model.status = response['status'];
|
||||
model.errorMessage = response['errorMessage'];
|
||||
_showErrorSnackBar(response['errorMessage']);
|
||||
return ApiResponse.failure(response['errorMessage'] ?? "Transaction failed");
|
||||
}
|
||||
} catch (e) {
|
||||
logger.e(e);
|
||||
model.errorMessage = e.toString();
|
||||
_showErrorSnackBar(
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
return ApiResponse.failure(
|
||||
"Problem completing the transaction, please try again.",
|
||||
);
|
||||
}
|
||||
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> pollTransaction(String uid) async {
|
||||
Future<ApiResponse<Map<String, dynamic>>> pollTransaction(String uid) async {
|
||||
while (!model.isCancelled) {
|
||||
// Check again after delay in case it was cancelled during the delay
|
||||
if (model.isCancelled) break;
|
||||
@@ -117,7 +114,7 @@ class ConfirmController extends ChangeNotifier {
|
||||
transactionController.updateReceiptData(response);
|
||||
model.isCancelled = true;
|
||||
notifyListeners();
|
||||
break;
|
||||
return ApiResponse.success(Map<String, dynamic>.from(response));
|
||||
}
|
||||
} catch (e) {
|
||||
logger.e(e);
|
||||
@@ -130,6 +127,7 @@ class ConfirmController extends ChangeNotifier {
|
||||
// Wait 5 seconds before the next poll
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
}
|
||||
return ApiResponse.failure("Polling cancelled");
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user