Skip to Content
Docs

Handle the return URL

Pass the URLs your app is opened with to the SDK, so a payment that sent the customer to a payment method's page can finish.

A redirect payment method opens its page in a Custom Tab. When the customer finishes there, the page sends them to your returnUrl, which opens your app. Pass that URL to PayCheckout.handleReturn(), so the waiting checkout.pay() call can read the payment's status and return. The drop-in needs it too.

Call it with every URL your activity is opened with, in onCreate and onNewIntent. It's on PayCheckout's companion object, so it needs no checkout.

val handled: Boolean = PayCheckout.handleReturn(url)

Your server creates the session with return_url set to the same URL as the checkout's returnUrl, and the activity that pays declares an intent filter for it. See Register the return URL.

Parameters

ParameterTypeRequiredDescription
urlStringYesA URL your app was opened with, for example intent.data.toString(). Any URL is safe to pass.

Returns

true when the URL belongs to a payment in progress. The SDK takes it from there. false otherwise, for example for another of your app's deep links. It's also false when no payment is waiting for the URL anymore, for example because the app's process was restarted. In that case, ask your server for the session's status.

A URL belongs to a payment when its scheme and host are returnUrl's, ignoring case, and its path is returnUrl's path or below it. The query and the fragment don't count. With returnUrl = "myshop://pay", myshop://pay?result=done and myshop://pay/done match, and myshop://orders doesn't.

Only redirects in a Custom Tab come back through handleReturn. The 3DS challenge runs in the SDK's own WebView, which catches its return itself.

When the customer comes back to your app without the return URL, for example by closing the Custom Tab, the SDK treats the redirect as canceled 750 milliseconds after your activity resumes. onCreate and onNewIntent run before onResume, so a URL you pass there is in time.

Example

class CheckoutActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        intent?.data?.let { PayCheckout.handleReturn(it.toString()) }
        // ...
    }

    // The activity is declared with launchMode="singleTop", so the return URL arrives here.
    override fun onNewIntent(intent: Intent) {
        super.onNewIntent(intent)
        intent.data?.let { uri ->
            if (!PayCheckout.handleReturn(uri.toString())) {
                openDeepLink(uri) // One of your app's own links
            }
        }
    }
}

Next steps

  • Pay: What the SDK shows during a redirect, and what pay returns after it.
  • Register the return URL: The intent filter for your returnUrl.
Was this page helpful?