You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于定价矩阵的Stripe订阅实现咨询:宠物食品订阅站开发

Got it, let's walk through exactly how to build this 36-variant subscription pricing model on Stripe—your setup with tiered user statuses, weight ranges, and add-ons fits perfectly with Stripe's core Products & Prices system plus Subscription Items. Here's a step-by-step breakdown:

1. Define Base Subscription Products & Tiered Prices

First, map each of your 4 weight ranges to a Stripe Product (think of a Product as a parent category for your subscription). For example:

  • Create a Product named 4kg-14kg Pet Food Monthly Subscription, set its type to recurring (since it's a monthly delivery), and add a description for internal clarity.

For each of these 4 Products, create 3 separate Price objects—one for each user tier (INACTIVE, AVERAGE, ACTIVE). Key details for each Price:

  • Set unit_amount in cents (e.g., $58.00 = 5800)
  • Set currency to your target currency (USD in your case)
  • Set recurring.interval to month
  • Add metadata to tag each Price for easy filtering/managing, e.g.:
    metadata: {
      weight_range: "4kg-14kg",
      user_tier: "INACTIVE",
      price_type: "base"
    }
    

This gives you your 12 base price variants, all neatly organized under their respective weight-range Products.

2. Create Add-on Products & Prices

Next, model your 3 add-ons as separate Stripe Products (each as a recurring subscription type, since they're monthly add-ons to the base plan). For each add-on, create a single Price (since you mentioned 3 fixed add-on prices). Again, use metadata to tag these as price_type: "addon" for easy differentiation.

3. Assemble Subscriptions with Combined Items

When a user selects a base tier + add-on, create a Stripe Subscription that includes two Subscription Items: one for the base Price, and one for the add-on Price. Here's a quick example using the Node.js SDK:

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

// Create the subscription with both base and add-on items
const subscription = await stripe.subscriptions.create({
  customer: 'cus_123456', // Your user's Stripe Customer ID
  items: [
    { price: 'price_base_active_4-14kg' }, // ID of the selected base Price
    { price: 'price_addon_premium' }        // ID of the selected add-on Price
  ],
  payment_behavior: 'default_incomplete', // Handles cases where payment needs confirmation
  payment_settings: { save_default_payment_method: 'on_subscription' },
  expand: ['latest_invoice.payment_intent'], // Return payment intent details for frontend
});

This automatically combines the two recurring prices into a single monthly charge for the user.

4. Handle Dynamic Tier Changes (If User Statuses Shift)

If a user's tier changes (e.g., from INACTIVE to ACTIVE), you can update their subscription's base Price without creating a new subscription. Use the Subscription Items API to swap out the base Price:

// Update the base subscription item to the new tier's Price
await stripe.subscriptionItems.update(
  'si_789012', // The Subscription Item ID for the base plan
  { price: 'price_base_active_4-14kg' },
  { proration_behavior: 'create_prorations' } // Optional: Control how prorations are handled
);

This will adjust the user's monthly charge starting from the next billing cycle (or immediately, if you tweak the proration behavior).

5. Pro Tip: Fetch Prices Dynamically for Your Frontend

Instead of hardcoding all 36 variants in your frontend, pull the Prices directly from Stripe's API. Filter using the metadata you added earlier to group base prices by weight range and tier, then let users select their combination. This way, if you ever adjust prices in Stripe, your frontend will automatically reflect the changes without code updates.


内容的提问来源于stack exchange,提问作者Tyssen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:03:07