File tree Expand file tree Collapse file tree 6 files changed +34
-8
lines changed
guides/checkout-webview/handling-redirect
payments/accept-payment/redirect-backend Expand file tree Collapse file tree 6 files changed +34
-8
lines changed Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change @@ -2,7 +2,9 @@ const https = require('https')
22
33const 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
810const options = {
Original file line number Diff line number Diff line change 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 );
Original file line number Diff line number Diff line change 11curl 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
You can’t perform that action at this time.
0 commit comments