#alko89

1 messages · Page 1 of 1 (latest)

white duneBOT
warm heron
gusty grove
#

req_Z3MYlWlCnHy8G4

#

basically its a 404 error, think its because it expects an invoice item instead of line item

warm heron
#

where are you getting this invoice line item id from? il_tmp_1MBxsEGjQawimwZRpK9RYqxm

gusty grove
#

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'));
warm heron
#

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

gusty grove
#

it can be done using the dashboard, but I would like to automate this, there are a few of them 😄

warm heron
#

can you share the subscription id?

gusty grove
#

sub_1Lx6uwGjQawimwZR1LmdCdY2 here is one

warm heron
#

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

gusty grove
#

ahh, so I should remove these?

brisk junco
#

you can if you wish, and stripe.invoiceItems.del should work for those

gusty grove
#

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)

brisk junco
gusty grove
#

I get that, but why the different behavior for some subscriptions?

brisk junco
#

do you have an example of another subscription with different behaviour?

gusty grove
#

trying to find one, I already manually fixed the one I did

#

but essentially, removing these two items should fix the issue?

brisk junco
#

what issue exactly?

gusty grove
#

that the upcoming invoice will be overcharged after the update

brisk junco
#

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?

gusty grove
#

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

brisk junco
#

can you show me specific examples (sub_xxx/in_xxx) with these items please?

gusty grove
#

sub_1K6t40GjQawimwZRC26xbbJE

brisk junco
#

thanks, looking at it. whats is the additional item you don't want to charge for there?

gusty grove
#

the Remaining thing

brisk junco
#

Remaining time on <price> after 06 Dec 2022 1 US$59.34 ?

gusty grove
#

yep

brisk junco
#

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

gusty grove
#

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?

brisk junco
#

you should replicate this scenario in test mode and then test out that code

gusty grove
#

perfect, thanks!

think using description might be better, because we might have prorations in other subscriptions as well