AI Powered SaaS: Stripe + Auth + Billing + Deploy · บทเรียน

การเรียกเก็บเงินตามการใช้งานและการตั้งราคาตามปริมาณการใช้

เรียกเก็บเงินลูกค้าตามการใช้งานจริง โดยรายงานการใช้งานไปยัง Stripe ตั้งค่าราคาแบบคิดตามปริมาณ และสร้างระดับราคาอิงตามการใช้งานสำหรับ AI SaaS

บทเรียน 4 จาก 413 ขั้นตอน

การเรียกเก็บเงินตามการใช้งานและการตั้งราคาตามปริมาณการใช้ เป็นบทเรียน AI Powered SaaS: Stripe + Auth + Billing + Deploy ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน AI Powered SaaS: Stripe + Auth + Billing + Deploy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส AI Powered SaaS: Stripe + Auth + Billing + Deploy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Why Usage-Based Pricing?

Flat subscriptions do not fit products where cost scales with consumption — like AI tokens or API calls. Metered billing charges customers for actual usage, aligning revenue with cost.

Licensed vs Metered Prices

Stripe prices come in two usage types:

  • Licensed: a fixed quantity (e.g. 5 seats)
  • Metered: quantity reported over time and billed at period end

Creating a Metered Price

Define a recurring price with usage_type: metered. Stripe sums reported usage for each billing cycle.

await stripe.prices.create({
  product: productId,
  currency: 'usd',
  recurring: { interval: 'month', usage_type: 'metered' },
  unit_amount: 2
});

Subscribing Without a Quantity

For metered items you do not set a quantity at subscription time — Stripe learns it from usage reports.

await stripe.subscriptions.create({
  customer: customerId,
  items: [{ price: meteredPriceId }]
});

Reporting Usage

As customers consume the product, report usage against the subscription item. Use action: increment to add to the running total.

await stripe.subscriptionItems.createUsageRecord(itemId, {
  quantity: 1000,
  timestamp: Math.floor(Date.now() / 1000),
  action: 'increment'
});

When to Report

Report at the moment usage happens — for example, after each AI completion count its tokens. Buffer high-frequency events and flush periodically to avoid hitting API limits.

async function onAiCall(itemId, tokens) {
  await reportUsage(itemId, tokens);
}

Idempotent Reporting

Avoid double-counting on retries by sending an idempotency key. Stripe ignores duplicate requests with the same key.

await stripe.subscriptionItems.createUsageRecord(
  itemId,
  { quantity: 1000, action: 'increment' },
  { idempotencyKey: 'usage-' + eventId }
);

Tiered Pricing

You can combine metering with tiers: the first 10,000 units cost more per unit, additional units less. Stripe computes the blended total automatically.

recurring: { usage_type: 'metered' },
billing_scheme: 'tiered',
tiers_mode: 'graduated'

Showing Usage to Customers

Customers want transparency. Fetch the current period's usage and display it in their dashboard so there are no billing surprises.

const summaries = await stripe.subscriptionItems.listUsageRecordSummaries(itemId);

Combining Plans

Many SaaS use a hybrid model: a fixed monthly base fee (licensed) plus metered overage. Add both prices as separate items on one subscription.

items: [
  { price: baseFeePriceId },
  { price: meteredPriceId }
]

Best Practices

Run metered billing reliably:

  • Use metered prices for consumption-based products
  • Report usage with increment and idempotency keys
  • Consider tiered pricing for volume
  • Show usage to customers for transparency

Quick Check

Test your metered billing knowledge.

Recap

You added usage-based billing:

  • Create metered prices and subscribe without a quantity
  • Report usage with increment and idempotency keys
  • Use tiered pricing and hybrid base-plus-overage models
  • Surface usage to customers for transparency

Your AI SaaS now charges fairly for what users consume.

เริ่มต้นได้ฟรี

เรียนรู้ AI Powered SaaS: Stripe + Auth + Billing + Deploy ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

คำถามที่พบบ่อย

บทเรียน “การเรียกเก็บเงินตามการใช้งานและการตั้งราคาตามปริมาณการใช้” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การเรียกเก็บเงินตามการใช้งานและการตั้งราคาตามปริมาณการใช้” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส AI Powered SaaS: Stripe + Auth + Billing + Deploy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส AI Powered SaaS: Stripe + Auth + Billing + Deploy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การเรียกเก็บเงินตามการใช้งานและการตั้งราคาตามปริมาณการใช้”

เรียกเก็บเงินลูกค้าตามการใช้งานจริง โดยรายงานการใช้งานไปยัง Stripe ตั้งค่าราคาแบบคิดตามปริมาณ และสร้างระดับราคาอิงตามการใช้งานสำหรับ AI SaaS คุณปฏิบัติ AI Powered SaaS: Stripe + Auth + Billing + Deploy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน AI Powered SaaS: Stripe + Auth + Billing + Deploy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน AI Powered SaaS: Stripe + Auth + Billing + Deploy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “การเรียกเก็บเงินตามการใช้งานและการตั้งราคาตามปริมาณการใช้” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน AI Powered SaaS: Stripe + Auth + Billing + Deploy นี้ได้ไหม

ได้ บทเรียน AI Powered SaaS: Stripe + Auth + Billing + Deploy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การจัดการการสมัครสมาชิก
  2. การจัดการเว็บฮุกของ Stripe
  3. พอร์ทัลลูกค้าและประวัติการเรียกเก็บเงิน
  4. การเรียกเก็บเงินตามการใช้งานและการตั้งราคาตามปริมาณการใช้
← กลับไปที่ AI Powered SaaS: Stripe + Auth + Billing + Deploy