#johan_api

1 messages ยท Page 1 of 1 (latest)

scarlet zodiacBOT
#

๐Ÿ‘‹ 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/1509841818509119619

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

torpid ruin
#

๐Ÿ‘‹ happy to help

bronze crater
#

hey tarzan thanks a lot

scarlet zodiacBOT
torpid ruin
#

yes this is tricky today since we don't have the billing_cycle_anchor_config param in the createPreview API

#

but you can still use the billing_cycle_anchor and get the utc timestamp of the beginning of that day

#

like billing_cycle_anchor_config: { day_of_month: 15 } for example translates to 15 June 2026 00:00 UTC

#

if you get that timestamp then you should be fine

bronze crater
#

I'm doing this on my end but sometimes it doesn't get it right with months that end in 30 days and the billing anchor is 31st for example.
const calcProratedData = (price: number, dayOfMonth: number) => { const today = moment().startOf('day'); const nextAnchor = today.clone().date(dayOfMonth); if (!nextAnchor.isAfter(today)) nextAnchor.add(1, 'month').date(dayOfMonth); // Use the next full billing period length as the denominator โ€” this matches // how Stripe calculates proration with billing_cycle_anchor_config, since months // like June don't have a 31st so the period length varies. const periodAfterAnchor = nextAnchor.clone().add(1, 'month'); const daysRemaining = nextAnchor.diff(today, 'days'); const daysInCycle = periodAfterAnchor.diff(nextAnchor, 'days'); return { price: Math.round((price * daysRemaining) / daysInCycle), from: today.format('D MMM YYYY'), to: nextAnchor.format('D MMM YYYY'), }; };

torpid ruin
#

note that we are working on improving the API to add parity but I can't provide any time line (because I have none tbh)

bronze crater
#

I guess is more secure the createPreview way so I might switch to that one if that's the case

#

let me try this again and get back to you if that's okay?

#

no worries at all I understnad

torpid ruin
#

yes sure

#

would you mind sharing your account ID? this way we can submit your use-case for the billing_cycle_anchor_config feature on the createPreview

bronze crater
#

this would be fantastic. acct_1CYhS4B45ZPr5ETA thanks a lot

#

do you have an estimated time of when this will be ready roughly? is it on this quarter?

#

after making the suggested changes:
const nextAnchorUTCTimestamp = (dayOfMonth: number): number => {
const today = moment.utc().startOf('day');
const candidate = today.clone().date(dayOfMonth);
if (!candidate.isAfter(today)) candidate.add(1, 'month').date(dayOfMonth);
return candidate.unix();
};

we're still not getting the exact number :/ we really want to resolve this because we have some possible churns and we've had the system like this for a while and we need to come up with a solution to resolve this. can you suggest something else? or is there something wrong there?

grim steppe
#

Sorry, we don't have a timeline for this at the moment

#

Can you share a request ID where you tried this approach?

scarlet zodiacBOT
cosmic flicker
#

Taking over from my colleague. Let me know if you've any follow-up questions