imrpoving tran flow

This commit is contained in:
2025-10-31 09:47:58 +02:00
parent bcc9d629c1
commit 52c8290625
9 changed files with 327 additions and 82 deletions

View File

@@ -1,4 +1,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:go_router/go_router.dart';
import 'package:qpay/screens/gateway/gateway_controller.dart';
import 'package:webview_flutter/webview_flutter.dart';
@@ -15,14 +18,20 @@ class _GatewayScreenState extends State<GatewayScreen> {
late WebViewController _webViewController;
late GatewayController controller;
bool integrationStarted = false;
@override
void initState() {
super.initState();
_initWebView(widget.url);
controller = GatewayController(context);
controller.pollTransaction(
controller.transactionController.model.receiptData?['id'],
);
bool simulate = bool.parse(dotenv.env['SIMULATE_PAYMENT_SUCCESS']!);
if(simulate) {
sleep(Duration(seconds: 10));
String url = widget.url.replaceAll("/pay/", "/receipt/");
_webViewController.loadRequest(Uri.parse(url));
}
}
void _initWebView(String url) {
@@ -42,6 +51,33 @@ class _GatewayScreenState extends State<GatewayScreen> {
},
onHttpError: (HttpResponseError error) {},
onWebResourceError: (WebResourceError error) {},
onUrlChange: (UrlChange url) async {
print("URL Changed to ${url.url!}");
if(url.url!.contains("/checkout/receipt/")){
if(integrationStarted) {
return;
}
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Payment was successful, please wait while we process your order."),
behavior: SnackBarBehavior.floating,
backgroundColor: Colors.black87,
duration: const Duration(seconds: 5),
),
);
setState(() {
integrationStarted = true;
});
await controller.poll(controller.transactionController.model.receiptData?['id']);
WidgetsBinding.instance.addPostFrameCallback((_) {
context.go('/integration');
});
}
}
),
)
..loadRequest(Uri.parse(url));