diff --git a/src/doc/guides/checkout-webview/handling-redirect/index.dart b/src/doc/guides/checkout-webview/handling-redirect/index.dart index 5640b6e..55e3cdf 100644 --- a/src/doc/guides/checkout-webview/handling-redirect/index.dart +++ b/src/doc/guides/checkout-webview/handling-redirect/index.dart @@ -5,14 +5,19 @@ Widget build(BuildContext context) { initialUrl: 'https://checkout.paystack.com/7zu1ot06d0qn9h6', javascriptMode: JavascriptMode.unrestricted, userAgent: 'Flutter;Webview', - navigationDelegate: (navigation){ - //Listen for callback URL - if(navigation.url == "https://hello.pstk.xyz/callback"){ + navigationDelegate: (navigation) { + //Listen for callback URL + if (navigation.url == "https://hello.pstk.xyz/callback") { verifyTransaction(reference); Navigator.of(context).pop(); //close webview } + if (navigation.url == "https://your-cancel-url.com") { + //handle webview removal + Navigator.of(context).pop(); //close webview + //Run the cancel payment function if you have one + } return NavigationDecision.navigate; }, ), ); -} \ No newline at end of file +} diff --git a/src/doc/guides/checkout-webview/handling-redirect/index.js b/src/doc/guides/checkout-webview/handling-redirect/index.js index d2cd5a8..3ac3f2b 100644 --- a/src/doc/guides/checkout-webview/handling-redirect/index.js +++ b/src/doc/guides/checkout-webview/handling-redirect/index.js @@ -6,6 +6,7 @@ export default function App() { const authorization_url = 'https://checkout.paystack.com/luKuasMan'; const callback_url = 'https://yourcallback.com'; + const cancel_url = "https://your-cancel-url.com"; onNavigationStateChange = state => { @@ -18,6 +19,12 @@ export default function App() { const redirectTo = 'window.location = "' + callback_url + '"'; this.webview.injectJavaScript(redirectTo); } + if (url === cancel_url) { + // handle webview removal + // You can either unmount the component, or + // Use a navigator to pop off the view + // Run the cancel payment function if you have one + } }; return ( @@ -27,4 +34,4 @@ export default function App() { onNavigationStateChange={ this.onNavigationStateChange } /> ); -} +} \ No newline at end of file diff --git a/src/doc/guides/checkout-webview/handling-redirect/index.kt b/src/doc/guides/checkout-webview/handling-redirect/index.kt index 0a18d5d..249ee0f 100644 --- a/src/doc/guides/checkout-webview/handling-redirect/index.kt +++ b/src/doc/guides/checkout-webview/handling-redirect/index.kt @@ -4,6 +4,8 @@ class MainActivity : AppCompatActivity() { get() = "https://checkout.paystack.com/ok62i2sdld514e4" private val callbackUrl: String get() = "https://yourcallback.com" + private val cancelUrl: String + get() = "https://your-cancel-url.com" override fun onCreate(savedInstanceState: Bundle?) { // ... @@ -25,6 +27,11 @@ class MainActivity : AppCompatActivity() { if (url?.host == callbackUrl) { return true } + if (url?.host == cancelUrl) { + // handle webview removal + // Run the cancel payment function if you have one + return true + } return super.shouldOverrideUrlLoading(view, request) } diff --git a/src/doc/payments/accept-payment/redirect-backend/index.js b/src/doc/payments/accept-payment/redirect-backend/index.js index b184265..c68635f 100644 --- a/src/doc/payments/accept-payment/redirect-backend/index.js +++ b/src/doc/payments/accept-payment/redirect-backend/index.js @@ -2,7 +2,9 @@ const https = require('https') const params = JSON.stringify({ "email": "customer@email.com", - "amount": "20000" + "amount": "20000", + "callback_url":"https://hello.pstk.xyz/callback", + "metadata":{"cancel_action": "https://your-cancel-url.com"} }) const options = { diff --git a/src/doc/payments/accept-payment/redirect-backend/index.php b/src/doc/payments/accept-payment/redirect-backend/index.php index 65f0b93..3c53a10 100644 --- a/src/doc/payments/accept-payment/redirect-backend/index.php +++ b/src/doc/payments/accept-payment/redirect-backend/index.php @@ -3,7 +3,9 @@ $fields = [ 'email' => "customer@email.com", - 'amount' => "20000" + 'amount' => "20000", + 'callback_url' => "https://hello.pstk.xyz/callback", + 'metadata' => ["cancel_action" => "https://your-cancel-url.com"] ]; $fields_string = http_build_query($fields); diff --git a/src/doc/payments/accept-payment/redirect-backend/index.sh b/src/doc/payments/accept-payment/redirect-backend/index.sh index dd13919..2b891fe 100644 --- a/src/doc/payments/accept-payment/redirect-backend/index.sh +++ b/src/doc/payments/accept-payment/redirect-backend/index.sh @@ -1,5 +1,8 @@ curl https://api.paystack.co/transaction/initialize -H "Authorization: Bearer YOUR_SECRET_KEY" -H "Content-Type: application/json" --d '{ "email": "customer@email.com", "amount": "20000" }' +-d '{ "email": "customer@email.com", "amount": "20000", + "callback_url":"https://hello.pstk.xyz/callback", + "metadata":{"cancel_action": "https://your-cancel-url.com"} + }' -X POST \ No newline at end of file