条纹订阅现在和每个月的第一天支付

时间:2021-02-05 18:17:14

标签: stripe-payments

我正在尝试通过 Stripe API 创建订阅。我已经创建了产品和项目,现在需要为用户提交订阅,但我现在需要向客户收取全价 - 无论是当月的哪一天 - 然后在每个月初收费 -即使明天开始。

看起来我现在可以创建一个一次性项目来收费,然后为每月的计费周期设置订阅,但我想知道我是否可以通过订阅在一次调用中完成所有操作 => 创建函数.我不想按比例分配第一个月,我看不出有什么方法可以告诉它现在收取全价,并在接下来的每个月的第一天重复设置。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:1)

处理您所描述的流程的一种方法是组合 backdate_start_datebilling_cycle_anchor 属性。这个想法是,在创建订阅时,您将 billing_cycle_anchor 设置为下个月的第一天,并将 backdate_start_date 设置为当月的第一天。例如,假设您想为用户注册今天(2 月 5 日)开始的 10.00 美元订阅,但您想立即向他们收取 10.00 美元的全部费用(即使他们错过了前 5 天)。然后,您希望在 3 月 1 日以及此后每个月的第一天再次向他们收取 10.00 美元的帐单。创建订阅时,您将设置:

  • billing_cycle_anchor:1614556800(3 月 1 日)
  • backdate_start_date:1612137600(2 月 1 日)

这将导致今天的发票为 10.00 美元,3 月 1 日的发票再次为 10.00 美元,以后每个月的第一天的发票为 10.00 美元。

这是在 Node 中的样子:

(async () => {
  const product = await stripe.products.create({ name: "t-shirt" });

  const customer = await stripe.customers.create({
    name: "Jenny Rosen",
    email: "jenny.rosen@gmail.com",
    payment_method: "pm_card_visa",
    invoice_settings: {
      default_payment_method: "pm_card_visa",
    },
  });

  const subscription = await stripe.subscriptions.create({
    customer: customer.id,
    items: [
      {
        quantity: 1,
        price_data: {
          unit_amount: 1000,
          currency: "usd",
          recurring: {
            interval: "month",
          },
          product: product.id,
        },
      },
    ],
    backdate_start_date: 1612137600,
    billing_cycle_anchor: 1614556800,
    expand: ["latest_invoice"],
  });

  console.log(subscription);
})();