> For the complete documentation index, see [llms.txt](https://docs.coda.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coda.co/https-coda-payments.gitbook.io-zhong-wen-coda-private-technical-documentation/codapay/xun-huan-fu-kuan-ji-jiang-tui-chu/yong-li-he-liu-cheng.md).

# 用例和流程

本节介绍循环支付的不同使用场景和交易流程。这些流程涵盖客户发起的支付和商家发起的支付，并处理诸如首次支付、老用户支付和订阅计费等场景。

**关键场景**

1. **首次付款及保存付款方式：**&#x65B0;用户完成付款并选择保存其详细信息。
2. **商家发起的定期付款：**&#x5546;家会自动从已保存的付款方式中扣除订阅费用。
3. **购物者移除已保存的付款方式：**&#x8D2D;物者从其账户中移除已保存的付款方式。

### 首次付款及保存付款方式 <a href="#first-time-payment-and-saving-a-payment-method" id="first-time-payment-and-saving-a-payment-method"></a>

**描述**

新顾客完成付款后，可以选择保存付款方式以便将来交易使用。

```mermaid
sequenceDiagram
    Title First-Time Payment & Saving Payment Method (CIT for MIT)

    actor 购物者
    participant 商家
    participant Coda API
    participant Coda 支付页面
    participant 支付网关

    商家 ->>+ Coda API: 发起支付请求 API (/v2.0/Payment/init.json)<br>[userInitiaed=true, offSessionReuse=true, offSessionType]
    Coda API -->> 商家: 返回 支付 ID (txnId)
    商家 ->> 购物者: 跳转到 Coda 支付页面
    购物者 ->> Coda 支付页面: 输入支付信息然后选择 "Save for future use"
    Coda 支付页面 ->> 支付网关: 处理付款
    支付网关 -->> Coda 支付页面: 付款结果
    Coda 支付页面 -->> 购物者: 展示成果页面
    
    Coda API -->> 商家: 回调通知 PAYMENT_METHOD_ADDED (仅限成功支付)
    Coda API -->> 商家: 回调 订单交易状态 通知 (支付方式令牌 PaymentMethodId)
```

**流程详情**

1. 商家通过发起支付请求`/v2/Payment/init`，传递购物者信息、交易详情以及`savePaymentMethod: true`相应的参数：
   1. `offSessionType`此账户绑定的未来非课程付款类型（非计划付款、订阅付款、分期付款）
2. 购物者将被重定向到托管支付页面。
3. 购物者输入付款信息并选择保存付款方式
4. 付款已处理，正在经过身份验证和欺诈检查（例如，SCA 强客户认证）。
5. 成功后：
   * 创建一个购物者档案（如果不存在）。
   * 生成并存储支付方式令牌。
   * 商家会收到确认已保存付款方式的通知。
6. 商家会收到支付成功响应以及令牌化的支付方式。

您可以参考[“托管支付页面集成：发起支付请求](https://coda-payments.gitbook.io/coda-public-technical-documentation/codapay/hosted-component-integration/cards/initiate-a-payment-request)和[保存卡片详细信息”](https://coda-payments.gitbook.io/coda-public-technical-documentation/codapay/hosted-payment-page-integration/saving-card-details)参考资料，了解有关每个 API 的更多详细信息。

#### 商家发起的定期付款 <a href="#merchant-initiated-recurring-payment" id="merchant-initiated-recurring-payment"></a>

**描述**

商家在顾客不在场的情况下（离线）使用预先保存的付款方式自动向顾客收费。

```mermaid
sequenceDiagram
    Title 商家发起的交易（周期性、订阅、非计划扣款）

    participant 商家
    participant Coda API
    participant 支付网关

    商家 ->>+ Coda API: 使用 Token 化支付方式扣款 (/v1.0/payment/token/charge)<br>[payment_method_id]
    Coda API -->> 商家: 返回交易 ID (txnId) - 已确认接收

    Coda API ->> 支付网关: 处理支付授权
    支付网关 -->> Coda API: 支付授权结果
    
    Coda API -->> 商家: 发送支付结果 Webhook 回调
```

**流程详情**

1. 商家通过`/v1/payment/token`以下方式发起收费：
   * `paymentMethodId` 已保存特定 partnerShopperId 的付款方式
   * `offSessionType`用户在首次付款时保存付款方式并获得同意后，被授权使用 offSession 绑定类型。
2. 系统使用已存储的支付方式处理付款。
3. 交易需经过标准认证、欺诈检查和处理流程。
4. 商家收到支付成功的响应。

您可以参考[“托管支付页面集成：发起支付请求](https://coda-payments.gitbook.io/coda-public-technical-documentation/codapay/hosted-component-integration/cards/initiate-a-payment-request)和[保存卡片详细信息”](https://coda-payments.gitbook.io/coda-public-technical-documentation/codapay/hosted-payment-page-integration/saving-card-details)参考资料，了解有关每个 API 的更多详细信息。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.coda.co/https-coda-payments.gitbook.io-zhong-wen-coda-private-technical-documentation/codapay/xun-huan-fu-kuan-ji-jiang-tui-chu/yong-li-he-liu-cheng.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
