#oleg-codaio-update_subscription
1 messages · Page 1 of 1 (latest)
hello! you'd probably want to look into using Subscription Schedules : https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#resetting-anchor
Let's say for instance that there is an annual subscription with a term of March 1, 2022 - March 1, 2023. The customer would like to update the subscription to a different plan, which also come with a one-time setup fee. On Sept 8, 2022 at 1:05pm, they make the change. Here's what I want to happen:
- Subscription is updated with a new billing anchor - Sept 8, 2022 1:05pm - Sept 8, 2023 1:05pm
- Invoice sent out containing these line items:
- Unused time on 1 × Subscription after 08 Sep 2022
- 1 × Subscription (per seat) - [Sept 8, 2022 - Sept 8, 2023]
- Setup fee [Sept 8, 2022 - Sept 8, 2023] -
discountable = falseand also containing additionalmetadata
Here's what I tried:
- Using
subscriptions.updatewithadd_invoice_items. That works as far as setting theperiodcorrectly but there is no way for me to setdiscountableormetadataon the added invoice item - Creating the setup fee ahead of time using
invoiceItems.createand an explicitperiodand then updating the subscription withbilling_cycle_anchor: 'now'. But by the time the subscription is created, a few seconds may have passed so the period on the setup fee item doesn't match that of the subscription. Settingproration_dateonly affects the proration item but not the new subscription item
Thanks @spark berry! So I think subscription schedules have the same limitation because add_invoice_items doesn't allow setting metadata or discountable https://stripe.com/docs/api/subscription_schedules/create#create_subscription_schedule-phases-add_invoice_items
gimme a while to understand your requirements
isn't the setup fee item a one time fee?
yeah - use case is we're upselling the customer to a more expensive plan with a new one time setup fee
where are you seeing that the period on the setup fee item doesn't match that of the subscription?
since it's a one time fee, i'm a bit confused over what period you're seeing that doesn't match that of the subscription
it does if I use add_invoice_items. but if I manually add the item to the customer using invoiceItems.create then the period needs to be set explicitly
i.e., I add the invoice item as a pending item to the customer and when I update the subscription, that pending item gets slurped up into the next invoice
do you have an example request where you get the error that the period needs to be explicitly set? cause this is an optional parameter
oh it's optional but if I don't set it it's just auto set to the request time
then is that period visible to the customer anywhere on their invoice?
if the period isn't visible to the customer, and if you're not using the period to implement any logic, i don't think you need to worry about it
it's not so much what the customer sees as the value that gets set on invoice items - we sync the data via Stripe Data Pipeline, etc and use it for accounting purposes
but if you want it to match everything exactly - you could always set the period start and end when creating the invoice item
yeah - that's what I'm trying to do, but the issue is I can set the exact time when creating the item, but not when updating the subscription with a new billing cycle anchor timestamp
so it's off by a few seconds depending on latency and that causes some data integrity checks to go off on our end since ideally it'd all be exact
hmmm let me quickly test something
thanks!
sorry about the delay, had to step away to handle something urgent
so what i'd suggest is to still use Subscription Schedules. After the invoice is generated (and still in draft mode) invoice.created event, you can still update the invoice item to set discountable=false, and set the metadata. Stripe waits approximately one hour before finalizing the invoice and attempting payment, or sending an email.
np, thanks for the suggestion. we're also using this pay_immediately flag (from a legacy Avalara integration) so that also gives access to the same behavior
the only downside is it's a bit clunky since we have to iterate over the invoice later to find the items of interest, create an anonymous product for the fee (since the description is custom), archive it, etc so it's not particularly elegant
in the ideal world, add_invoice_items would be more fully featured so we could specify metadata, discountable, and for price_data to have product_data inside of it
though I left some feedback here #dev-help message
👋 stepping in and thanks for the feedback. I think my colleague has reported it
thanks! also one thing I noticed with schedules is they don't support setting pending_invoice_item_interval?
Yes as far as I can tell, unfortunately
thanks for confirming - would like to submit a feature request for this so we don't need to manage that out of band