completed first web iteration
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
@@ -17,6 +15,7 @@ class _GatewayScreenState extends State<GatewayScreen> {
|
||||
late WebViewController _webViewController;
|
||||
late GatewayController controller;
|
||||
late String url;
|
||||
String? sessionID;
|
||||
|
||||
bool integrationStarted = false;
|
||||
|
||||
@@ -24,63 +23,71 @@ class _GatewayScreenState extends State<GatewayScreen> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
controller = GatewayController(context);
|
||||
// https://na.gateway.mastercard.com/checkout/pay/SESSION0002220827459I8059951J88?checkoutVersion=1.0.0
|
||||
|
||||
url = controller.transactionController.model.receiptData?['targetUrl'];
|
||||
_initWebView(url);
|
||||
|
||||
_initWebView();
|
||||
}
|
||||
|
||||
void _initWebView() async {
|
||||
_webViewController = WebViewController()
|
||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||
..setNavigationDelegate(
|
||||
NavigationDelegate(
|
||||
onProgress: (int progress) {
|
||||
// Update loading bar.
|
||||
},
|
||||
onPageStarted: (String url) {
|
||||
controller.startLoading();
|
||||
},
|
||||
onPageFinished: (String url) {
|
||||
controller.finishLoading();
|
||||
},
|
||||
onHttpError: (HttpResponseError error) {},
|
||||
onWebResourceError: (WebResourceError error) {},
|
||||
onUrlChange: (UrlChange url) async {
|
||||
print("URL Changed to ${url.url!}");
|
||||
|
||||
_navigateWhenDone(url.url!);
|
||||
},
|
||||
),
|
||||
)
|
||||
..loadRequest(Uri.parse(url));
|
||||
|
||||
bool simulate = bool.parse(dotenv.env['SIMULATE_PAYMENT_SUCCESS']!);
|
||||
if(simulate) {
|
||||
sleep(Duration(seconds: 10));
|
||||
if (simulate) {
|
||||
await Future.delayed(Duration(seconds: 10));
|
||||
String targetUrl = url.replaceAll("/pay/", "/receipt/");
|
||||
_webViewController.loadRequest(Uri.parse(targetUrl));
|
||||
}
|
||||
}
|
||||
|
||||
void _initWebView(String url) {
|
||||
_webViewController =
|
||||
WebViewController()
|
||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||
..setNavigationDelegate(
|
||||
NavigationDelegate(
|
||||
onProgress: (int progress) {
|
||||
// Update loading bar.
|
||||
},
|
||||
onPageStarted: (String url) {
|
||||
controller.startLoading();
|
||||
},
|
||||
onPageFinished: (String url) {
|
||||
controller.finishLoading();
|
||||
},
|
||||
onHttpError: (HttpResponseError error) {},
|
||||
onWebResourceError: (WebResourceError error) {},
|
||||
onUrlChange: (UrlChange url) async {
|
||||
print("URL Changed to ${url.url!}");
|
||||
void _navigateWhenDone(String url) {
|
||||
if (url.contains("/checkout/receipt/")) {
|
||||
if (integrationStarted) {
|
||||
return;
|
||||
}
|
||||
|
||||
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: 10),
|
||||
),
|
||||
);
|
||||
|
||||
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: 10),
|
||||
),
|
||||
);
|
||||
setState(() {
|
||||
integrationStarted = true;
|
||||
});
|
||||
|
||||
setState(() {
|
||||
integrationStarted = true;
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.go('/integration');
|
||||
});
|
||||
}
|
||||
}
|
||||
),
|
||||
)
|
||||
..loadRequest(Uri.parse(url));
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.go('/integration');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -94,15 +101,14 @@ class _GatewayScreenState extends State<GatewayScreen> {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Complete your payment'),
|
||||
leading:
|
||||
context.canPop()
|
||||
? IconButton(
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
},
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
)
|
||||
: SizedBox.shrink(),
|
||||
leading: context.canPop()
|
||||
? IconButton(
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
},
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
)
|
||||
: SizedBox.shrink(),
|
||||
),
|
||||
body: ListenableBuilder(
|
||||
listenable: controller,
|
||||
@@ -112,9 +118,12 @@ class _GatewayScreenState extends State<GatewayScreen> {
|
||||
context.go('/integration');
|
||||
});
|
||||
}
|
||||
|
||||
return controller.model.isLoading
|
||||
? const Center(child: CircularProgressIndicator(strokeWidth: 5))
|
||||
: WebViewWidget(controller: _webViewController);
|
||||
: SizedBox.expand(
|
||||
child: WebViewWidget(controller: _webViewController),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user