当用户创建订阅并付款时,在 "stripe" 控制台中没有任何费用,发送了 0 比索

When a user creates a subscription and pays, in the "stripe" console nothing was charge, 0 pesos were sent

创建订阅时,像这样:

import Stripe from 'stripe';

const stripe = Stripe(process.env.STRIPE_API_KEY_SERVER);
const freePlan =
  process.env.NODE_ENV === 'production'
    ? 'price_xxxx'
    : 'price_xxxx';

export default async (req, res) => {
  const { customerId, tokenId, price } = req.body;

  try {
    const source = await stripe.customers.createSource(customerId, {
      source: tokenId,
    });

    if (!source) {
      return res.json({ ok: false, error: 'Stripe failed to attach card' });
    }

    const sub = await stripe.subscriptions.create({
      customer: customerId,
      items: [{ price }],
      trial_end:
        price === freePlan
          ? new Date(Date.now() + 30 * 24 * 60 * 60 * 1000)
          : undefined,
    });

    return res.json({ ok: true, subId: sub.id });
  } catch (error) {
    console.error(error);
    return res.json({ ok: false, error });
  }
};

请愿成功,但是看到stripe控制台,什么都没有收费...

并且产品有其价格...(在这种情况下,使用的是“计划月经”)。

我们能做什么?谢谢!

使用计量价格未指定为创建订阅的调用的一部分。相反,当您的客户使用您的产品时,您将使用使用记录 API (https://stripe.com/docs/api/usage_records/create). At the end of each billing period, Stripe charge the Customer based on the reported usage. You can see a full walk-through on how to used metered billing with subscriptions here (https://stripe.com/docs/billing/subscriptions/metered#report-usage).

将使用情况报告回 Stripe

如果您确实预先知道订阅项目的数量(在创建订阅时),那么您可能想要切换到许可价格而不是计量价格。