#alko89
1 messages · Page 1 of 1 (latest)
hi there, can you share the request id [0]? it'd look like req_xxx
req_Z3MYlWlCnHy8G4
basically its a 404 error, think its because it expects an invoice item instead of line item
where are you getting this invoice line item id from? il_tmp_1MBxsEGjQawimwZRpK9RYqxm
from an upcoming invoice
this is the code I have rn, I want to write a script to fix the upcoming invoices by removing remaining time items, after I updated prices with tax collection
const invoice = await stripe.invoices.retrieveUpcoming({
subscription: 'sub_*',
});
const item = invoice.lines.data.find((line) => line.description.startsWith('Remaining time'));
when you retrieve an upcoming invoice, in most cases, the invoice and invoice line items do not actually exist yet, so you can't delete those objects
you need to wait till the Invoice / Invoice Items are actually created before you can actually delete the line items
it can be done using the dashboard, but I would like to automate this, there are a few of them 😄
can you share the subscription id?
sub_1Lx6uwGjQawimwZR1LmdCdY2 here is one
the only reason why it's possible for you to edit that invoice item in the Dashboard under Upcoming Invoice is because the invoice item was already created as part of a proration previously
if you look at the Customer in the Dashboard, you'll see that Invoice Item under Pending invoice items i.e. it was already created
ahh, so I should remove these?
you can if you wish, and stripe.invoiceItems.del should work for those
yeah, I'm a bit confused why stripe even created these. Some of these also have the same balance subtracted, which is ok
all were updated using the same script though
for example this one, which has two pending items (Unused and Remaining)
yep those are proration items created by changing the subscription from one plan to another in https://dashboard.stripe.com/logs/req_jypjJqexS1eSaq
I get that, but why the different behavior for some subscriptions?
do you have an example of another subscription with different behaviour?
trying to find one, I already manually fixed the one I did
but essentially, removing these two items should fix the issue?
what issue exactly?
that the upcoming invoice will be overcharged after the update
hmm, how so? can you show me an invoice that will be overcharged and explain why you think that's an overcharge and what you expect it to be instead?
I've updated prices in subscriptions to turn on tax collection
now most of them have an additional item we don't want to charge for
can you show me specific examples (sub_xxx/in_xxx) with these items please?
sub_1K6t40GjQawimwZRC26xbbJE
thanks, looking at it. whats is the additional item you don't want to charge for there?
the Remaining thing
Remaining time on <price> after 06 Dec 2022 1 US$59.34 ?
yep
so that was created because you updated the subscription to change the pricing plan, in https://dashboard.stripe.com/logs/req_OXgAh4tIiWBgGO . If you don't pass proration_behavior:none for example, we generate those proration items. Do you fully understand that part?
if you didn't want that to happen you should have made the request differently/not at all.
If you want to delete the proration item, then I believe using stripe.invoiceItems.del with the ID of the proration items ii_1MBxxcGjQawimwZRUcpbmT6f and ii_1MBxxcGjQawimwZR2WGU8LVw would work, and you can use https://stripe.com/docs/api/invoiceitems/list#list_invoiceitems-customer to find those in general
yep it was my mistake, I imagine this should fix it:
const lines = await stripe.invoiceItems.list({
pending: true,
}).autoPagingToArray({limit: 10000});
const unusedItems = lines.filter((line) => line.description.startsWith('Unused time on Moralis Optimum Server'));
const remainingItems = lines.filter((line) => line.description.startsWith('Remaining time on Moralis Optimum Server'));
// Unused 98
// Remaining 87
Removing these should do the trick right?
you should replicate this scenario in test mode and then test out that code
you also don't need to filter by description string, there's a proration:true boolean set on the item which is likely a bit safer https://stripe.com/docs/api/invoiceitems/object#invoiceitem_object-proration
perfect, thanks!
think using description might be better, because we might have prorations in other subscriptions as well