Handle the return URL
Pass the URLs your app is opened with to the SDK, so a redirect or app switch that comes back to your app finishes its payment.
PayCheckout.handleReturn(_:) hands a URL your app was opened with to the payment flow that waits for it. A redirect payment method comes back at the checkout's returnURL, for example when a bank app switches back to yours after the customer approves. Pass every URL your app is opened with. The SDK takes the ones that belong to a Pay.com flow in progress and leaves the rest to you. The drop-in relies on it too.
PayCheckout.handleReturn(url)Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
url | URL | Yes | A URL your app was opened with, from SwiftUI's onOpenURL, the scene delegate's scene(_:openURLContexts:), or a universal link's NSUserActivity. |
Returns
true when the URL belonged to a Pay.com flow in progress, which then goes on to read the payment's status. false otherwise, so you can pass every URL and handle the ones that return false yourself. You can ignore the result.
A URL belongs to the flow when its scheme and host are the return URL's, ignoring case, and its path is the return URL's path or below it. The query and fragment don't count. With a returnURL of myshop://pay, both myshop://pay?status=done and myshop://pay/complete match.
handleReturn is a static method that runs on the main actor. It doesn't throw.
When it's needed
Whether you need handleReturn depends on the kind of return URL.
- A custom scheme (such as
myshop://pay). The redirect screen finishes by itself when its page reaches the return URL. When a bank app switches back to yours, the URL reaches your app instead, andhandleReturnfinishes the flow. Register the scheme in your app's URL types. - A universal link. The redirect screen can't catch it, so the flow finishes only when your app passes the URL to
handleReturn.
The 3DS challenge doesn't need it, because its web view catches the return URL itself.
Your server must create the session with return_url set to the same URL as the checkout's returnURL.
Example
Pass the URL from SwiftUI or from your scene delegate.
import PayCheckout
import SwiftUI
@main
struct ShopApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL { url in
if !PayCheckout.handleReturn(url) {
// Not a Pay.com return: handle your own deep link.
}
}
}
}
}import PayCheckout
import UIKit
final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
for context in URLContexts {
PayCheckout.handleReturn(context.url)
}
}
// Universal links
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
if let url = userActivity.webpageURL {
PayCheckout.handleReturn(url)
}
}
}Next steps
- Pay: How a redirect runs, from the page opening to the result.
- Start a checkout: Set the checkout's
returnURL.