imrpoving tran flow
This commit is contained in:
@@ -9,6 +9,7 @@ class GatewayModel {
|
||||
String status = '';
|
||||
String? errorMessage;
|
||||
bool isCancelled = false;
|
||||
int count = 0;
|
||||
}
|
||||
|
||||
class GatewayController extends ChangeNotifier {
|
||||
@@ -40,6 +41,7 @@ class GatewayController extends ChangeNotifier {
|
||||
|
||||
void startLoading() {
|
||||
model.isLoading = true;
|
||||
model.status = '';
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -48,6 +50,36 @@ class GatewayController extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> poll(String uid) async {
|
||||
startLoading();
|
||||
try {
|
||||
dynamic workflowResponse = await http.get('/public/transaction/poll/$uid');
|
||||
|
||||
logger.i(workflowResponse.toString());
|
||||
|
||||
dynamic response = workflowResponse['body'];
|
||||
|
||||
model.status = response['status'];
|
||||
transactionController.model.paymentStatus = response['status'];
|
||||
transactionController.updateReceiptData(response);
|
||||
|
||||
if(model.status == 'PENDING') {
|
||||
_showErrorSnackBar('Transaction status still pending');
|
||||
}
|
||||
|
||||
if(model.status != 'FAILED') {
|
||||
_showErrorSnackBar(response['errorMessage'].isEmpty ? 'Transaction failed' : response['errorMessage']);
|
||||
}
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
logger.e(e);
|
||||
_showErrorSnackBar(
|
||||
"Network error. Please try again or contact support",
|
||||
);
|
||||
}
|
||||
finishLoading();
|
||||
}
|
||||
|
||||
Future<void> pollTransaction(String uid) async {
|
||||
while (!model.isCancelled) {
|
||||
// Check cancellation flag instead of true
|
||||
@@ -57,25 +89,7 @@ class GatewayController extends ChangeNotifier {
|
||||
// Check again after delay in case it was cancelled during the delay
|
||||
if (model.isCancelled) break;
|
||||
|
||||
try {
|
||||
dynamic workflowResponse = await http.get('/public/transaction/poll/$uid');
|
||||
|
||||
logger.i(workflowResponse.toString());
|
||||
|
||||
dynamic response = workflowResponse['body'];
|
||||
|
||||
if (response['status'] == 'SUCCESS') {
|
||||
model.status = response['status'];
|
||||
transactionController.updateReceiptData(response);
|
||||
notifyListeners();
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
logger.e(e);
|
||||
_showErrorSnackBar(
|
||||
"Network error. Please try again or contact support",
|
||||
);
|
||||
}
|
||||
await poll(uid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user