#johann-muller_api

1 messages ยท Page 1 of 1 (latest)

lean fiberBOT
lost ferryBOT
#

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.

lean fiberBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can 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/1248198239824384114

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

magic pasture
lean fiberBOT
onyx compass
#

Ok I tried to use Schedules to start a subscription in the future, and have a trial period, with a billing anchor in the following month but it just doesn't come out correct.

$subscription = $this->stripe->subscriptionSchedules->create([
'customer' => 'cus_QF6VLH0v0C4qI5',
'start_date' => $trialStart,
'phases' => [
[
'items' => [
[
'quantity' => 1,
'price' => 'price_1PL73iQeTVnMyqsf7VZ3cfU0',
],
],
'add_invoice_items' => [
[
'price' => 'price_1PMXO5QeTVnMyqsf8sLUBH0Q',
'quantity' => 1,
],
],
'trial_end' => $trialEnd,
'iterations' => 1,
],
[
'items' => [
[
'price' => 'price_1PL73iQeTVnMyqsf7VZ3cfU0',
'quantity' => 1,
],
],
],
],
], ['stripe_account' => $siteData->StripeAccountId]);

If I do this in the Dashboard it works perfect so please how do I get this (as per image) done using the API - I'm sure I'm just being stupid again and missing something small ... if it works in the Dashboard without using schedules, shouldn't it work in the API without schedules?

hoary veldt
#

๐Ÿ‘‹ taking over for my colleague. Let me catch up.

#

would you mind sharing the request ID that generated the wrong subscription schedule?

onyx compass
#

Sure - let me run it again

#

req_a195qer1fuxl1i

lost ferryBOT
onyx compass
#

issue is we need a "gap" between when the trial ends to when the first "billing cycle" should start and the system needs to pro-rate that gap - check the image, the blue line ๐Ÿ™‚

#

oops - I see the image has some elements missing

idle hamlet
#

I suppose a quick way to do this is to do it in the Dashboard(as you say that does what you're looking for) and then look at the API request it is making in your Developers>Logs section, and then write code to make the same call

onyx compass
#

here's the image again with the correct result I got doing it in the dashboard - like a breeze ๐Ÿ™‚ Just need to find how to "translate" this into API call/s

#

apologies I didn't notice the first image was wrong

#

You see when I run this client through the test clock the invoices are done correct time and correct amounts.

idle hamlet
#

I really appreciate the image but it's not entirely clear to me(it's always hard to wrap my head around these topics). I think your best option is what I said above, do it in the Dashboard and copy what it does. I can help you with that if you maybe have an example sub_sched_xxxx created that has your desired behaviour

onyx compass
#

Let me try explain it from the product and selling point, perhaps that helps to clear it up a little.

  1. We have a "service" we sell as a subscription (90EUR) which has a fixed billing cycle of 1 month and bills every 15th of the month.
  2. We also provide a 1 month trial at 45EUR and the customer can selected their start date.

So customers buys the service today (6.6) and selects 20.6 to start the service.

  1. So we need to invoice the customer on the 20.6 (start of service or "duration" in Dashboard) = 45EUR. The customer then starts the 20th and their trial ends the 19th of July BUT the invoice cycle is the 15th and the next 15th is 15.8. So the system creates a pro-rate invoice for that period between the 19.7 and 15.8 - works perfect if I do it via the dashboard as you can see at the top of the image - 3 invoices.
  2. So prorated invoice from 20 Jul 2024 - 15 Aug 2024 - perfect
  3. Next invoice then for the "Billing Cycle start" @ 90EUR
#

Let me add the anchor and see - 1 minue

#

minute

#

wait the billing_cycle_anchor only works in the subscription->create - we are told to use the schedules

idle hamlet
#

yeah that's what I meant when I said "the top of my head I can't give an example of doing it with a SubscriptionSchedule but we can work it out".
You say this works when you use the Dashboard, so lets again, start with that(do it in the Dashboard, we'll look at the sub_sched_xxx it created, and work out the PHP needed to replicate).

onyx compass
#

Ok - I will do one again for a new client in the dashboard and send you the detail - 1 minute

#

ok done.

#

client: cus_QF7c1QXgwOFTZ5

#

Subscription: sub_1POdPaQeTVnMyqsfs14R9V4I

idle hamlet
#

ok I'll look in a bit, unfortunately there's a burst of questions right now

onyx compass
#

So there's no rush - I have been hacking at this for some time so I can wait ๐Ÿ™‚

idle hamlet
#

but I think this initial_billing_cycle_anchor paramter it's using is not something available in the public API, let me look.

onyx compass
#

thanks - I'm also looking at the Inspector - never knew it added the Dashboard created items there as well. This API and tools just never stops amazing me - great stuff!!

idle hamlet
#

ok so initial_billing_cycle_anchor is something Dashboard-only for now. I think that without that, the only workaround is either

  • manually create the Subscription in the future at the time you want it to start, and set trial_period + billing_cycle_anchor per https://docs.stripe.com/billing/subscriptions/trials#combine-trial-anchor , at that time(i.e. implement the "schedule/cron job" part yourself
  • continue to use the Dashboard for this (probably not scalable)
  • use a Schedule in the public API, but use a trial period for the whole time until the anchor(the start_date of the next phase)(the black and blue bars in your picture would just become one long trial period). I don't think that does exactly what you want though as it won't do the proration, sorry.
onyx compass
#

thanks for all the help but wow it must be possible in the API - don't think this is a unique business model ๐Ÿ˜ฆ

Cannot do this is the dashboard - it's a complete SaaS system and connected accounts don't have access to this in the dashboard

Can you please escalate this to the dev team and ask how this can be done BIG please. This is the last part of the API and we;re done and go live

idle hamlet
#

FWIW this is feedback/feature requests that are being actively worked on I think

#

Can you please escalate this to the dev team and ask how this can be done BIG please. This is the last part of the API and we;re done and go live
I mean I already have, I bumped some internal feedback. If you want to escalate it more, you'd need to file support tickets/ask your sales account manager etc. But for now the best workaround is the first one I said, implement your own cron model to create the Subscription at the date required, I think.

onyx compass
#

๐Ÿซฃ cron will be ugly solution and can just see that going south ๐Ÿ˜†

#

But again thanks for all the help - always helps having a chat to see what can and cannot be done. You people do a GREAT job and the Stripe API / system is TOP notch!!