> ## 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.

# PayPal 和 Venmo

> 通过 Web SDK 和 Checkout 流程，或使用 Braintree nonce 以服务器到服务器的方式，在 Yuno 上集成 PayPal 和 Venmo。

PayPal 是一款全球性的数字钱包，允许客户使用其 PayPal 余额、关联的银行账户或已存储的信用卡和借记卡进行支付。在受支持的地区（例如美国），购物者还可以使用 **Venmo** 完成购买。

## 主要功能

* **全球覆盖**：接受来自全球数百万活跃 PayPal 账户的支付。
* **Venmo 支持**：当您的 PayPal 连接的 `ENABLE_FUNDING` 参数包含 `venmo` 时，一旦 PayPal 确认买家符合条件（使用 USD 支付的美国买家），Web SDK 就会在 PayPal 按钮下方显示 Venmo 按钮。
* **快捷 checkout**：直接在商品页、购物车页或支付页上显示独立的 PayPal 和 Venmo 按钮。
* **Vault 存储和 Pay Later**：在符合条件的情况下，支持账单协议和分期付款（Pay in 4 / Pay Later）。

## SDK 集成

PayPal 可作为快捷按钮用于各种 Web SDK 流程（Full Checkout、Lite 和 Seamless），也可用于 Yuno SDK。

### 快捷按钮配置

在 `startCheckout()` 或 `startSeamlessCheckout()` 中传入 `externalButtons.paypal`，以自定义按钮外观：

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
await yuno.startCheckout({
  checkoutSession,
  countryCode: 'US',
  language: 'en',
  externalButtons: {
    paypal: {
      color: 'gold',      // 'gold' | 'blue' | 'silver' | 'white' | 'black'
      shape: 'rect',      // 'rect' | 'pill' | 'sharp'
      label: 'paypal',    // 'paypal' | 'checkout' | 'buynow' | 'pay' | 'installment'
      layout: 'vertical', // 'vertical' | 'horizontal'
      height: 45,         // 25 to 55 px
      borderRadius: 4,
    },
  },
})
```

对于使用 PayPal 的自定义 Braintree 集成，请使用 `onShippingAddressChange` 等配送回调配置 `externalButtons.paypalBraintree`。完整选项请参阅 [Web SDK 参考](https://docs.y.uno/docs/sdks/resources/references/web.md#paypal-braintree)。

### 注册流程

对于定期支付或令牌化，请使用 `mountEnrollmentLite()` 以注册模式挂载 PayPal 按钮。请参阅[使用元素渲染模式注册 PayPal](https://docs.y.uno/docs/sdks/lite-web/enrollment.md#paypal-enrollment-with-element-render-mode)。

## 使用 Braintree nonce 直接集成

如果您在自己的 checkout 中使用 Braintree JS SDK 收集 PayPal 信息，并以服务器到服务器的方式调用 Yuno，请在 `DIRECT` 支付中发送一次性 Braintree nonce。Yuno 会将其转发到 Braintree 连接，由该连接进行扣款，并在使用 `vault_on_success` 时将 PayPal 账户存入 vault。

1. 使用 Braintree JS SDK 收集 PayPal 授权并获取 nonce。
2. 使用[创建支付](https://docs.y.uno/zh-hans/reference/payments/create-payment.md)创建支付：`workflow` 为 `DIRECT`，`payment_method.type` 为 `PAYPAL_BRAINTREE`，nonce 放在 `payment_method.detail.wallet.provider_payment_token` 中；如需保存账户，将 `payment_method.vault_on_success` 设为 `true`。
3. 成功后，支付会返回 `payment_method.vaulted_token`。后续支付请使用该 `vaulted_token` 扣款。只有当支付携带 `customer_payer.id` 时，Yuno 才会创建 `vaulted_token`。
4. 当您需要 Braintree 支付方式 id 时（例如，通过 Braintree Grant API 与合作伙伴共享 PayPal 账户），请从支付响应的 `payment_method.payment_method_detail.wallet.provider_token` 中读取。[检索支付](https://docs.y.uno/reference/payments/retrieve-payment-by-id)会返回相同的值，[检索支付方式](https://docs.y.uno/reference/payment-methods-checkout/retrieve-payment-method-by-id-checkout.md)则针对该 `vaulted_token` 以 `provider.token` 返回该值。

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "account_id": "<ACCOUNT_ID>",
  "merchant_order_id": "order-1234",
  "country": "US",
  "amount": { "currency": "USD", "value": 50 },
  "workflow": "DIRECT",
  "customer_payer": { "id": "<CUSTOMER_ID>" },
  "payment_method": {
    "type": "PAYPAL_BRAINTREE",
    "vault_on_success": true,
    "detail": {
      "wallet": {
        "provider_payment_token": "<BRAINTREE_NONCE>"
      }
    }
  }
}
```

`provider_payment_token` 的规则：

* 仅在 `DIRECT` 工作流中接受；`REDIRECT` 和 `SDK_CHECKOUT` 会返回 `400 INVALID_REQUEST`。
* 不得为空，且不得与 `wallet.payment_token`、`wallet.cryptogram`、`payment_method.token` 或 `payment_method.vaulted_token` 同时使用。
* nonce 仅可使用一次：每笔使用它的支付都要发送一个新的 nonce。Yuno 不会存储它。

## 移动浏览器中的展示方式

当购物者在移动设备上触发 PayPal 或 Venmo 快捷 checkout 时：

* **iOS 浏览器（iOS 上的 Safari、Chrome、Firefox、Edge），包括 Venmo**：默认情况下，移动浏览器打开弹出窗口时会冻结后台浏览器标签页，这可能会中断支付握手。Web SDK 可以改为在页面内的模态 iframe 覆盖层中显示 PayPal 和 Venmo，在订单移交期间保持商户页面处于活动状态。该覆盖层随 Web SDK 1.11.40 发布，默认关闭；Yuno 会按账户启用它。
* **桌面端**：桌面浏览器（例如 macOS Safari）始终使用弹出窗口。
* **订单生成时间**：当生成订单耗时超过 30 秒时，SDK 会记录日志，但不会使会话失败，也不会向购物者返回错误。


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