#sanjay_api

1 messages · Page 1 of 1 (latest)

crimson fieldBOT
#

đź‘‹ Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

đź”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1389846638826098739

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

steep flicker
#

Hi! Looking into your query.

tranquil pulsar
#

This is what I tried:
async createSubscription(customerId, priceId1, priceId2, startDateUnix) {
const sub = await this.stripe.subscriptions.create({
customer: customerId,
items: [
{price: priceId1, quantity: 1},
{price: priceId2}
],
backdate_start_date: startDateUnix,
expand: ["latest_invoice.payment_intent"]
});
return sub;
}

steep flicker
#

Thank you for waiting! Looking at your request to create the subscription (https://dashboard.stripe.com/test/logs/req_dv1Zk55HwQp3qp), you passed 1751394600 as the backdate_start_date which is 2025-07-01 18:30:00 UTC. And you created the subscription on 2025-07-02 04:41:06 UTC. This automatically created a proration for price_1RfgVsCpfpVCWu67RrChlEQB between the 2 date / timings. And then it also charged the full amount of 150 from the billing cycle anchor to the next end period which is a day.

tranquil pulsar
#

inorder to avoid the extra 63 usd (proration) and only charge 150 usd, what should i do?

steep flicker
#

Any reason you are passing backdate_start_date?

tranquil pulsar
#

so that i will get every monthly invoices on corresponding day next month at 12 am only (00:00:00 time)

steep flicker
tranquil pulsar
#

i tried with proration: none, it worked.
But still, the next invoice time is not 12 am (next month), even if i backdated to 12 am today while creating subscription

steep flicker
#

Back date just determines when the subscription started. Then the amount is prorated to be charged from the backdated date to the time the subscription is created.

tranquil pulsar
#

my requirement is that i need to charge the flat rate immediately when subscription is created, after that next month (same date) at 12 am (00:00:00), i need to charge the usage of this billing period along with the flat charge of next month

#

if i use billing anchor, it charges the flat charge at that particular time right?

steep flicker
#

Lets say you were to create a subscription on 2nd July 17:00:00 UTC, you want $150 charged for 2nd July and then you want subsequent charges to be 3rd July 00:00:00, 4th July 00:00:00, 5th July 00:00:00, etc.?

tranquil pulsar
#

yes, something like this (but monthly, yeah i will update the billing period of those prices to monthly)

steep flicker
tranquil pulsar
#

you mean to create first subscription with only flat price and then create a new subscription item for usage based price (tiered) with billing anchor to next month

steep flicker
#

You can set the billing cycle anchor when you create the subscription with both the prices.

tranquil pulsar
#

but then it wont charge immeediately right?

steep flicker
tranquil pulsar
#

as per my requirements, when should i set bililing anchor?

steep flicker
#

If you create a subscription today, but want it to bill at the start of each month, you can set the date for the billing cycle anchor as 1 August.

tranquil pulsar
#

async createSubscription(customerId, priceId1, priceId2, threshold, startDateUnix) {
const nextMonth12AM = new Date();
nextMonth12AM.setMonth(nextMonth12AM.getMonth() + 1);
nextMonth12AM.setDate(nextMonth12AM.getDate());
nextMonth12AM.setHours(0, 0, 0, 0);
const sub = await this.stripe.subscriptions.create({
customer: customerId,
items: [
{price: priceId1, quantity: 1},
{price: priceId2}
],
billing_thresholds: {
amount_gte: threshold,
reset_billing_cycle_anchor: false
},
backdate_start_date: startDateUnix,
billing_cycle_anchor: Math.floor(nextMonth12AM.getTime() / 1000),
proration_behavior: "always_invoice",
expand: ["latest_invoice.payment_intent"]
});
return sub;
}

you mean this right?

#

i think i found the solution

steep flicker
#

I still see that you are passing the backdate_start_date. This will result in the same issue as you had earlier.

crimson fieldBOT