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

# 端到端追踪 Stripe 支付流程

export const UseCaseHero = ({title, description, prompt, category, features, devinUrl, agent, intent, playbookId, type}) => {
  const encodedPrompt = encodeURIComponent(prompt || '');
  const tag = 'docs-use-case-gallery';
  const utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=hero-cta';
  const agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  const devinHref = type === 'schedule' ? 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + (prompt ? '&prompt=' + encodedPrompt : '') : type === 'review' ? 'https://app.devin.ai/review?' + utm : agent === 'ada' ? 'https://app.devin.ai/search?' + utm + '&noSubmit=true' + (prompt ? '&prompt=' + encodedPrompt : '') : devinUrl ? devinUrl.includes('?') ? devinUrl + '&' + utm + agentParams : devinUrl + '?' + utm + agentParams : prompt ? 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encodedPrompt : 'https://app.devin.ai/?' + utm + agentParams;
  const buttonLabel = type === 'schedule' ? 'Schedule in Devin ↗' : type === 'review' ? 'Set Up Devin Review ↗' : agent === 'advanced' ? 'Try in Devin ↗' : agent === 'dana' ? 'Try in Dana ↗' : agent === 'ada' ? 'Try in Ask Devin ↗' : 'Try in Devin ↗';
  const featureList = features ? features.split(',').map(f => f.trim()) : [];
  return <div className="uc-hero">
      <div className="uc-hero-inner">
        <div className="uc-hero-left">
          <h1 className="uc-hero-title">{title}</h1>
          <p className="uc-hero-desc">{description}</p>
          <div>
            <a href={devinHref} target="_blank" rel="noopener noreferrer" className="try-in-devin-btn">
              {buttonLabel}
            </a>
          </div>
        </div>
        <div className="uc-hero-meta">
          <div className="uc-meta-item">
            <span className="uc-meta-label">Author</span>
            <span className="uc-meta-value">Cognition</span>
          </div>
          <div className="uc-meta-item">
            <span className="uc-meta-label">Category</span>
            <span className="uc-meta-value">{category}</span>
          </div>
          {featureList.length > 0 && <div className="uc-meta-item">
              <span className="uc-meta-label">Features</span>
              <span className="uc-meta-value">{featureList.join(', ')}</span>
            </div>}
        </div>
      </div>
    </div>;
};

export const PromptBlock = ({children, type, agent, intent, playbookId}) => {
  var utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=prompt-block';
  var tag = 'docs-use-case-gallery';
  var agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  var label = type === 'schedule' ? 'Schedule in Devin' : type === 'playbook' ? 'Create Playbook' : type === 'knowledge' ? 'Add to Knowledge' : agent === 'advanced' ? 'Try in Devin' : agent === 'dana' ? 'Try in Dana' : agent === 'ada' ? 'Try in Ask Devin' : 'Try in Devin';
  var buildUrl = function (text) {
    var encoded = encodeURIComponent(text);
    if (type === 'schedule') return 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + '&prompt=' + encoded;
    if (type === 'playbook') return 'https://app.devin.ai/settings/playbooks/create?' + utm + '&body=' + encoded;
    if (type === 'knowledge') return 'https://app.devin.ai/knowledge?' + utm + '&body=' + encoded;
    if (agent === 'ada') return 'https://app.devin.ai/search?' + utm + '&noSubmit=true&prompt=' + encoded;
    return 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encoded;
  };
  const ref = React.useRef(null);
  const [href, setHref] = React.useState('#');
  React.useEffect(() => {
    if (!ref.current) return;
    var codeEl = ref.current.querySelector('pre code');
    if (codeEl) {
      var text = codeEl.textContent.trim();
      if (text) setHref(buildUrl(text));
    }
    var header = ref.current.querySelector('[data-component-part="code-block-header"]');
    if (header && !header.querySelector('.prompt-block-devin-link')) {
      var link = document.createElement('a');
      link.href = href;
      link.target = '_blank';
      link.rel = 'noopener noreferrer';
      link.className = 'prompt-block-devin-link';
      link.style.cssText = 'display:inline-flex;align-items:center;gap:6px;text-decoration:none;color:#fff;font-size:11px;font-weight:500;padding:4px 10px;border-radius:6px;white-space:nowrap;background:#317CFF;transition:background 0.2s;margin-left:8px;';
      link.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg> ' + label;
      link.onmouseenter = function () {
        link.style.background = '#2968D9';
      };
      link.onmouseleave = function () {
        link.style.background = '#317CFF';
      };
      header.appendChild(link);
    }
    var existingLink = ref.current.querySelector('.prompt-block-devin-link');
    if (existingLink && href !== '#') existingLink.href = href;
  });
  return <div className="prompt-block" ref={ref}>{children}</div>;
};

<UseCaseHero title="端到端追踪 Stripe 支付流程" description="使用 Ask Devin 在写下第一行代码之前，先梳理 Stripe 结账流程中涉及的每一个文件和函数，从 Subscribe 按钮到 webhook 处理程序。" prompt="我需要给我们的支付 webhook 处理程序添加重试逻辑。在开始之前，请先带我梳理完整的支付流程——从前端结账按钮，到 API、Stripe 集成、webhook 处理以及数据库更新。请列出涉及的每一个文件和函数。" category="功能开发" features="MCP" agent="ada" />

<div className="uc-detail-wrapper">
  <Tip>不想手动设置？将此页面的链接粘贴到 Devin 会话中，让它替你完成所有设置。</Tip>

  <Steps>
    <Step title="请 Devin 跟踪支付流程">
      你接到一个工单，要给 Stripe webhook 处理器添加重试逻辑，但你是两周前才加入团队，而且之前从没接触过支付相关代码。与其花一小时在源码里到处点来点去，不如打开 [Ask Devin](https://app.devin.ai/search?utm_source=docs\&utm_medium=use-case-gallery)，让它帮你梳理整个流程。

      在左侧侧边栏中选择 **Ask Devin**，选择你的代码仓库，然后描述你需要理解的业务流程：

      <PromptBlock agent="ada">
        ```txt Trace the payment flow theme={null}
        I need to add retry logic to our payment webhook handler. Before I
        start, walk me through how payments work end-to-end:

        1. What happens when a user clicks "Subscribe" on the pricing page?
        2. Which API route handles the request?
        3. How does the Stripe integration work — where are subscriptions created?
        4. How do webhooks get processed and where does the DB get updated?

        For each step, give me the file path, function name, and a one-line
        summary of what it does.
        ```
      </PromptBlock>

      Devin 会阅读你仓库的 [DeepWiki](/zh/work-with-devin/deepwiki) 文档，搜索实际源代码，并跨文件跟踪函数调用，构建出完整的全貌。它会返回整个流程的结构化映射：

      ```
      ## 支付流程：订阅 → 数据库

      1. src/pages/pricing/PricingCard.tsx:45
         handleSubscribe() → POST /api/v2/subscriptions

      2. src/api/v2/subscriptions/create.ts:12
         Validates input, checks eligibility → calls SubscriptionService.create()

      3. src/services/SubscriptionService.ts:89
         Creates Stripe subscription via stripe.subscriptions.create()
         Stores pending record with status="pending"

      4. src/webhooks/stripe.ts:34
         Receives invoice.payment_succeeded → calls SubscriptionService.activate()
         ⚠ 此处无重试逻辑 — 这里就是你需要进行修改的地方

      5. src/services/SubscriptionService.ts:134
         Updates status to "active", creates invoice record, emits event
      ```

      不到一分钟，你就能拿到一份支付流水线的文件级示意图——涉及五个文件、具体的函数名，以及你需要做改动的确切位置。
    </Step>

    <Step title="通过后续追问深入挖掘 webhook 处理器">
      Ask Devin 是对话式的 —— 你可以根据需要提出任意数量的后续问题。现在你已经能看到流水线了，深入查看你将要修改的部分：

      <PromptBlock agent="ada">
        ```txt Find error handling patterns theme={null}
        展示一下这个代码库中其他 webhook 处理器是如何处理失败的。
        有没有已经存在的重试机制或死信队列可以复用？请检查 src/webhooks/
        以及任何共享的 middleware。
        ```
      </PromptBlock>

      <PromptBlock agent="ada">
        ```txt Check for related callers theme={null}
        找出所有调用 SubscriptionService 的位置 —— 我想确保我的重试逻辑
        不会影响其他调用方。还请检查是否有带内置重试支持的共享 StripeClient
        封装。
        ```
      </PromptBlock>

      持续追问，直到你对整体有完整的认识。Ask Devin 会保留整个对话的上下文，因此每个问题都会建立在之前答案的基础之上。你也可以让 Devin 帮你梳理实现方案的大致思路。
    </Step>

    <Step title="直接在 Ask Devin 中发起编程会话">
      你现在已经知道要修改的具体文件 (`src/webhooks/stripe.ts`) 、要复用的现有重试工具 (`src/lib/retry.ts`) ，以及其他处理程序已经推送到的死信队列 (`src/queues/dlq.ts`) 。

      按下 **⌥ Option + Enter** (或单击箭头图标) ，即可直接从 Ask Devin 对话中启动 Devin 会话。Devin 会带上它已经学到的一切——文件映射、错误处理模式、重试工具——因此会跳过分析阶段，直接进入实现阶段。**会话状态会直接显示在你的 Ask Devin 对话中**，这样你无需切换上下文就能监控进度。

      你也可以在按下 ⌥ Enter 之前输入一个具体的实现指令，用来引导 Devin 要构建什么：

      <PromptBlock>
        ```txt Implement with full context theme={null}
        在 src/webhooks/stripe.ts 中为 Stripe webhook 处理程序添加指数退避重试逻辑。
        复用 src/lib/retry.ts 中其他 webhook 处理程序已经使用的 RetryPolicy 类。

        如果 webhook 处理失败，使用退避重试最多重试 3 次
        （1s、4s、16s）。在所有重试都耗尽后，将该事件推送到
        现有的 SQS 死信队列 src/queues/dlq.ts。

        添加覆盖重试和 DLQ 场景的测试。
        ```
      </PromptBlock>

      由于会话会继承 Ask 对话中的上下文，Devin 能够产出更准确的 PR，所需迭代次数更少。这个从 Ask 到 Agent 的工作流，是从 "我不熟悉这个代码库" 到 "这是一个 PR" 的最快路径。你可以在 [Ask Devin 指南](/zh/work-with-devin/ask-devin) 中了解更多信息。
    </Step>
  </Steps>
</div>
