#anthonyg-sub-schedule

1 messages · Page 1 of 1 (latest)

brisk dune
#

Hmm

rustic escarp
#

Yeah, I couldn't see a clean way of doing this.

brisk dune
#

I don't think you can manage this with the schedule itself, but you can manipulate the invoice to defer payment by disabling auto-advance

#

ie, you could stop the autoadvance while it is a draft to avoid finalizing and paying, then finalize it on the 15th

rustic escarp
#

Ok, interesting. I've never worked with this. So how is that done and can I get it to automatically charge the card on file for the invoice for that later date?

brisk dune
#

So you'd monitor the invoice.created webhook event for that sub and update the invoice in the 1hr window before it finalizes

#

If they have a default payment method that would already be the one used, so once it finalizes that would be what happens

rustic escarp
#

So the workflow we have is that a staff member sits down and updates our billing account in a database. We want to have them make the change there and then run a script to update their account. We don't have any webhook events being monitored in other words. Is there no way to just set something on the schedule phase like delay payment until a certain date so that it automatically charages them on that later date?

brisk dune
rustic escarp
#

I've seen in the dashboard a way to pausing collection until a specific date for a schedule, but wasn't sure what that was.

brisk dune
#

No, you could have the schedule shift the payment with a short trial period say, but this would also change the billing period

rustic escarp
#

Yeah I checked that out and noticed it makes the invoice look weird.

brisk dune
rustic escarp
#

So does this pause resume auto charging on that date. Looked to me like it allows invoices to go into draft mode in the pause period, but wasn't clear whether it auto paid them once things resumed.

#

Ok so the doc you sent looks like it's saying that if you set a resume date, but that to charge the draft invoices created during the pause you'd have to specifically set auto_advance back to true with a separate call.

brisk dune
#

yea, exactly

rustic escarp
#

Ok, so just setting the resume date at the time of pause doesn't reenable auto advance???

#

Looks like you can specify specific invoices to re-enable auto_advance or use a sub ID to do all drafts. So why doesn't the resumes_at date do this?

brisk dune
#

I think this is just a limitation of pause+schedules, as far as i can tell

#

So you will need to manage it as described

rustic escarp
#

So if it were just a sub not on a schedule would setting a resumes_at date automatically reeenable the auto_advance for old draft invoices?

#

It still seems like you have to set auto_advance back manually, but I want to be sure as this would be a distinct advantage of not using schedules.

brisk dune
#

Ah no, it looks like it all cases you need to resume auto advance directly. The resume at date just stops future invoices from staying as draft (its effectively disabling autoadvance at invoice creation to prevent payment like you describe).

rustic escarp
#

So is there a webhook event for when a sub schedule resumes after having the resumes_at param set when pausing collection?

sterile stirrup
#

I don't think there's a specific webhook in that case, just when it cycled

rustic escarp
#

So was discussing earlier how to pause a subscription and then resume later as a way to delay and invoice getting charged. But the draft invoice then needs to be collected on after the resume date and to do that you need to specify that it turn back on auto_advance for the invoice. But wondering how to do that based on setting the sub schedule to paused action. Is there a way to do that?

sterile stirrup
#

I'm sorry I do not understand what you mean at all 😅

rustic escarp
#

I've got a subscription on a schedule that I want to set to pause collection on with a resumes_at date. There will be an invoice that gets generated after I paused but before the resumption that will go to draft status. On the date of the resumes_at I want to them charge that draft invoice by setting it's auto_advance back to true. Can I do that using a webhook to let me know when the subscription resumes is what I'm trying to find out.

sterile stirrup
#

I'm not sure sorry. I'd recommend trying with resumes_at a few minutes in the future and seeing what happens

rustic escarp
#

What? What do you mean try what with resumes_at?

sterile stirrup
#

You're asking what happens right? So why not try it?

rustic escarp
#

No, I'm not.

#

I'm asking if I can get webhook notification when a subscription changes from paused to unpaused.

sterile stirrup
#

hum

#

I'm sorry, sometimes I'm unclear what is blocking you

#

Like I understand the question, and I know you would rather get a straight answer with a clear yes or no. But I don't know the answer to that question, neither do my colleagues. So the best next step is to try that flow and then see if you do get an event or not

#

I'm happy to try, but it will take me a couple hours to reply with a definitive answer. If that works for you though I can start now

rustic escarp
#

Ok, well, if someone's gotta try something to know and it'll take you a couple of hours then I might as well spend the time doing it so I have it setup, in the event that it works. If it doesn't work, though, then it's a waste of two hours of my time. Which is why I like to ask yes or no questions like I do. But no one knows. So I'm happy to try. What webhook event do I try, the subscriptions_schedule.updated? I don't see much clear info on which webhook to even try that might give me the changes status I'm looking for.

sterile stirrup
#

it will take me 2 hours because I;m doing a lot of other things. It should take you like 5 minutes to test with code since you're deep into this and schedules and should have all the code for it

#

you shouldn't need to try a specific webhook either. You configure the schedule to resume and then you wait for that time and then you see waht exact events are sent if any

rustic escarp
#

Oh yeah, I totally get why it would need to take you several hours as I know you're working on other things. Wasn't complaining about that at all. Sorry if it came across the wrong way there.

Wait so where do I see what exact events are sent if any? I was thinking I'd need to setup a webhook framework to test things. If I can see what events are sent that's great! (And no wonder why you were saying just test it. I thought I needed to setup a webhook to test it)

sterile stirrup
#

All events are displayed in the Dashboard

rustic escarp
#

Ahhh I See that.

sterile stirrup
#

both on the Subscription page itself adn in the Events tab

#

and you can also use the CLI and such to see a "stream of event"

#

I'm also trying to test now before my next meeting so I might get lucky

rustic escarp
#

Yeah, I haven't tried the CLI stuff out yet.

sterile stirrup
#

okay my schedule is taking too long to cycle and so struggling to test resumes_at reliably but keeping attempts

#

okay now I have a schedule with the sub paused for ~10 minutes, the new invoice is created in draft, now I'm waiting to see it cycle to see what event(s) are generated when the pause stops (if any)

rustic escarp
#

Yeah, I was getting the same problem of delay. Is there a way to finalize a newly scheduled invoice right after it's created instead of waiting the normal 1 hour?

sterile stirrup
#

I'm not sure why that would matter, don't you want to pause the subscription when it's already ongoing?

rustic escarp
#

Yeah, so I was using a test account and had to create a new schedule first. Deleted out the million that I had in there already yesterday to clean things up!

sterile stirrup
#

ah gotcha, so what I did is this: ```$schedule = $stripe->subscriptionSchedules->create([
'customer' => $customer->id,
'start_date' => 'now',
'phases' => [
[
'trial_end' => time() + 30,
'items' => [
['price' => 'testidreuse'],
],
'iterations' => 2,
],
],
]);
stripeDump($schedule);

$subscription = $stripe->subscriptions->update(
$schedule->subscription,
[
'pause_collection' => [
'behavior' => 'keep_as_draft',
'resumes_at' => time() + 300,
],
]
);
stripeDump($subscription);```

#

create a schedule with a trial of 30s => first invoice is $0, then schedule cycles after 30s, but quickly update the sub to be paused for 5 minutes so that when we cycle at the end of the trial, the new invoice is in draft (if you're lucky)

#

and now I'm waiting for the 5 minutes to be done and for our background job to catch the resumes_at has changed

#

Okay I got customer.subscription.updated with "previous_attributes": { "pause_collection": { "behavior": "keep_as_draft", "resumes_at": 1636057392 } }

#

this means something like "the subscription was paused, it's not paused anymore, so we send you an event to tell you about this"

#

so your code can listen to that specific event, and then check if that subscription had paused invoices and if so explicitly attempt to charge them

rustic escarp
#

Ok, perfect this is exactly what I was hoping would be possible! Thanks for testing that so quickly! One other question, on the subscription, the pause didn't change any of the schedule phase period info like the billing period the invoice that drafted and then was finalized?

sterile stirrup
#

correct it's really just some "please stop charging"

#

we built it quickly when COVID happened

#

lots of businesses wanted time to figure things out but keep all invoices/cycles identical

rustic escarp
#

Yeah, it's totally useful for us even now so that we can quickly adjust a customer's bill date for one installment, but keep everything else on track and not have to edit the phases or whatever.

#

Now I still have one more use case to figure out which is when a customer is behind say two installments and we want to start them now and bill them for one not both and then bill the second one like 15 days after the first one / start of the subscription. Was hoping to use this pause logic to do that as well.

#

If I back date the sub schedule then it bills them for the entire amount since the start date.

sterile stirrup
#

yeah I really think most of your flows are just impossible unfortunately, they are really special/specific, I have never seen a user ask for this before

#

you'd be better off making one-off invoices, but that hurts revenue recognition

#

pausing won't work unfortunately and I can't think of a clean way in that case

rustic escarp
#

Yeah, one big problem for us is that we basically just bill one total lump sum amount into different installment plans. Ideally we'd be able to setup 9 payments and just simply specify the date to bill each of the 9 on. Then we'd be able to change any one of them to whatever we want in terms of dates. Guess that's maybe what you mean by one-off invoices. It's just too bad we can't setup a subscription with a bunch of one-off invoices in them, or not have them have to be so chained together.

#

Can you see any value in us setting up basically a phase in a schedule for each payment?

#

The case I'm trying to solve now btw are not really our regular flows. They are edge cases and are really happening because we got behind on getting customer started with their installment plans.

#

When all is normal, they are paying in even monthly installments, or twice per season, or once, all on the same date of the 3rd of whatever month.

sterile stirrup
#

yeah I think I would do the phases like I recommend the other day

#

the main issue is that you need to be super sure you won't have any rogue proration because your phase period won't match the subscription's real period

rustic escarp
#

So is there a way to process a payment on an invoice for a partial amount?

sterile stirrup
#

no that does not exist

rustic escarp
#

How about this? Let's say I create a sub with a schedule back dated to Nov 3rd with the first phase ending on Dec 3rd. That generates and invoice for what would be our second installment. I then pause collection on the subscription before the invoices gets charged and set the resume date to Nov 15th so I can then use the webhook method we discussed above to turn auto processing back on and charge the card on that date for that invoice. Then I create an invoice that I associate with the subscription for what would have been our first installment from back on Oct 3rd for the period from Oct 3 to Nov 3rd and I pay that invoice right away, right after the schedule is created. So that invoice is the first thing to get paid and then the next is the draft invoice that got created while the sub was paused. Would that work? Only thing I'm unclear on would be how do I specify when creating the invoice what period it's for on the sub, or what price to include or whatever in terms of the cost?

sterile stirrup
#

That's the thing, the last sentence is just impossible

#

you can't make an Invoice on Nov 15 and backdate it the way you want it, it's just impossible sadly

#

you can hack things around the way you described but the period won't match

rustic escarp
#

Well if I make the schedule start on Nov 3rd and then pause the sub until Nov 15th, then the first period of the sub would be Nov 3rd to Dec 3rd. Perfect. It just gets paid on the 15th because of the pause and restart webhook method from earlier. So then that just leaves it for me to get paid what would have been the first invoice right away now by creating a one off invoice and paying that right away when created. I read in the api you can create an invoice and specific that it belongs to a subscription, but I'm not exactly sure what associating it to a sub does or how I would set the amount to be charged on the one-off invoice.

sterile stirrup
#

associating it to a subscription mostly makes you find the invoice when you do https://stripe.com/docs/api/invoices/list + subscription: 'sub_123' and pulls in pending invoice items for that specific subscription

rustic escarp
#

Ok so you’d have to create invoice items on the sub first before creating the invoice so that they pull in when associating it with that subscription? Am I understanding that correctly?

sterile stirrup
#

kind of. Like you can't just create an invoice, the API doesn't take "line items" so you always have to create invoice items on the customer first and then create an invoice to pull them in the invoice

rustic escarp
#

Ok. So is that a one off invoice like you were talking about that wouldn’t get pulled into recurring revenue calculations or whatever?

sterile stirrup
#

yeah I don't know anything about revenue recognition unfortunately. It's tied to the sub itself if you pass subscription: 'sub_123' on invoice creation but it'd represent an invoice for something a month ago and I don't know how it works

rustic escarp
#

Ok great. Yeah I saw that just now too on the invoice items. I’ll play with this and see if that works.

sterile stirrup
#

good luck!