#j_subscription-list
1 messages ยท Page 1 of 1 (latest)
๐ 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.
- j_unexpected, 33 minutes ago, 25 messages
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;
};
The only way the shipping/tax item would be present in the upcoming invoice is if it has been added as a subscription item.
You can delete the subscription item - https://docs.stripe.com/api/subscription_items/delete
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?
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
RE: this, our shipping line items are just invoice line items using our current implementation-- so, essentially, we'd want to delete that item. but right now, we just get those temp items back
yeah, i understand that-- does it contain shipping line items if we are trying to add those ourselves
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 ๐
Okay. I see. So is there any way to access those one-off items?
There are no one-off items in an upcoming invoice.. Is your Upcoming Invoice API calls showing you anything differently?
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
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
got it-- that's what you meant! ok, that's super helpful, i'll just do that
thank you
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
of course, 0% chance there's not also some wonky architecture stuff going on here haha
Yup! ๐
how do you get a list of all subscription items
From a subscription? You can use this endpoint - https://docs.stripe.com/api/subscription_items/list
Other option is to retrieve Subscription - https://docs.stripe.com/api/subscriptions/retrieve and look at items - https://docs.stripe.com/api/subscriptions/object#subscription_object-items
Cannot find name 'SubscriptionItem'. Did you mean 'subscriptionId'?ts(2552)
? (might just be dumb here)
j_subscription-list
@torpid thistle can you share more details with your question such as the exact code you are using?
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);
})
);
okay so what exact line is failing? Try to provide all the context in one message so we can help you.
essentially, just trying to delete subscription items from a subscription
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
yeah, sorry, refactoring on the fly here. Give me a second
Have been hustling because otherwise the thread closes
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.
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.)
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?
Just one.
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?
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
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.
You can't get rid of any line items on a subscription without getting rid of the entire thing?
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
Did you have another question about this?
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?
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
Yeah, I think I'm confused on where these are even coming from, then
these lines, I mean
Why would you have a $10/month Subscription and then want to modify their next Invoice to not have that $10 line
someone did shipping using line items 16 months ago
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?
sub_1QGSH3Ek6sr5GyDhvVBNkGrC
Sorry that's just the id
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
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
Perfect, so those are InvoiceItems
those can be deleted using the Delete InvoiceItem API https://docs.stripe.com/api/invoiceitems/delete and they have an id that starts with ii_ (which is different from the iltmp_ from an upcoming Invoice)
You can use the List InvoiceItems API https://docs.stripe.com/api/invoiceitems/list, pass customer: 'cus_123' and pending: true to see those and then delete each one with the Delete InvoiceItem API https://docs.stripe.com/api/invoiceitems/delete
@torpid thistle did that solve your problem?