One way to go about the flow you're describing is to combine the backdate_start_date
and billing_cycle_anchor
properties. The idea is that when creating the subscription you would set the billing_cycle_anchor
to the first of the next month, and you would set the backdate_start_date
to the first of the current month. For example, say you wanted to sign up a user for a $10.00 subscription that starts today (February 5th), but you want to bill them for the full $10.00 right away (even though they missed the first 5 days). Then, you want to bill them $10.00 again on March 1st, and the first of every month thereafter. When creating the subscription you would set:
billing_cycle_anchor
: 1614556800 (March 1st)
backdate_start_date
: 1612137600 (February 1st)
Which would result in a $10.00 invoice today, and a $10.00 invoice again on the first of March, and subsequent $10.00 invoices on the first of every month going forward.
Here's what this would look like in 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);
})();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…