> ## Documentation Index
> Fetch the complete documentation index at: https://docs.y.uno/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Test in the sandbox first: base URL https://api-sandbox.y.uno (Test Mode in the Dashboard). Production is https://api.y.uno (Live Mode).
> Every API request needs the public-api-key and private-secret-key headers. Get them in the Dashboard at https://dashboard.y.uno/developers (Developers > Credentials); sandbox and production keys are different.
> Send an X-Idempotency-Key (a UUID) when creating payments, refunds and cancels, so retries do not create duplicates.
> Start with the Quickstart (https://docs.y.uno/docs/quickstart.md) and the agent guide (https://docs.y.uno/agents.md). To search these docs from a coding agent, connect the docs MCP server at https://docs.y.uno/mcp.

# 处理 deeplink

> 将传入的 URL 转发给 SDK，使其在从外部应用或页面返回后能够恢复交易。

当交易将用户重定向到外部目标时。另一个应用、钱包、银行流程或托管页面。用户最终会返回您的应用或网站。iOS、Android 和 React Native SDK 提供 `handleDeeplink`，以便您转发该传入的 URL，让 SDK 恢复交易。

Web SDK 没有 `handleDeeplink`。当购物者回到您的返回 URL 时，页面会重新加载，SDK 不会在重定向前后保留任何状态。读取您存储的结账会话或返回 URL 中的结账会话，然后调用 `sdkPayments.transactionStatus({ checkoutSession, elementSelector })`。SDK 会将该会话的支付结果渲染到 `elementSelector` 中。传入 `language` 和 `countryCode` 以与原始交易保持一致。该界面仅用于展示，因此请通过 webhooks 或支付 API 确认结果。

## 行为

`handleDeeplink(url)` 接受任意 URL。请根据 URL 本身决定何时调用它。例如，当 URL 带有 `customer` 或 `checkoutSession` 等查询参数，表明它属于某个 Yuno 交易时。

该方法返回一个布尔值，表示交易是否能够继续。它不反映交易的最终结果。最终状态仍通过 `onStatus` 传递。

在 iOS 上，安装 [Revolut Pay 模块](https://docs.y.uno/zh-hans/docs/yuno-sdk/features/native-modules.md#revolut-pay)后，同一调用还会接收 Revolut Pay 支付的返回 URL。

## 在哪里调用

在您的应用接收传入 URL 的任何位置调用 `handleDeeplink`。

> [tab] iOS
>
> 如果您使用 UIKit，请使用 `AppDelegate`；如果您的应用基于 SwiftUI，请使用 SwiftUI 生命周期。
>
> **UIKit（`AppDelegate`）**
>
> ```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> func application(
>     _ app: UIApplication,
>     open url: URL,
>     options: [UIApplication.OpenURLOptionsKey : Any] = [:]
> ) -> Bool {
>     if SdkPayments.handleDeeplink(url) {
>         return true
>     }
>     // Handle other URLs here.
>     return false
> }
> ```
>
> **SwiftUI（`onOpenURL`）**
>
> ```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> @main
> struct MyApp: App {
>     var body: some Scene {
>         WindowGroup {
>             ContentView()
>                 .onOpenURL { url in
>                     SdkPayments.handleDeeplink(url)
>                 }
>         }
>     }
> }
> ```

> [tab] Android
>
> `handleDeeplink` 是 `Transaction` 的一个方法。从接收 deeplink intent 的 Activity 转发 URI，并将该 Activity 作为第一个参数传入（SDK 会从它启动恢复后流程的界面）：同时覆盖冷启动（`onCreate`）和热返回（`onNewIntent`）。URL 中携带的会话优先于 `TransactionConfig` 中的会话；当 URL 只携带令牌时，配置中的会话作为后备。
>
> ```kotlin theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> class MainActivity : ComponentActivity() {
>
>     override fun onCreate(savedInstanceState: Bundle?) {
>         super.onCreate(savedInstanceState)
>         intent?.data?.let(::forwardDeeplink)
>     }
>
>     override fun onNewIntent(intent: Intent) {
>         super.onNewIntent(intent)
>         intent.data?.let(::forwardDeeplink)
>     }
>
>     private fun forwardDeeplink(uri: Uri) {
>         val handled = Transaction(
>             TransactionConfig(
>                 countryCode = "US",
>                 checkoutSession = "session-from-backend",
>                 controller = controller,
>             ),
>         ).handleDeeplink(this, uri)
>         if (!handled) {
>             // Handle other URLs here.
>         }
>     }
> }
> ```

> [tab] React Native
>
> 将您应用的 URL scheme 接入 React Native 的 `Linking`（在 iOS 上，按照 React Native 文档的说明从您的 `AppDelegate` 转发 URL），然后将每个 URL 交给您启动的交易。在冷启动时，以同样的方式传入来自 `Linking.getInitialURL()` 的 URL。
>
> ```tsx theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> useEffect(() => {
>   const subscription = Linking.addEventListener('url', ({ url }) => {
>     transaction.handleDeeplink(url).then((handled) => {
>       if (!handled) {
>         // Handle other URLs here.
>       }
>     });
>   });
>   return () => subscription.remove();
> }, [transaction]);
> ```
>
> `SdkPayments.handleDeeplink(url)` 无需交易引用即可完成相同操作：它使用最后启动的交易。

## 签名

```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
// iOS
@discardableResult
func handleDeeplink(_ url: URL) -> Bool
```

```kotlin theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
// Android: method of Transaction
fun handleDeeplink(activity: ComponentActivity, uri: Uri): Boolean
```

```typescript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
// React Native
transaction.handleDeeplink(url: string): Promise<boolean>
SdkPayments.handleDeeplink(url: string): Promise<boolean>
```

## 相关内容

* [交易](https://docs.y.uno/zh-hans/docs/basic-concepts/transactions.md)。支付如何在 Yuno 中流转。
* [`onStatus`](https://docs.y.uno/zh-hans/docs/yuno-sdk/controllers/on-status)。接收交易的最终状态。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.