Skip to content

Commit c049f8f

Browse files
update webview guide code snippet
1 parent df8dc95 commit c049f8f

File tree

6 files changed

+34
-8
lines changed

6 files changed

+34
-8
lines changed

src/doc/guides/checkout-webview/handling-redirect/index.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ 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+
}

src/doc/guides/checkout-webview/handling-redirect/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default function App() {
66

77
const authorization_url = 'https://checkout.paystack.com/luKuasMan';
88
const callback_url = 'https://yourcallback.com';
9+
const cancel_url = "https://your-cancel-url.com";
910

1011
onNavigationStateChange = state => {
1112

@@ -18,6 +19,12 @@ export default function App() {
1819
const redirectTo = 'window.location = "' + callback_url + '"';
1920
this.webview.injectJavaScript(redirectTo);
2021
}
22+
if (url === cancel_url) {
23+
// handle webview removal
24+
// You can either unmount the component, or
25+
// Use a navigator to pop off the view
26+
// Run the cancel payment function if you have one
27+
}
2128
};
2229

2330
return (
@@ -27,4 +34,4 @@ export default function App() {
2734
onNavigationStateChange={ this.onNavigationStateChange }
2835
/>
2936
);
30-
}
37+
}

src/doc/guides/checkout-webview/handling-redirect/index.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ class MainActivity : AppCompatActivity() {
44
get() = "https://checkout.paystack.com/ok62i2sdld514e4"
55
private val callbackUrl: String
66
get() = "https://yourcallback.com"
7+
private val cancelUrl: String
8+
get() = "https://your-cancel-url.com"
79

810
override fun onCreate(savedInstanceState: Bundle?) {
911
// ...
@@ -25,6 +27,11 @@ class MainActivity : AppCompatActivity() {
2527
if (url?.host == callbackUrl) {
2628
return true
2729
}
30+
if (url?.host == cancelUrl) {
31+
// handle webview removal
32+
// Run the cancel payment function if you have one
33+
return true
34+
}
2835

2936
return super.shouldOverrideUrlLoading(view, request)
3037
}

src/doc/payments/accept-payment/redirect-backend/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ const https = require('https')
22

33
const params = JSON.stringify({
44
"email": "customer@email.com",
5-
"amount": "20000"
5+
"amount": "20000",
6+
"callback_url":"https://hello.pstk.xyz/callback",
7+
"metadata":{"cancel_action": "https://your-cancel-url.com"}
68
})
79

810
const options = {

src/doc/payments/accept-payment/redirect-backend/index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
$fields = [
55
'email' => "customer@email.com",
6-
'amount' => "20000"
6+
'amount' => "20000",
7+
'callback_url' => "https://hello.pstk.xyz/callback",
8+
'metadata' => ["cancel_action" => "https://your-cancel-url.com"]
79
];
810

911
$fields_string = http_build_query($fields);
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
curl https://api.paystack.co/transaction/initialize
22
-H "Authorization: Bearer YOUR_SECRET_KEY"
33
-H "Content-Type: application/json"
4-
-d '{ "email": "customer@email.com", "amount": "20000" }'
4+
-d '{ "email": "customer@email.com", "amount": "20000",
5+
"callback_url":"https://hello.pstk.xyz/callback",
6+
"metadata":{"cancel_action": "https://your-cancel-url.com"}
7+
}'
58
-X POST

0 commit comments

Comments
 (0)