@@ -5,17 +5,23 @@ Widget build(BuildContext context) {
55 initialUrl: 'https://checkout.paystack.com/7zu1ot06d0qn9h6',
66 javascriptMode: JavascriptMode.unrestricted,
77 userAgent: 'Flutter;Webview',
8- navigationDelegate: (navigation){
9- //Listen for callback URL
10- if(navigation.url == "https://hello.pstk.xyz/callback"){
8+ navigationDelegate: (navigation) {
9+ //Listen for callback URL
10+ if (navigation.url == "https://hello.pstk.xyz/callback") {
1111 verifyTransaction(reference);
1212 Navigator.of(context).pop(); //close webview
1313 }
14+ if (navigation.url == "https://your-cancel-url.com") {
15+ //handle webview removal
16+ Navigator.of(context).pop(); //close webview
17+ //Run the cancel payment function if you have one
18+ }
1419 return NavigationDecision.navigate;
1520 },
1621 ),
1722 );
18- }`
23+ }
24+ `
1925
2026const js = `import React from 'react';
2127import { WebView } from 'react-native-webview';
@@ -25,6 +31,7 @@ export default function App() {
2531
2632 const authorization_url = 'https://checkout.paystack.com/luKuasMan';
2733 const callback_url = 'https://yourcallback.com';
34+ const cancel_url = "https://your-cancel-url.com";
2835
2936 onNavigationStateChange = state => {
3037
@@ -37,6 +44,12 @@ export default function App() {
3744 const redirectTo = 'window.location = "' + callback_url + '"';
3845 this.webview.injectJavaScript(redirectTo);
3946 }
47+ if (url === cancel_url) {
48+ // handle webview removal
49+ // You can either unmount the component, or
50+ // Use a navigator to pop off the view
51+ // Run the cancel payment function if you have one
52+ }
4053 };
4154
4255 return (
@@ -46,15 +59,16 @@ export default function App() {
4659 onNavigationStateChange={ this.onNavigationStateChange }
4760 />
4861 );
49- }
50- `
62+ }`
5163
5264const kt = `class MainActivity : AppCompatActivity() {
5365
5466 private val authorizationUrl: String
5567 get() = "https://checkout.paystack.com/ok62i2sdld514e4"
5668 private val callbackUrl: String
5769 get() = "https://yourcallback.com"
70+ private val cancelUrl: String
71+ get() = "https://your-cancel-url.com"
5872
5973 override fun onCreate(savedInstanceState: Bundle?) {
6074 // ...
@@ -76,6 +90,11 @@ const kt = `class MainActivity : AppCompatActivity() {
7690 if (url?.host == callbackUrl) {
7791 return true
7892 }
93+ if (url?.host == cancelUrl) {
94+ // handle webview removal
95+ // Run the cancel payment function if you have one
96+ return true
97+ }
7998
8099 return super.shouldOverrideUrlLoading(view, request)
81100 }
0 commit comments