@@ -5,17 +5,23 @@ Widget build(BuildContext context) {
5
5
initialUrl: 'https://checkout.paystack.com/7zu1ot06d0qn9h6',
6
6
javascriptMode: JavascriptMode.unrestricted,
7
7
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") {
11
11
verifyTransaction(reference);
12
12
Navigator.of(context).pop(); //close webview
13
13
}
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
+ }
14
19
return NavigationDecision.navigate;
15
20
},
16
21
),
17
22
);
18
- }`
23
+ }
24
+ `
19
25
20
26
const js = `import React from 'react';
21
27
import { WebView } from 'react-native-webview';
@@ -25,6 +31,7 @@ export default function App() {
25
31
26
32
const authorization_url = 'https://checkout.paystack.com/luKuasMan';
27
33
const callback_url = 'https://yourcallback.com';
34
+ const cancel_url = "https://your-cancel-url.com";
28
35
29
36
onNavigationStateChange = state => {
30
37
@@ -37,6 +44,12 @@ export default function App() {
37
44
const redirectTo = 'window.location = "' + callback_url + '"';
38
45
this.webview.injectJavaScript(redirectTo);
39
46
}
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
+ }
40
53
};
41
54
42
55
return (
@@ -46,15 +59,16 @@ export default function App() {
46
59
onNavigationStateChange={ this.onNavigationStateChange }
47
60
/>
48
61
);
49
- }
50
- `
62
+ }`
51
63
52
64
const kt = `class MainActivity : AppCompatActivity() {
53
65
54
66
private val authorizationUrl: String
55
67
get() = "https://checkout.paystack.com/ok62i2sdld514e4"
56
68
private val callbackUrl: String
57
69
get() = "https://yourcallback.com"
70
+ private val cancelUrl: String
71
+ get() = "https://your-cancel-url.com"
58
72
59
73
override fun onCreate(savedInstanceState: Bundle?) {
60
74
// ...
@@ -76,6 +90,11 @@ const kt = `class MainActivity : AppCompatActivity() {
76
90
if (url?.host == callbackUrl) {
77
91
return true
78
92
}
93
+ if (url?.host == cancelUrl) {
94
+ // handle webview removal
95
+ // Run the cancel payment function if you have one
96
+ return true
97
+ }
79
98
80
99
return super.shouldOverrideUrlLoading(view, request)
81
100
}
0 commit comments