#nick-metered-upcoming
1 messages · Page 1 of 1 (latest)
so then what about this one? https://dashboard.stripe.com/subscriptions/sub_1KMBR6I67GP2qpb4oYdqcCwI
Trying to GET from the Stripe API returns error along the lines of:
InvalidRequestError(message='No upcoming invoices for customer: cus_L2Fwu0fveVbMKt', param=None, code='invoice_upcoming_none', http_status=404, request_id='req_gLMjQVEpvXfPUu')
stripe.error.InvalidRequestError: Request req_gLMjQVEpvXfPUu: No upcoming invoices for customer: cus_L2Fwu0fveVbMKt
here's a sub in the same account that does have the 0 upcoming invoice for no usage https://dashboard.stripe.com/subscriptions/sub_INMX71gw989JoK
so sorry I completely missed you reply, looking
that subscription is marked to cancel at the end of the current period, so there won't be a new invoice right @last solar ?
Theoretically, unless they add a credit card, at which point we will wipe the cancel_at_period_end parameter
But wouldn't a metered subscription still need the upcoming invoice, to charge at the time it cancels?
Like basically just because you set the subscription to cancel doesn't necessarily mean there won't be any further usage accrued until the time of cancellation... So would reporting said usage bring the upcoming invoice back?
Hmmm that's a good point. Does the upcoming invoice work if you add usage records?
Does it change the result of the GET request from the upcoming invoice API?
Trying that now
stripe invoices upcoming --customer cus_L8Lqq3tvIojlbG --subscription sub_1KS59hI67GP2qpb4GlM0OZKY
{
"error": {
"code": "invoice_upcoming_none",
"doc_url": "https://stripe.com/docs/error-codes/invoice-upcoming-none",
"message": "No upcoming invoices for customer: cus_L8Lqq3tvIojlbG",
"type": "invalid_request_error"
}
}
So no, AFAICT
Interesting, alright. Let me spin up my own reproduction of this.
I'm going to wipe the cancel_at_period_end to see if that brings back the invoice
Yeah so when I ran stripe subscriptions update sub_1KS59hI67GP2qpb4GlM0OZKY -d "cancel_at_period_end"=false and refreshed the dashboard, the upcoming invoice exists now
And then setting cancel_at_period_end back to true, the upcoming invoice remains...
I suspect it only considers the renewal invoice, and not the final invoice added for clearing out accrued metered usage
renewal invoice being what was generated when I "un-canceled" it?
This "bug" (for lack of a better term rn) makes me think Stripe is handling this subscription like a licensed one, where it's paid up front, so Stripe determines that there's no need for an upcoming invoice since the period has been paid for and it's canceling the sub at the end of the period
OH, it's probably worth mentioning that these subscriptions that are having this issue were at one point in time a licensed subscription. They've been converted to a metered one - but like I said earlier, I converted around 8500 subscriptions from licensed to metered, and only around 210 had this issue
Interesting, this is not happening with all such subscriptions?
It isn't, no. for example this subscription went through the same migration https://dashboard.stripe.com/subscriptions/sub_1Jk29NI67GP2qpb4NZhz9ars but has an upcoming invoice. It seems to only have affected subscriptions that had their cancel_at time set prior to migrating them from licensed to metered
Which kind of fits my hunch of Stripe still treating it as a licensed invoice I think?
@last solar earlier you mentioned specifically cancel_at_period_end but in my testing that didnt cause any issue
I was able to reproduce this with an explicit cancel_at prior to the end of the period
Yeah sorry I kind of use them interchangeably:
When the trial expires, we set the subscription to cancel 14 days after the expiry utilizing the cancel_at parameter, since the period end may not be 14 days away. (therefore you have a 14 day trial, and then we lock your access to the product - but keep their data around for 14 days in case they add a credit card)
If they add a credit card, we un-set the cancel_at time - only way to do that with the API is by passing cancel_at_period_end=false, since the API doesn't accept null or 0 for updating the cancel_at time
So for the subscriptions you're looking at, they're in the state of trial expired, cancel_at time was set explicitly to 14 days in the future, and we're just waiting for them to either add their card or for the subscription to cancel
You should be able to send an empty string to clear cancel_at
I just tested this to confirm
Ah, didn't try that way back when I built the lifecycle. Good tip.
(but that's unrelated to the bug)
I've been thinking about this and I'm pretty sure I can make it work as-is. If the customer doesn't have a credit card, we won't be able to bill them anyways so no point in trying to invoice them. Since cancel_at_period_end=false brings back the upcoming invoice, we'll just keep doing that when they add the card and we can bill accordingly from that point
Also, I don't expect this migration to have to ever happen again so as these cancel out, the problem will fade away
But definitely some weird behaviour. Hopefully I didn't send you deep down the rabbit hole on a Friday at 4 lol
I'm writing this up to file the bug, and in my testing I'm finding the upcoming invoice works as intended with cancel_at_period_end=true so you might be able to switch to that to keep the pending cancellation in place
@last solar Do you want to email in and mentioned my username so I can keep in touch that way while we work on this?
You can send it to support@stripe.com and mention you talked to synthrider
Great. I'll send it over soon
Do you need me to provide any context in the email? Or will your bug report include everything?
We have all the information on our end so no need to rewrite all the context
Awesome. Sent it off. Thanks all!
Got it, thanks!