0Pricing
Stripe Payments & SaaS Billing Systems · 课时

使用 Checkout 完成首笔支付

使用 Stripe Checkout 实现简单的支付流程,演示如何收集卡片信息并完成交易。

使用 Checkout 完成首笔支付 是 CoddyKit 上的免费 Stripe Payments & SaaS Billing Systems 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Stripe Payments & SaaS Billing Systems 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Stripe Payments & SaaS Billing Systems 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Welcome to Stripe Checkout!

Stripe Checkout is a pre-built, hosted payment page. Stripe handles the hard parts — security and compliance — so you never touch raw card details.

How Stripe Checkout Works

How Checkout works: your server creates a session, the customer is redirected to Stripe's secure page to pay, then sent back to your site afterward.

The Checkout Session Object

The Checkout Session object describes the payment: the line_items being bought, the mode, and the success and cancel redirect URLs.

Setting Up Your Server

To create a session you need a small server (Node, Python, Ruby, PHP, etc). Install the Stripe library and init it with your secret key — never expose it client-side.

Creating a Checkout Session

Here's how to create a one-time Checkout Session on your server. Swap in your real secret key; it prints the session ID and URL.

const stripe = require('stripe')('sk_test_YOUR_SECRET_KEY');

async function createCheckoutSession() {
  try {
    const session = await stripe.checkout.sessions.create({
      line_items: [
        {
          price_data: {
            currency: 'usd',
            product_data: {
              name: 'CoddyKit Course',
            },
            unit_amount: 1999, // $19.99
          },
          quantity: 1,
        },
      ],
      mode: 'payment',
      success_url: 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
      cancel_url: 'https://example.com/cancel',
    });
    console.log('Checkout Session created:');
    console.log('  ID:', session.id);
    console.log('  URL:', session.url);
  } catch (error) {
    console.error('Error creating Checkout Session:', error.message);
  }
}

createCheckoutSession();

Redirecting to Checkout

The server returns a session.url; your client then redirects the user there with window.location.href = session.url to reach Stripe's secure page.

Handling Success & Cancel

After paying or cancelling, the customer returns to your success_url or cancel_url. The success URL can carry the session ID for confirmation.

Retrieving Session Details

On the success page, use the session_id to retrieve the full session on your server. That confirms payment status before you fulfill the order.

Security & PCI Compliance

Checkout's big win is security: Stripe handles all card data, your server never sees card numbers, and your PCI compliance burden drops dramatically.

Quick Check

Which of the following are key benefits or features of using Stripe Checkout for processing payments?

Recap: Your First Payment

Recap: Stripe Checkout is a hosted page driven by a session object you create server-side, then a redirect, post-payment handling, and big security wins.

常见问题解答

「使用 Checkout 完成首笔支付」课时是免费的吗?

是的 — 「使用 Checkout 完成首笔支付」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Stripe Payments & SaaS Billing Systems 课程的其余内容,请升级到 CoddyKit PRO。 Stripe Payments & SaaS Billing Systems 课程共包含 4 节课。

「使用 Checkout 完成首笔支付」这节课中我会学到什么?

使用 Stripe Checkout 实现简单的支付流程,演示如何收集卡片信息并完成交易。 你通过在浏览器中直接运行的动手代码来练习 Stripe Payments & SaaS Billing Systems,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Stripe Payments & SaaS Billing Systems 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Stripe Payments & SaaS Billing Systems 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。

「使用 Checkout 完成首笔支付」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Stripe Payments & SaaS Billing Systems 课中编写并运行代码吗?

能。每节 Stripe Payments & SaaS Billing Systems 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 了解在线支付生态系统
  2. Stripe 账户设置与仪表板导览
  3. 使用 Checkout 完成首笔支付
  4. 了解 Stripe 测试模式与测试卡
← 返回 Stripe Payments & SaaS Billing Systems