#j_subscription-list

1 messages ยท Page 1 of 1 (latest)

pliant archBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1303028093425815646

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

torpid thistle
#

Okay, followup-- if we DID want to remove shipping from any upcoming invoices, if it did exist, how would we handle it

#

essentially, i want to try to perserve that function to the greatest extent possible

#
  const invoice = await stripe.invoices.retrieveUpcoming({ subscription: subscriptionId });
  const shipping = invoice.lines.data.filter((i) => i.description.includes('Shipping'));
  console.log(invoice);
  console.log(shipping);
  if (shipping.length === 0) {
    logger.log(
      'No shipping on invoice. Failing fast. Subscription id for invoice is' + subscriptionId
    );
    return;
  }

  await Promise.all(
    shipping.map((s) => {
      console.log(s.id);
      stripe.invoiceItems.del(s.id);
    })
  );

  return true;
};
regal terrace
torpid thistle
#

I see. Do you have any thoughts why stripe.invoices.retrieveUpcoming is retrieving different things within minutes of each other for the same user with no other changes for that user besides updating the subscription is this on? Is this newly updated subscription not creating an "upcoming" invoice?

regal terrace
#

Can you clarify what you mean by different things? Examples would help

To clarify, the upcoming invoice API lets you preview what the next invoice would look like. It does not create an actual invoice as such. It's meant to serve as temporary view/preview.

If you want to create a preview invoice - you should use this endpoint instead https://docs.stripe.com/api/invoices/create_preview

torpid thistle
torpid thistle
regal terrace
#

Invoice line items are added per invoice after you make the API call to add them to an invoice.

There won't be any one-off invoice line items in an upcoming invoice since there's no invoice. It is just a preview

#

I think you're still confused ๐Ÿ˜…

torpid thistle
#

Okay. I see. So is there any way to access those one-off items?

regal terrace
#

There are no one-off items in an upcoming invoice.. Is your Upcoming Invoice API calls showing you anything differently?

torpid thistle
#

Right, one second

#

so on our subscriptions, we have this line item, which is a "shipping" line item, being retrieved from stripe

#

im just gonna send you all of what we get from this call to help actually

#

like we aren't using the actual shipping field, we just create a line item on the subscription for shipping and use that

regal terrace
#

So that's what we call a subscription item - which is recurringly added to the invoices generated by the subscription ๐Ÿ™‚

I addressed how you can remove that here -
#1303028093425815646 message

torpid thistle
#

got it-- that's what you meant! ok, that's super helpful, i'll just do that

#

thank you

regal terrace
#

Yup, NP! ๐Ÿ™‚ Would highly recommend testing it out in test mode to be 100% certain of the behavior. We've talked about things back and forth so it's possible we might've missed something. Testing it out would help make sure this triggers 100% intended behavior

torpid thistle
#

of course, 0% chance there's not also some wonky architecture stuff going on here haha

regal terrace
#

Yup! ๐Ÿ™‚

torpid thistle
#

how do you get a list of all subscription items

regal terrace
pliant archBOT
torpid thistle
#

Cannot find name 'SubscriptionItem'. Did you mean 'subscriptionId'?ts(2552)

? (might just be dumb here)

silent pelican
#

j_subscription-list

#

@torpid thistle can you share more details with your question such as the exact code you are using?

torpid thistle
#

const items = subscription.items.data;
console.log(items);
if (shipping.length === 0) {
logger.log(
'No shipping on invoice. Failing fast. Subscription id for invoice is' + subscriptionId
);
return;
}

await Promise.all(
items.map((s) => {
console.log(s.id);
const c = SubscriptionItem.retrieve(s.id);
stripe.invoices.del(s.id);
})
);

silent pelican
#

okay so what exact line is failing? Try to provide all the context in one message so we can help you.

torpid thistle
#

essentially, just trying to delete subscription items from a subscription

silent pelican
#

sure sure but you seem to be completely rushing through things without looking at docs carefully

#

Like the last line of code you shared is calling the Delete Invoice API which would have nothing to do with deleting SubscriptionItems

torpid thistle
#

yeah, sorry, refactoring on the fly here. Give me a second

#

Have been hustling because otherwise the thread closes

silent pelican
#

I get it, but this is complex code that you do need to take the time to test end to end and debug on your own first. It's fine if the thread closes, you can ask your latest question as a new thread clearly summarized.

torpid thistle
#

Right... thank you for your patience. To reformulate, I have the following code.

  console.log(invoice.lines.data);
  const subscription = await stripe.subscriptions.retrieve(subscriptionId);
  const items = subscription.items.data;
  const shipping = items.filter((i) => i.metadata.description?.includes('Shipping'));
  console.log('ITEMS');
  console.log(items);```

I was told there would be no line items on invoices, and that anything attached to an upcoming invoice that actually existed would really exist somewhere as a subscription item, and could be deleted. (If I'm recapping that correctly?) 

However, when I open that invoice.lines.data console log, I have these temp objects:

```id: 'il_tmp_1QHTgWEk6sr5GyDh6I1gtr0B',
object: 'line_item',
amount: 3599,
amount_excluding_tax: 3599,
currency: 'usd',
  description: 'Shipping',
discount_amounts: [],
  discountable: true,   ```

and on the subscription items, that item doesn't exist.

So that temp object is not a real object I can actually remove from that invoice, because it's not an actual invoice, it's just a preview. However, there's a line item that it's showing *would* exist on the preview that I'm trying to access and delete, in whatever "real" form it exists in.
#

(I can also send what I get when I console log the subscription's items.)

silent pelican
#

Gotcha, so you seem to be quite lost and mixing up all the concepts at once. Not your fault, this is quite subtle and the words are quite similar from each other.

So I won't answer this, but I'll teach you how to fish instead

#

Question 1: How many SubscriptionItems does your Subscription currently have?

torpid thistle
#

Just one.

silent pelican
#

Perfect so you have one Subscription sub_12345 that is for say a monthly $10/usd Price price_123 and that's represented as one SubscriptionItem si_ABC on that Subscription

#

It is impossible to "delete" the last SubscriptionItem of a Subscription. Othetrwise you'd have an empty Subscription which would make no sense on our platform
So what you were trying to do from the start didn't really make sense and looks like a complete misunderstanding (again totally fine)

#

Question 2: What were you really trying to do since deleting the last SubscriptionItem doesn't make sense? Were you trying to cancel the Subscription entirely?

torpid thistle
#

No-- so, we have this line item that seems to be attached to an invoice, that you can see when you use retrieveUpcoming-- we create shipping details as a line item on an invoice. We just want to get rid of the line item, but we can't remove it from whatever ID we get from retrieveUpcoming, because it's some temp ID that errors when we try to remove it the way we used to, prior to updating our codebase

#

that object: 'line_item' from earlier

silent pelican
#

Yes but that is expected. You have a Subscription for a recurring Price such as that $10/month. Every Invoice will have that $10/month. It's impossible to delete.

torpid thistle
#

You can't get rid of any line items on a subscription without getting rid of the entire thing?

silent pelican
#

Kind of. A subscription can have 20 Prices at the same time. You can delete some of those and keep the other ones. But you aren't using this feature, you only have one Price and so that one can't be deleted

silent pelican
#

Did you have another question about this?

torpid thistle
#

Yes, if I can-- there's obviously no attached invoice,but there is an invoice_item attached-- is that something that could be used to delete these 'invoiceitem' objects from a subscription, or is there any other way to get rid of these charges besides finding them and applying a counter-credit?

silent pelican
#

No that is impossible

#

The lines on an Invoice reflect the SubscriptionItem(s) on a Subscription. You can't delete such a line, since again it would be akin to having an empty Subscription

#

I'm sorry this still looks like a complete misunderstanding to me

torpid thistle
#

Yeah, I think I'm confused on where these are even coming from, then

#

these lines, I mean

silent pelican
#

Why would you have a $10/month Subscription and then want to modify their next Invoice to not have that $10 line

torpid thistle
#

someone did shipping using line items 16 months ago

silent pelican
#

Sorry that sentence doesn't really make sense unfortunately. You do seem lost and I'm trying to tear apart the confusion

#

Can you share the Subscription id sub_123 and a screenshot of what you see in the Dashboard?

torpid thistle
#

sub_1QGSH3Ek6sr5GyDhvVBNkGrC

silent pelican
#

Sorry that's just the id

torpid thistle
#

it seems like you can, at least from the dashboard, delete those invoice items-- I'm just trying to find a way to do that in code

silent pelican
#

Okay so you have a Subscription sub_1QGSH3Ek6sr5GyDhvVBNkGrC, it has one SubscriptionItem si_R8jkUCmINQDuqG associated with a Product called Cream for $90/month. So each month you are going to have an Invoice issues with that Cream line item like you see on your first screenshot

#

So it was a complete misunderstanding after all which is good because that's solvable

#

The other lines you see on that first screenshot map to something we call a pending InvoiceItem which are created on a Customer to be pending until their next Invoice. Those can be deleted, but do require understanding exactly what they are and how they work first

#

go to the Customer's page associated with that Subscription and share a screenshot of what you see

torpid thistle
#

wrong photo one second

#

here we are

silent pelican
#

Perfect, so those are InvoiceItems

silent pelican
#

@torpid thistle did that solve your problem?