81 lines
2.3 KiB
Dart
81 lines
2.3 KiB
Dart
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:qpay/http/http.dart';
|
|
import 'package:qpay/screens/gateway/gateway_controller.dart';
|
|
import 'package:qpay/screens/transaction_controller.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class IntegrationModel {
|
|
Map<String, dynamic>? transaction;
|
|
String status = '';
|
|
bool isLoading = false;
|
|
String? errorMessage;
|
|
}
|
|
|
|
class IntegrationController extends ChangeNotifier {
|
|
final IntegrationModel model = IntegrationModel();
|
|
final Http http = Http();
|
|
late TransactionController transactionController;
|
|
late GatewayController gatewayController;
|
|
late SharedPreferences prefs;
|
|
|
|
BuildContext context;
|
|
|
|
IntegrationController(this.context) {
|
|
transactionController = Provider.of<TransactionController>(
|
|
context,
|
|
listen: false,
|
|
);
|
|
|
|
gatewayController = GatewayController(context);
|
|
}
|
|
|
|
void _showErrorSnackBar(String? message) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(message.toString()),
|
|
behavior: SnackBarBehavior.floating,
|
|
backgroundColor: Colors.deepOrange,
|
|
),
|
|
);
|
|
});
|
|
}
|
|
|
|
|
|
Future<void> doIntegration() async {
|
|
try {
|
|
model.isLoading = true;
|
|
notifyListeners();
|
|
|
|
dynamic workflowResponse = await http.get(
|
|
'/public/transaction/integration/'
|
|
'${transactionController.model.confirmationData['id']}'
|
|
);
|
|
logger.i(workflowResponse.toString());
|
|
|
|
dynamic response = workflowResponse['body'];
|
|
|
|
if (response['status'] == 'SUCCESS') {
|
|
model.status = response['status'];
|
|
transactionController.updateReceiptData(response);
|
|
|
|
gatewayController.poll(transactionController.model.confirmationData['id']);
|
|
} else {
|
|
model.status = response['status'];
|
|
model.errorMessage = response['errorMessage'];
|
|
_showErrorSnackBar(response['errorMessage']);
|
|
}
|
|
model.isLoading = false;
|
|
notifyListeners();
|
|
|
|
} catch (e) {
|
|
model.isLoading = false;
|
|
model.errorMessage = e.toString();
|
|
notifyListeners();
|
|
}
|
|
}
|
|
} |